/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
button { font: inherit; cursor: pointer; background: none; border: 0; color: inherit; }

:root {
  /* iOS dark mode greys */
  --bg-base: #000;
  --bg-1: #1c1c1e;
  --bg-2: #2c2c2e;
  --bg-3: #3a3a3c;
  --bg-elev: rgba(28, 28, 30, 0.72);
  --separator: rgba(84, 84, 88, 0.36);
  --separator-strong: rgba(84, 84, 88, 0.65);

  /* iOS labels */
  --label-1: #ffffff;
  --label-2: rgba(235, 235, 245, 0.62);
  --label-3: rgba(235, 235, 245, 0.32);
  --label-4: rgba(235, 235, 245, 0.18);

  /* iOS system colors */
  --blue: #0a84ff;
  --indigo: #5e5ce6;
  --purple: #bf5af2;
  --pink: #ff375f;
  --red: #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffd60a;
  --green: #30d158;
  --teal: #64d2ff;

  --accent: var(--blue);
  --accent-soft: rgba(10, 132, 255, 0.16);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --shadow-soft: 0 1px 2px rgba(0,0,0,0.18), 0 6px 24px rgba(0,0,0,0.22);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.45);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
               'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--label-1);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

.root { height: 100%; }

/* ─── Auth ────────────────────────────────────────────────────────────────── */
#auth-root {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #0a0a0c;
}
.auth-bg {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(circle at 25% 30%, rgba(94, 92, 230, 0.35), transparent 45%),
    radial-gradient(circle at 75% 70%, rgba(48, 209, 88, 0.18), transparent 50%),
    radial-gradient(circle at 50% 90%, rgba(191, 90, 242, 0.18), transparent 50%);
  filter: blur(60px);
  pointer-events: none;
  animation: drift 20s ease-in-out infinite;
}
@keyframes drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-2%, 1%); }
}
.auth-card {
  position: relative;
  background: rgba(28, 28, 30, 0.65);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 28px;
  padding: 44px 48px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: pop-in 0.5s var(--ease) both;
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.auth-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 18px 0 4px;
  letter-spacing: -0.025em;
}
.auth-sub {
  font-size: 14px;
  color: var(--label-2);
  margin: 0 0 28px;
}
.g-signin { display: flex; justify-content: center; }
.auth-error { color: var(--red); font-size: 13px; margin: 14px 0 0; min-height: 18px; }

/* ─── Brand mark ─────────────────────────────────────────────────────────── */
.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  background: linear-gradient(135deg, var(--indigo) 0%, var(--purple) 100%);
  border-radius: 16px;
  font-weight: 700;
  font-size: 28px;
  color: #fff;
  box-shadow: 0 8px 24px rgba(94, 92, 230, 0.35), inset 0 1px 0 rgba(255,255,255,0.18);
}
.brand-mark.sm {
  width: 28px;
  height: 28px;
  font-size: 14px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(94, 92, 230, 0.3), inset 0 1px 0 rgba(255,255,255,0.18);
}
.brand-mark.lg {
  width: 64px;
  height: 64px;
  font-size: 32px;
  border-radius: 18px;
  margin-bottom: 14px;
}

