#page-chat { min-height: 0; overflow: hidden; }
#chat-page-root { width: 100%; height: 100%; min-height: 0; }
.chat-layout { display: grid; grid-template-columns: minmax(15rem, 0.85fr) minmax(0, 2fr); gap: 1rem; width: 100%; height: 100%; min-height: 0; max-width: 90rem; margin: 0 auto; }
.chat-sidebar, .chat-conversation { min-width: 0; min-height: 0; overflow: hidden; border: 1px solid rgba(148,163,184,0.24); border-radius: 1.25rem; background: rgba(255,255,255,0.97); box-shadow: 0 20px 50px rgba(15,23,42,0.12); }
.chat-sidebar { display: flex; flex-direction: column; padding: 1.25rem 0.75rem; }
.chat-sidebar-heading { padding: 0 0.6rem 1rem; }
.chat-sidebar-top-row { display: flex; align-items: center; gap: 0.5rem; }
.chat-sidebar-heading h1 { margin: 0; color: #0f172a; font-size: 1.4rem; font-weight: 800; }
.chat-sidebar-heading p { margin: 0.25rem 0 0; color: #64748b; font-size: 0.82rem; }
.chat-subject-list { display: flex; min-height: 0; flex-direction: column; gap: 0.65rem; overflow-y: auto; padding: 0.15rem 0.2rem 0.3rem; }
.chat-subject-button { display: flex; flex: 0 0 auto; flex-direction: column; gap: 0.65rem; width: 100%; padding: 0.85rem 0.9rem; border: 1px solid color-mix(in srgb, var(--chat-accent) 38%, white); border-left: 4px solid var(--chat-accent); border-radius: 0.9rem; background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 38%, white), color-mix(in srgb, var(--chat-accent) 22%, white)); color: #334155; text-align: left; cursor: pointer; transition: background 160ms ease, border-color 160ms ease, transform 160ms ease; }
.chat-subject-button:hover { transform: translateY(-1px); background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 66%, white), color-mix(in srgb, var(--chat-accent) 46%, white)); }
.chat-subject-button.active { border-color: var(--chat-accent); background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 58%, white), color-mix(in srgb, var(--chat-accent) 38%, white)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--chat-accent) 18%, transparent); }
.chat-subject-card-top { display: flex; min-width: 0; align-items: center; gap: 0.65rem; }
.chat-subject-icon { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 2.35rem; height: 2.35rem; border: 1px solid color-mix(in srgb, var(--chat-accent) 12%, var(--chat-tint)); border-radius: 50%; background: color-mix(in srgb, var(--chat-accent) 10%, var(--chat-tint)); color: var(--chat-accent); }
.chat-subject-icon i { font-size: 1.1rem; }
.chat-subject-label { min-width: 0; flex: 1; overflow: hidden; color: #0f172a; font-size: 0.88rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.chat-subject-chevron { width: 1rem; flex: 0 0 auto; color: #94a3b8; font-size: 0.75rem; text-align: center; }
.chat-subject-divider { width: 100%; height: 1px; background: color-mix(in srgb, var(--chat-accent) 17%, white); }
.chat-subject-preview-row { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 0.6rem; }
.chat-subject-last-message { display: block; overflow: hidden; color: #64748b; font-size: 0.76rem; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.chat-unread-count { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; min-width: 1.45rem; height: 1.45rem; padding: 0 0.35rem; border-radius: 50%; background: var(--chat-accent); color: #fff; font-size: 0.7rem; font-weight: 800; line-height: 1; }
.chat-conversation { display: flex; flex-direction: column; }
.chat-conversation-header { display: flex; flex: 0 0 auto; align-items: center; gap: 0.8rem; padding: 1.1rem 1.35rem; border-bottom: 2px solid color-mix(in srgb, var(--chat-accent, #002147) 25%, #e2e8f0); background: linear-gradient(90deg, var(--chat-tint, #eff6ff), #fff 55%); }
.chat-subject-avatar { display: grid; flex: 0 0 auto; place-items: center; width: 2.5rem; height: 2.5rem; padding: 0; border: 1px solid color-mix(in srgb, var(--chat-accent, #002147) 12%, var(--chat-tint, #dbeafe)); border-radius: 50%; background: color-mix(in srgb, var(--chat-accent, #002147) 10%, var(--chat-tint, #dbeafe)); color: var(--chat-accent, #002147); }
.chat-subject-avatar i { display: block; width: 1.1rem; margin: 0; font-size: 1.1rem; line-height: 1; text-align: center; }
.chat-conversation-header h2 { margin: 0; color: #0f172a; font-size: 1.05rem; font-weight: 800; }
.chat-conversation-header p { margin: 0.12rem 0 0; color: #64748b; font-size: 0.78rem; }
.chat-messages { display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 0.9rem; overflow-y: auto; padding: 1.25rem; }
.chat-message { display: flex; max-width: min(82%, 34rem); flex-direction: column; align-items: flex-start; gap: 0.25rem; }
.chat-message.is-own { align-self: flex-end; align-items: flex-end; }
.chat-message-author { color: #64748b; font-size: 0.72rem; font-weight: 700; }
.chat-message-bubble { padding: 0.7rem 0.9rem; border: 1px solid #cbd5e1; border-radius: 0.25rem 1rem 1rem; background: #e2e8f0; color: #1e293b; font-size: 0.88rem; line-height: 1.45; overflow-wrap: anywhere; }
.chat-message.is-own .chat-message-bubble { border-color: #002147; border-radius: 1rem 0.25rem 1rem 1rem; background: #002147; color: #fff; }
.chat-empty-state { align-self: center; margin: auto; color: #64748b; font-size: 0.9rem; text-align: center; }
.chat-compose { display: flex; flex: 0 0 auto; gap: 0.65rem; padding: 0.9rem 1rem; border-top: 1px solid #e2e8f0; }
#chat-message-input { min-width: 0; flex: 1; padding: 0.75rem 0.95rem; border: 1px solid #cbd5e1; border-radius: 999px; outline: none; color: #0f172a; font: inherit; font-size: 0.88rem; }
#chat-message-input:focus { border-color: #002147; box-shadow: 0 0 0 3px rgba(0,33,71,0.1); }
.chat-compose button { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 2.8rem; height: 2.8rem; border: 0; border-radius: 50%; background: #002147; color: #fff; cursor: pointer; transition: background 160ms ease; }
.chat-compose button:hover { background: #123b65; }
.chat-compose button i { font-size: 1rem; }
.chat-compose .chat-file-button { border: 1px solid #cbd5e1; background: #f1f5f9; color: #475569; }
.chat-compose .chat-file-button:hover { background: #e2e8f0; color: #002147; }
.chat-attachment-name { display: none; flex: 0 0 auto; margin: 0; padding: 0 1.1rem 0.65rem; color: #64748b; font-size: 0.76rem; overflow-wrap: anywhere; }
.chat-attachment-name.is-visible { display: block; }
.chat-message-attachment { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.35rem; padding: 0.45rem 0.6rem; border-radius: 0.55rem; background: rgba(15,23,42,0.07); font-size: 0.78rem; overflow-wrap: anywhere; }
.chat-message.is-own .chat-message-attachment { background: rgba(255,255,255,0.15); }
.app-dark .chat-sidebar, .app-dark .chat-conversation { border-color: #002147; background-color: #001a38; color: #e2e8f0; }
.app-dark .chat-sidebar-heading h1, .app-dark .chat-conversation-header h2 { color: #f1f5f9; }
.app-dark .chat-sidebar-heading p, .app-dark .chat-conversation-header p, .app-dark .chat-message-author, .app-dark .chat-empty-state { color: #a8b6c8; }
.app-dark .chat-subject-chevron { color: #94a3b8; }
.app-dark .chat-subject-last-message { color: #a8b6c8; }
.app-dark .chat-message-bubble { border-color: #24466b; background: #002147; color: #e2e8f0; }
.app-dark .chat-message.is-own .chat-message-bubble { border-color: #fff; background: #fff; color: #002147; }
.app-dark .chat-message-attachment { background: rgba(255,255,255,0.1); color: #e2e8f0; }
.app-dark .chat-conversation-header { border-color: #123b65; background: #001a38; }
.app-dark .chat-subject-avatar { border-color: color-mix(in srgb, var(--chat-accent, #002147) 35%, #123b65); background: color-mix(in srgb, var(--chat-accent, #002147) 18%, #001a38); }
.app-dark #chat-message-input { border-color: #123b65; background: #002147; color: #f1f5f9; }
.app-dark #chat-message-input::placeholder { color: #9aabc0; }
.app-dark #chat-message-input:focus { border-color: #4777a8; box-shadow: 0 0 0 3px rgba(71,119,168,0.22); }
.app-dark .chat-compose { border-color: #123b65; }
.app-dark .chat-compose .chat-file-button { border-color: #123b65; background: #002147; color: #cbd5e1; }
.app-dark .chat-compose .chat-file-button:hover { background: #123b65; color: #fff; }
.app-dark .chat-attachment-name { color: #a8b6c8; }
.app-dark .chat-subject-button { border-color: color-mix(in srgb, var(--chat-accent) 55%, #002147); background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 38%, #001a38), color-mix(in srgb, var(--chat-accent) 22%, #001a38)); }
.app-dark .chat-subject-button.active { background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 58%, #001a38), color-mix(in srgb, var(--chat-accent) 38%, #001a38)); }
.app-dark .chat-subject-button:hover { background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 66%, #001a38), color-mix(in srgb, var(--chat-accent) 46%, #001a38)); }
.app-dark .chat-subject-icon { border-color: color-mix(in srgb, var(--chat-accent) 40%, #002147); background: color-mix(in srgb, var(--chat-accent) 22%, #001a38); }
.app-dark .chat-subject-button[data-chat-subject="coding"] .chat-subject-icon,
.app-dark .chat-subject-avatar[style*="334155"] { border-color: #64748b; background: #334155; color: #fff; }
.app-dark .chat-subject-label { color: #f1f5f9; }
.app-dark .chat-subject-divider { background: color-mix(in srgb, var(--chat-accent) 40%, #334155); }

body[data-color-theme]:not([data-color-theme="default"]) .chat-sidebar,
body[data-color-theme]:not([data-color-theme="default"]) .chat-conversation {
  border-color: var(--portal-accent-border);
  background: var(--portal-light-surface);
}
body[data-color-theme]:not([data-color-theme="default"]) .chat-conversation-header {
  border-color: var(--portal-accent-border);
  background: linear-gradient(90deg, var(--portal-accent-soft), var(--portal-light-surface) 75%);
}
body[data-color-theme]:not([data-color-theme="default"]) .chat-message-bubble {
  border-color: var(--portal-accent-border);
  background: color-mix(in srgb, var(--portal-accent) 8%, #fff);
}
body[data-color-theme]:not([data-color-theme="default"]) .chat-message.is-own .chat-message-bubble,
body[data-color-theme]:not([data-color-theme="default"]) .chat-compose button:not(.chat-file-button) {
  border-color: var(--portal-accent);
  background: var(--portal-accent);
  color: #fff;
}
body[data-color-theme]:not([data-color-theme="default"]) .chat-compose button:not(.chat-file-button):hover {
  background: var(--portal-accent-hover);
}
body[data-color-theme]:not([data-color-theme="default"]) #chat-message-input:focus {
  border-color: var(--portal-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--portal-accent) 16%, transparent);
}
body[data-color-theme]:not([data-color-theme="default"]) .chat-compose {
  border-color: var(--portal-accent-border);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-sidebar,
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-conversation {
  border-color: var(--portal-accent-border);
  background: var(--portal-dark-surface);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-conversation-header {
  border-color: var(--portal-accent-border);
  background: linear-gradient(90deg, var(--portal-accent-soft), var(--portal-dark-surface) 78%);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-message-bubble {
  border-color: var(--portal-accent-border);
  background: color-mix(in srgb, var(--portal-accent) 12%, var(--portal-dark-surface));
  color: #f1f5f9;
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-message.is-own .chat-message-bubble,
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-compose button:not(.chat-file-button) {
  border-color: var(--portal-accent);
  background: var(--portal-accent);
  color: #fff;
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-compose button:not(.chat-file-button):hover {
  background: var(--portal-accent-hover);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-subject-button {
  border-color: color-mix(in srgb, var(--chat-accent) 34%, var(--portal-dark-surface));
  background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 18%, var(--portal-dark-surface)), color-mix(in srgb, var(--chat-accent) 10%, var(--portal-dark-surface)));
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-subject-button.active {
  border-color: var(--chat-accent);
  outline: none;
  background: linear-gradient(110deg, color-mix(in srgb, var(--chat-accent) 58%, var(--portal-dark-surface)), color-mix(in srgb, var(--chat-accent) 38%, var(--portal-dark-surface)));
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) #chat-message-input {
  border-color: var(--portal-accent-border);
  background: color-mix(in srgb, var(--portal-accent) 5%, var(--portal-dark-surface));
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) #chat-message-input:focus {
  border-color: var(--portal-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--portal-accent) 24%, transparent);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-compose,
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-compose .chat-file-button {
  border-color: var(--portal-accent-border);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-compose .chat-file-button {
  background: var(--portal-dark-surface);
}
body.app-dark[data-color-theme]:not([data-color-theme="default"]) .chat-compose .chat-file-button:hover {
  background: var(--portal-accent-soft);
  color: var(--portal-accent-ink);
}

@media (max-width: 700px) {
  .chat-layout { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(7.5rem, 0.28fr) minmax(0,1fr); gap: 0.65rem; }
  .chat-sidebar { padding: 0.65rem; }
  .chat-sidebar-heading { padding: 0 0.3rem 0.4rem; }
  .chat-sidebar-heading h1 { font-size: 1rem; }
  .chat-sidebar-heading p { display: none; }
  .chat-subject-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .chat-subject-button { flex: 0 0 13rem; width: 13rem; gap: 0.45rem; padding: 0.55rem 0.65rem; }
  .chat-subject-icon { width: 1.9rem; height: 1.9rem; }
  .chat-subject-last-message { font-size: 0.7rem; }
  .chat-conversation-header { padding: 0.75rem 0.9rem; }
  .chat-messages { padding: 0.9rem; }
  .chat-compose { padding: 0.65rem; }
}
