:root {
  color-scheme: light dark;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f8fb;
  --text: #151a2d;
  --muted: #6d7284;
  --line: #e5e6ec;
  --accent: #6d5dfc;
  --accent-soft: #eeebff;
  --success: #168a5b;
  --danger: #c63c45;
  --shadow: 0 18px 48px rgba(31, 35, 51, .09);
  --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1017;
    --surface: #171922;
    --surface-2: #1d202b;
    --text: #f3f3f7;
    --muted: #a7aaba;
    --line: #2b2e3a;
    --accent: #9b8fff;
    --accent-soft: #2b254d;
    --success: #52c58f;
    --danger: #ff858d;
    --shadow: 0 20px 60px rgba(0, 0, 0, .32);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 12%, rgba(109, 93, 252, .16), transparent 32%),
    radial-gradient(circle at 82% 88%, rgba(82, 197, 143, .11), transparent 30%),
    var(--bg);
}
.login-panel {
  width: min(440px, 100%);
  padding: 44px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: white;
  background: linear-gradient(145deg, #8375ff, #5948e6);
  box-shadow: 0 12px 24px rgba(109, 93, 252, .28);
  font-family: Georgia, serif;
  font-size: 28px;
  font-weight: 600;
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 20px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .14em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(30px, 4vw, 44px); font-weight: 500; }
h2 { margin-bottom: 8px; font-size: 20px; }
.login-panel .brand-mark { margin-bottom: 28px; }
.login-intro, .privacy-note, .muted-copy { color: var(--muted); line-height: 1.6; }
.login-panel form { display: grid; gap: 10px; margin-top: 30px; }
label { margin-top: 8px; font-size: 13px; font-weight: 650; }
label span { color: var(--muted); font-weight: 400; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 13px 14px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent); }
.primary-button, .secondary-button, .send-button, .voice-button, .icon-button, .nav-item, .conversation-button {
  border: 0;
  color: inherit;
}
.primary-button {
  min-height: 46px;
  margin-top: 12px;
  border-radius: 13px;
  color: white;
  background: var(--accent);
  font-weight: 700;
  box-shadow: 0 10px 22px color-mix(in srgb, var(--accent) 24%, transparent);
}
.primary-button.compact, .secondary-button.compact { min-height: 38px; margin: 0; padding: 0 14px; }
.secondary-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 650;
}
.form-error { min-height: 20px; margin: 4px 0 0; color: var(--danger); font-size: 13px; }
.privacy-note { margin: 24px 0 0; font-size: 12px; text-align: center; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.brand-row { display: flex; align-items: center; gap: 12px; padding: 0 8px 14px; font-family: Georgia, serif; font-size: 25px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item {
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 12px;
  background: transparent;
  text-align: left;
}
.nav-item:hover, .nav-item.active { color: var(--accent); background: var(--accent-soft); }
.nav-item span { width: 22px; text-align: center; }
.conversation-list { min-height: 0; overflow: auto; display: grid; gap: 3px; }
.conversation-button {
  padding: 9px 10px;
  overflow: hidden;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-button:hover, .conversation-button.selected { background: var(--surface-2); color: var(--text); }
.account-row { margin-top: auto; padding: 12px 8px 0; display: grid; grid-template-columns: 38px 1fr 36px; align-items: center; gap: 10px; border-top: 1px solid var(--line); }
.account-row small { display: block; margin-top: 2px; color: var(--muted); text-transform: capitalize; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--accent); font-weight: 700; }
.icon-button, .voice-button, .send-button { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); }
.icon-button:hover { background: var(--accent-soft); color: var(--accent); }

.main-content { min-width: 0; min-height: 100vh; background: var(--bg); }
.app-view { display: none; min-height: 100vh; padding: 34px clamp(20px, 5vw, 72px) 130px; }
.app-view.active-view { display: block; }
.topbar { min-height: 70px; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.topbar h1 { font-size: clamp(30px, 4vw, 42px); }
.messages { max-width: 880px; margin: 20px auto; display: flex; flex-direction: column; gap: 22px; }
.message { max-width: min(78%, 720px); scroll-margin-bottom: 160px; }
.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message-label { display: block; margin: 0 6px 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.message.user .message-label { text-align: right; }
.message-content {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 6px 20px 20px 20px;
  background: var(--surface);
  box-shadow: 0 5px 20px rgba(30, 35, 55, .04);
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-content p { margin: 0 0 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 4px 0 12px; padding-left: 24px; }
.message-content li + li { margin-top: 5px; }
.message-content pre { margin: 8px 0; padding: 14px; overflow: auto; border-radius: 12px; background: #11131b; color: #f5f6fa; font: 13px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }
.message-heading { display: block; margin: 4px 0 8px; font-size: 1.03em; }
.message.user .message-content { border: 0; border-radius: 20px 20px 6px 20px; background: var(--accent-soft); box-shadow: none; }
.message.pending { opacity: .66; }
.message.failed .message-content { border-color: color-mix(in srgb, var(--danger) 38%, var(--line)); }
.message-actions { margin: 7px 6px 0; display: flex; justify-content: flex-end; align-items: center; gap: 9px; color: var(--danger); font-size: 12px; }
.retry-button { min-height: 30px; padding: 0 11px; border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); border-radius: 9px; color: var(--danger); background: var(--surface); font-weight: 700; }
.retry-button:hover { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.retry-button:disabled { cursor: wait; opacity: .6; }
.action-card { width: min(440px, calc(100vw - 76px)); margin-top: 10px; padding: 16px; border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); border-radius: 16px; background: linear-gradient(145deg, var(--surface), var(--accent-soft)); box-shadow: 0 10px 30px rgba(30, 35, 55, .07); }
.action-card-header { display: grid; gap: 8px; }
.action-card-header strong { font-size: 16px; }
.action-badge { width: fit-content; padding: 4px 8px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.action-card dl { margin: 14px 0; display: grid; grid-template-columns: 76px 1fr; gap: 7px 12px; font-size: 13px; }
.action-card dt { color: var(--muted); }
.action-card dd { margin: 0; font-weight: 600; }
.action-controls { display: flex; justify-content: flex-end; gap: 8px; }
.action-controls .primary-button { margin: 0; padding-inline: 15px; }
.action-status { min-height: 18px; margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.action-card.confirmed { border-color: color-mix(in srgb, var(--success) 45%, var(--line)); }
.action-card.confirmed .action-status { color: var(--success); font-weight: 700; }
.action-card.cancelled { opacity: .72; }
.composer {
  position: fixed;
  z-index: 5;
  left: calc(280px + max(20px, (100vw - 280px - 880px) / 2));
  right: max(20px, (100vw - 280px - 880px) / 2);
  bottom: 22px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.composer textarea { min-height: 48px; max-height: 160px; padding: 13px 12px 4px; resize: none; border: 0; background: transparent; box-shadow: none; }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.chat-status { margin-right: auto; color: var(--muted); font-size: 12px; }
.voice-button { color: var(--accent); background: var(--accent-soft); }
.send-button { color: white; background: var(--accent); font-size: 22px; }

.today-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.feature-card, .setting-row, .calendar-row, .empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.feature-card { padding: 24px; }
.welcome-card { grid-column: 1 / -1; padding: 34px; background: linear-gradient(140deg, var(--surface), var(--accent-soft)); }
.item-list { display: grid; gap: 10px; }
.calendar-items { display: grid; gap: 12px; margin-top: 18px; }
.calendar-row { min-height: 76px; padding: 14px 16px; display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 14px; }
.calendar-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: var(--accent); background: var(--accent-soft); font-size: 20px; }
.calendar-row p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.empty-state { padding: clamp(44px, 10vw, 100px) 24px; color: var(--muted); text-align: center; }
.empty-state h2 { color: var(--text); }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 20px; display: grid; place-items: center; border-radius: 20px; color: var(--accent); background: var(--accent-soft); font-size: 30px; }
.settings-list { display: grid; gap: 12px; }
.setting-row { padding: 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.setting-row p { margin: 4px 0 0; color: var(--muted); }
.setting-row > span { color: var(--accent); font-size: 13px; }

dialog { width: min(520px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 12, 20, .55); backdrop-filter: blur(5px); }
dialog form { padding: 26px; display: grid; gap: 9px; }
.form-field { display: grid; gap: 9px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.checkbox-row input { width: 18px; height: 18px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 28px; padding: 12px 18px; border-radius: 12px; color: white; background: #242738; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 20px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav, .mobile-only { display: none; }

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 15; inset: 0 auto 0 0; width: min(300px, 86vw); visibility: hidden; pointer-events: none; transform: translateX(-102%); transition: transform .2s ease, visibility 0s linear .2s; box-shadow: var(--shadow); }
  .menu-open .sidebar { visibility: visible; pointer-events: auto; transform: translateX(0); transition-delay: 0s; }
  .app-view { padding: 24px 18px 150px; }
  .mobile-only { display: grid; }
  .mobile-nav { position: fixed; z-index: 10; left: 10px; right: 10px; bottom: 8px; padding: 6px; display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); border-radius: 18px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
  .mobile-nav .nav-item { min-width: 0; min-height: 52px; padding: 5px 2px; display: flex; flex-direction: column; justify-content: center; gap: 3px; font-size: 17px; text-align: center; }
  .mobile-nav small { font-size: 9px; }
  .composer { left: 12px; right: 12px; bottom: 76px; }
  .today-grid { grid-template-columns: 1fr; }
  .welcome-card { grid-column: auto; }
  .message { max-width: 91%; }
}

@media (max-width: 520px) {
  .login-panel { padding: 30px 22px; border-radius: 22px; }
  .calendar-row { grid-template-columns: 42px 1fr; }
  .calendar-row .secondary-button { grid-column: 2; justify-self: start; }
  .topbar { min-height: 62px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
