:root {
  --base:     #1e1e2e;
  --mantle:   #181825;
  --crust:    #11111b;
  --s0:       #313244;
  --s1:       #45475a;
  --s2:       #585b70;
  --ov0:      #6c7086;
  --ov1:      #7f849c;
  --text:     #cdd6f4;
  --sub1:     #bac2de;
  --mauve:    #cba6f7;
  --blue:     #89b4fa;
  --green:    #a6e3a1;
  --red:      #f38ba8;
  --peach:    #fab387;
  --yellow:   #f9e2af;
  --glass:    rgba(30, 30, 46, 0.7);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--crust);
  color: var(--text);
  font-family: 'Outfit', sans-serif;
  overflow: hidden;
  overflow-x: hidden;
}

/* ── Layout ── */
#container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  background-image:
    radial-gradient(at 0% 0%, rgba(203, 166, 247, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(137, 180, 250, 0.05) 0px, transparent 50%);
}

#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ── Header ── */
header {
  background: var(--glass);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
  z-index: 10;
}
header .brand {
  font-size: 18px; font-weight: 700; letter-spacing: 4px;
  background: linear-gradient(90deg, var(--mauve), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
header .meta { display: flex; gap: 20px; align-items: center; font-size: 11px; color: var(--ov1); font-weight: 500; }
#dash-toggle {
  display: none;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--s0);
  color: var(--ov1);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: lowercase;
}
#dash-toggle:hover {
  background: var(--s0);
  color: var(--text);
}
#clear-btn {
  background: rgba(255,255,255,0.05); border: 1px solid var(--s0); color: var(--ov1);
  padding: 4px 10px; border-radius: 6px; cursor: pointer; transition: all 0.2s;
}
#clear-btn:hover { background: var(--s0); color: var(--text); }

/* ── Dashboard (Sidebar) ── */
#dashboard {
  width: 320px;
  background: var(--mantle);
  border-left: 1px solid rgba(255,255,255,0.05);
  display: flex; flex-direction: column; gap: 24px;
  padding: 24px; overflow-y: auto; flex-shrink: 0;
}
.dashboard-top {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: -8px;
}
.dash-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ov1);
}
#dash-close {
  display: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--s1);
  background: var(--crust);
  color: var(--sub1);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
#dashboard-backdrop {
  display: none;
}

.dash-section {
  background: var(--base);
  border: 1px solid rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.dash-label {
  font-size: 10px; font-weight: 800; color: var(--mauve);
  letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 12px;
  opacity: 0.8;
}

.dash-stat { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; font-weight: 400; }
.dash-stat .val { color: var(--blue); font-weight: 600; font-family: 'JetBrains Mono', monospace; }
.dash-empty { color: var(--ov1); font-size: 12px; }

.dash-ws-item {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--crust);
  color: var(--text);
  border: 1px solid var(--s0);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.dash-ws-item:last-child { margin-bottom: 0; }
.dash-ws-item:hover {
  border-color: var(--mauve);
  background: rgba(203, 166, 247, 0.08);
}
.ws-name {
  font-size: 12px;
  font-weight: 600;
}
.ws-meta {
  font-size: 10px;
  color: var(--blue);
  font-family: 'JetBrains Mono', monospace;
}
.ws-desc {
  font-size: 11px;
  color: var(--ov1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Quick Log ── */
#ql-text {
  width: 100%; background: var(--crust); border: 1px solid var(--s0);
  border-radius: 8px; color: var(--text); font-family: inherit; font-size: 13px;
  padding: 10px; resize: none; outline: none; margin-bottom: 10px;
  transition: border-color 0.2s;
}
#ql-text:focus { border-color: var(--mauve); }
.ql-controls { display: flex; justify-content: space-between; align-items: center; }
#ql-ctx {
  background: var(--s0); color: var(--text); border: none; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; font-family: inherit; outline: none;
}
#ql-btn {
  background: var(--mauve); color: var(--crust); font-weight: bold;
  border: none; border-radius: 6px; padding: 6px 16px; font-size: 12px; cursor: pointer;
}