/* ─── App layout ──────────────────────────────────────────────────────────── */
#app-root { display: flex; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-elev);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-right: 1px solid var(--separator);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 22px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.navitem {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--label-2);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
.navitem:hover { background: rgba(255,255,255,0.05); color: var(--label-1); }
.navitem.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.navitem:active { transform: scale(0.98); }
.navitem svg { flex-shrink: 0; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 6px;
  border-top: 1px solid var(--separator);
  margin-top: 8px;
}
#user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg-3);
  object-fit: cover;
}
.user-meta { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-size: 11px;
  color: var(--label-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  color: var(--label-2);
  display: grid;
  place-items: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover { background: rgba(255,255,255,0.07); color: var(--label-1); }

/* ─── Main / views ────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-base);
  position: relative;
}
.view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.view.active {
  display: flex;
  animation: fade-in 0.3s var(--ease) both;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 36px 44px 48px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}
.page-header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.page-sub {
  color: var(--label-2);
  margin: 4px 0 0;
  font-size: 15px;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary, .btn-ghost, .btn-danger {
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s var(--ease), transform 0.08s var(--ease);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #1a8cff; }
.btn-primary:active { transform: scale(0.97); }
.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: var(--label-1);
}
.btn-ghost:hover { background: rgba(255,255,255,0.12); }
.btn-danger {
  background: rgba(255, 69, 58, 0.15);
  color: var(--red);
}
.btn-danger:hover { background: rgba(255, 69, 58, 0.25); }

.link-btn {
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 0;
  transition: opacity 0.15s var(--ease);
}
.link-btn:hover { opacity: 0.75; }

/* ─── Segmented control (iOS) ─────────────────────────────────────────────── */
.segmented {
  display: inline-flex;
  background: var(--bg-2);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--label-2);
  border-radius: 7px;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.segmented button.active {
  background: var(--bg-3);
  color: var(--label-1);
  box-shadow: 0 0 0 0.5px rgba(0,0,0,0.04), 0 3px 8px rgba(0,0,0,0.12);
}

/* ─── Dashboard ───────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 36px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-1);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: left;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.stat-card:hover {
  transform: translateY(-2px);
  background: var(--bg-2);
  border-color: var(--separator-strong);
}
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.ico-blue   { background: rgba(10, 132, 255, 0.18); color: var(--blue); }
.ico-violet { background: rgba(191, 90, 242, 0.18); color: var(--purple); }
.ico-orange { background: rgba(255, 159, 10, 0.18); color: var(--orange); }
.ico-green  { background: rgba(48, 209, 88, 0.18); color: var(--green); }
.ico-pink   { background: rgba(255, 55, 95, 0.18); color: var(--pink); }
.stat-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-label {
  font-size: 12px;
  color: var(--label-2);
  margin-top: 2px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.block { margin-bottom: 30px; }
.block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.block-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ─── Card lists ──────────────────────────────────────────────────────────── */
.card-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}
.card-list li {
  background: var(--bg-1);
  border: 1px solid var(--separator);
  border-radius: 0;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border-bottom: none;
  transition: background 0.15s var(--ease);
  cursor: pointer;
}
.card-list li:first-child { border-top-left-radius: var(--radius-lg); border-top-right-radius: var(--radius-lg); }
.card-list li:last-child { border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: var(--radius-lg); border-bottom: 1px solid var(--separator); }
.card-list li + li { border-top: 0.5px solid var(--separator); }
.card-list li:hover { background: var(--bg-2); }
.card-list li.no-hover { cursor: default; background: var(--bg-1) !important; }

.card-list .body-col { flex: 1; min-width: 0; }
.card-list .title {
  font-weight: 500;
  font-size: 15px;
  color: var(--label-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-list .meta {
  font-size: 13px;
  color: var(--label-2);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-list .preview {
  font-size: 13px;
  color: var(--label-3);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}
.card-list .accessory {
  color: var(--label-3);
  flex-shrink: 0;
}
.card-list .actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.card-list li.empty {
  background: transparent;
  border: 1px dashed var(--separator-strong);
  border-radius: var(--radius-lg);
  color: var(--label-3);
  justify-content: center;
  padding: 28px;
  font-size: 14px;
  cursor: default;
}
.card-list li.empty:hover { background: transparent; }
.card-list .error { color: var(--red); border-color: rgba(255, 69, 58, 0.3); }

.card-list.compact li { padding: 12px 18px; }
.card-list.compact .title { font-size: 14px; }
.card-list.compact .meta  { font-size: 12px; }

/* Color accent strip for list items */
.card-list li .leading {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
}
.lead-stack { flex-direction: column; gap: 0; font-size: 11px; line-height: 1.05; padding: 4px; }
.lead-stack .day-num { font-size: 16px; font-weight: 700; }
.lead-stack .day-wd { font-size: 10px; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.05em; }
.lead-blue   { background: rgba(10, 132, 255, 0.18); color: var(--blue); }
.lead-orange { background: rgba(255, 159, 10, 0.18); color: var(--orange); }
.lead-purple { background: rgba(191, 90, 242, 0.18); color: var(--purple); }
.lead-green  { background: rgba(48, 209, 88, 0.18); color: var(--green); }
.lead-pink   { background: rgba(255, 55, 95, 0.18); color: var(--pink); }

/* ─── Chat ────────────────────────────────────────────────────────────────── */
[data-view="chat"] { padding: 0; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 32px 44px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--label-2);
  animation: fade-in 0.4s var(--ease) both;
}
.empty-title {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--label-1);
  letter-spacing: -0.02em;
}
.empty-sub { font-size: 14px; color: var(--label-2); }

.bubble {
  max-width: 70%;
  padding: 11px 16px;
  border-radius: 20px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
  animation: bubble-in 0.25s var(--ease) both;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.bubble a { color: #fff; text-decoration: underline; }
.bubble.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.bubble.assistant {
  background: var(--bg-1);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
}
.bubble.assistant a { color: var(--accent); }
.bubble.pending {
  color: var(--label-3);
  font-style: italic;
}
.bubble.error {
  background: rgba(255, 69, 58, 0.12);
  color: var(--red);
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 14px 44px 22px;
  background: var(--bg-base);
}
#chat-input {
  flex: 1;
  padding: 13px 18px;
  background: var(--bg-1);
  border: 1px solid var(--separator);
  border-radius: 999px;
  color: var(--label-1);
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease);
}
#chat-input:focus { border-color: var(--accent); background: var(--bg-2); }
#chat-input::placeholder { color: var(--label-3); }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
}
.send-btn:hover { background: #1a8cff; }
.send-btn:active { transform: scale(0.92); }

/* ─── Modal ───────────────────────────────────────────────────────────────── */
dialog.modal {
  background: rgba(44, 44, 46, 0.92);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  color: var(--label-1);
  padding: 0;
  width: 460px;
  max-width: 92vw;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.25s var(--ease) both;
}
dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}
dialog.modal form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 22px 18px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -4px -4px 4px;
}
.modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
dialog.modal input, dialog.modal textarea {
  padding: 11px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--label-1);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
dialog.modal input:focus, dialog.modal textarea:focus {
  border-color: var(--accent);
  background: rgba(255,255,255,0.04);
}
dialog.modal input::placeholder, dialog.modal textarea::placeholder { color: var(--label-3); }
dialog.modal textarea { resize: vertical; font-family: inherit; line-height: 1.5; }
.hint { color: var(--label-3); font-size: 12px; margin: 0; }
dialog.modal menu {
  display: flex;
  gap: 8px;
  padding: 0;
  margin: 6px 0 0;
  align-items: center;
}
.grow { flex: 1; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .sidebar { width: 64px; padding: 12px 8px; }
  .sidebar-brand span, .navitem span, .user-meta { display: none; }
  .navitem { justify-content: center; padding: 10px; }
  .sidebar-user { justify-content: center; }
  #sign-out { display: none; }
  .view-scroll { padding: 24px 20px; }
  .chat-log, .chat-form { padding-left: 18px; padding-right: 18px; }
  .page-header h1 { font-size: 26px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Scrollbar */
.view-scroll::-webkit-scrollbar, .chat-log::-webkit-scrollbar { width: 8px; }
.view-scroll::-webkit-scrollbar-thumb, .chat-log::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: 4px;
  border: 2px solid var(--bg-base);
}