/* ── Fast Actions ── */
#fast-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fast-action-btn {
  width: 100%;
  text-align: left;
  background: var(--crust);
  color: var(--sub1);
  border: 1px solid var(--s0);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.fast-action-btn:hover {
  border-color: var(--blue);
  color: var(--text);
  background: rgba(137, 180, 250, 0.08);
}

/* ── Doctor Card ── */
#doctor-summary {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 6px;
}
#doctor-meta {
  font-size: 11px;
  color: var(--ov1);
  line-height: 1.35;
  margin-bottom: 10px;
}
#doctor-btn {
  width: 100%;
  border: 1px solid var(--s1);
  background: var(--crust);
  color: var(--sub1);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
#doctor-btn:hover {
  border-color: var(--blue);
  color: var(--text);
  background: rgba(137, 180, 250, 0.08);
}
#doctor-btn:disabled {
  opacity: 0.65;
  cursor: default;
}
#dash-doctor.alert {
  border-color: rgba(243, 139, 168, 0.55);
}
#dash-doctor.watch {
  border-color: rgba(249, 226, 175, 0.4);
}
#doctor-when {
  margin-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ov1);
  font-size: 11px;
  line-height: 1.3;
}

/* ── Chat Feed ── */
#chat {
  flex: 1; overflow-y: auto; padding: 32px 24px;
  display: flex; flex-direction: column; gap: 24px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 16px; max-width: 90%; animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.lbl {
  font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  opacity: 0.4; margin-top: 8px; width: 40px; text-align: right;
}
.msg.user .lbl { text-align: left; }

.bubble {
  background: var(--mantle);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px; padding: 12px 18px;
  font-size: 14.5px; line-height: 1.6;
  position: relative; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--s1), var(--s0));
  border-color: rgba(255,255,255,0.08);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble { border-bottom-left-radius: 4px; }
.bubble-body.plain-text { white-space: pre-wrap; }

.msg-actions {
  display: flex;
  justify-content: flex-end;
}
.copy-btn {
  background: transparent;
  color: var(--ov1);
  border: 1px solid var(--s1);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.copy-btn:hover {
  border-color: var(--blue);
  color: var(--text);
  background: rgba(137, 180, 250, 0.08);
}

/* ── Markdown Content ── */
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin-left: 20px; margin-bottom: 8px; }
.bubble li { margin-bottom: 4px; }
.bubble pre {
  background: var(--crust); border: 1px solid var(--s0);
  padding: 10px; border-radius: 8px; overflow-x: auto;
  margin: 10px 0; font-family: 'JetBrains Mono', monospace; font-size: 13px;
}
.bubble code {
  background: var(--s0); padding: 2px 4px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 0.9em;
}
.bubble pre code { background: none; padding: 0; font-size: inherit; }
.bubble blockquote {
  border-left: 3px solid var(--mauve); padding-left: 12px;
  color: var(--ov1); font-style: italic; margin: 10px 0;
}
.bubble table {
  border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px;
}
.bubble table th, .bubble table td {
  border: 1px solid var(--s0); padding: 7px 12px; text-align: left;
}
.bubble table th {
  background: var(--crust); color: var(--mauve); font-weight: 600;
  font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase;
}
.bubble table tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.bubble table tr:hover { background: rgba(255,255,255,0.04); }

/* ── Input Box ── */
#input-wrap {
  background: var(--glass);
  backdrop-filter: blur(12px);
  padding: 20px 24px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,0.05);
}
#msg-row { display: flex; gap: 12px; align-items: flex-end; }
#quality-mode {
  height: 48px;
  min-width: 108px;
  border-radius: 12px;
  border: 1px solid var(--s1);
  background: var(--base);
  color: var(--sub1);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 0 10px;
  outline: none;
}
#quality-mode:focus { border-color: var(--blue); }
#msg {
  flex: 1; background: var(--base); border: 1px solid var(--s1);
  border-radius: 12px; color: var(--text); padding: 12px 16px;
  font-size: 15px; outline: none; min-height: 48px; max-height: 200px;
  transition: border-color 0.2s; font-family: inherit;
}
#msg:focus { border-color: var(--blue); background: var(--crust); }
.btn {
  height: 48px; border-radius: 12px; padding: 0 20px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; border: 1px solid transparent;
}
#send-btn { background: var(--blue); color: var(--crust); }
#send-btn:hover { filter: brightness(1.1); }
#img-btn { background: var(--s0); color: var(--ov1); font-size: 18px; border: 1px solid var(--s1); }

/* ── Briefing ── */
.briefing-bubble { border: 1px solid var(--mauve); border-radius: 20px !important; }

/* ── Auth ── */
#auth {
  position: fixed; inset: 0; background: var(--crust);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 100;
}
#auth input {
  background: var(--mantle); border: 1px solid var(--s1); border-radius: 12px;
  padding: 14px; width: 300px; color: var(--text); text-align: center; font-size: 16px;
}

/* ── Briefing card ── */
.briefing-bubble {
  padding: 16px 20px !important;
  min-width: min(320px, 100%);
}
.briefing-header {
  color: var(--mauve);
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}
.briefing-section {
  margin-top: 12px;
}
.briefing-section-label {
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--ov0);
  margin-bottom: 6px;
}
.briefing-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  font-size: 13px;
  line-height: 1.5;
}
.briefing-item.event .bi-dot { color: var(--blue); }
.briefing-item.todo  .bi-dot { color: var(--green); }
.briefing-item.overdue .bi-dot { color: var(--red); }
.bi-dot { font-size: 16px; flex-shrink: 0; line-height: 1; }
.bi-time {
  color: var(--ov1);
  font-size: 11px;
  min-width: 42px;
  flex-shrink: 0;
}
.bi-text { color: var(--text); }
.bi-badge {
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
  opacity: 0.8;
}
.briefing-empty { color: var(--ov0); font-size: 12px; font-style: italic; }
.briefing-item.todo { cursor: pointer; }
.briefing-item.todo:hover .bi-text { color: var(--sub1); }
.briefing-item.todo.done .bi-text { text-decoration: line-through; color: var(--ov0); }
.briefing-item.todo.done .bi-dot  { color: var(--s2) !important; }
.briefing-item.todo.done .bi-badge { display: none; }
.briefing-item.email .bi-dot { color: var(--peach); }
.bi-from { color: var(--ov1); font-size: 11px; min-width: 0; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

/* ── Mobile ── */
@media (max-width: 900px) {
  .msg { max-width: 100%; }
  #dash-toggle { display: inline-flex; align-items: center; justify-content: center; }
  #dashboard-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 17, 27, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 35;
    backdrop-filter: blur(2px);
  }
  #dashboard {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    width: min(88vw, 360px);
    z-index: 40;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    border-left: 1px solid rgba(255,255,255,0.08);
    padding: max(16px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
    gap: 16px;
  }
  .dashboard-top { display: flex; }
  #dash-close { display: inline-flex; align-items: center; justify-content: center; }
  body.dashboard-open #dashboard {
    transform: translateX(0);
  }
  body.dashboard-open #dashboard-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.dashboard-open {
    overflow: hidden;
  }
}

/* ── Mobile ── */
@media (max-width: 640px) {
  body { font-size: 15px; }

  header { padding: calc(8px + env(safe-area-inset-top)) 14px 8px; }
  header .brand { font-size: 13px; letter-spacing: 2px; }
  header .meta  { font-size: 10px; gap: 10px; }

  #chat { padding: 14px 10px 20px; gap: 14px; }

  .msg { gap: 0; max-width: 100%; }
  .lbl { display: none; }
  .bubble {
    font-size: 15px;
    max-width: 88vw;
    padding: 10px 14px;
  }
  .bubble img { max-width: 100%; }

  #input-wrap { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  #msg-row {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }
  #quality-mode {
    min-width: 0;
    height: 44px;
    font-size: 11px;
    width: 100%;
  }
  #img-btn {
    width: 100%;
    height: 44px;
  }
  #msg {
    grid-column: 1 / -1;
    font-size: 16px; /* prevents iOS auto-zoom */
    min-height: 44px;
    width: 100%;
  }
  .btn { height: 44px; padding: 0 12px; font-size: 14px; }
  #send-btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  footer { display: none; }

  #auth input { width: 90vw; font-size: 16px; }
  #auth h1 { font-size: 20px; }
}

@media (max-width: 420px) {
  #hdate { display: none; }
}
