:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-muted: #F1F5F9;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748B;
  --accent: #4F46E5;
  --accent-soft: #EEF2FF;
  --accent-hover: #4338CA;
  --danger: #DC2626;
  --danger-soft: #FEF2F2;
  --success: #059669;
  --success-soft: #ECFDF5;
  --warn: #D97706;
  --warn-soft: #FEF3C7;
  --radius: 12px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted-sm { font-size: 12px; color: var(--text-muted); }
.full-width { width: 100%; }

/* Auth */
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.brand-logo { width: 34px; height: 34px; border-radius: 9px; }
.brand-name { display: block; font-weight: 700; font-size: 15px; }
.brand-domain { display: block; font-size: 11px; color: var(--text-muted); }
.auth-desc { font-size: 13px; color: var(--text-muted); margin: 0 0 16px; line-height: 1.5; }
.pin-form { display: flex; gap: 8px; margin-bottom: 10px; }
.pin-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.auth-status { font-size: 12px; color: var(--accent); min-height: 18px; margin: 10px 0 0; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--surface-muted); }
.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #FECACA;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost-sm {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
}

/* 3-Column App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 240px 370px 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--surface);
}

.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
}
.compose-cta { margin-bottom: 16px; }

.nav-list { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.count-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.count-pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.sidebar-section { margin-top: 20px; }
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-left: 4px;
}
.provider-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

.storage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.storage-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}
.storage-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
  margin-bottom: 6px;
}
.storage-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.storage-sub { font-size: 11px; color: var(--text-muted); }

/* Middle List Column */
.list-col {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--surface);
}
.list-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.search-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13px;
  background: var(--bg);
}
.filter-row { display: flex; gap: 6px; }
.filter-tab {
  border: none;
  background: transparent;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.filter-tab.active { background: var(--surface-muted); color: var(--text); font-weight: 600; }

.list-banner {
  padding: 10px 14px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mail-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mail-card {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease;
}
.mail-card:hover { background: var(--bg); }
.mail-card.selected {
  background: var(--accent-soft);
  border-color: #C7D2FE;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.mail-card-body { flex: 1; min-width: 0; }
.mail-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.mail-sender {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.mail-subject {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.mail-snippet {
  font-size: 12px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.mail-badges {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
}
.badge.gmail { background: #FEE2E2; color: #B91C1C; }
.badge.outlook { background: #E0F2FE; color: #0369A1; }
.badge.drive { background: var(--success-soft); color: var(--success); }

/* Right Reader Column */
.reader-col {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
  min-width: 0;
}
.reader-empty {
  margin: auto;
  text-align: center;
  max-width: 340px;
  padding: 24px;
  color: var(--text-muted);
}
.empty-illustration { font-size: 36px; margin-bottom: 10px; }
.reader-empty h2 { margin: 0 0 6px; font-size: 17px; color: var(--text); }
.reader-empty p { margin: 0; font-size: 13px; line-height: 1.5; }

.reader-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.toolbar-actions { display: flex; gap: 8px; }
.reader-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.thread-header h2 { margin: 0 0 8px; font-size: 20px; line-height: 1.3; }
.meta-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.thread-messages { display: flex; flex-direction: column; gap: 12px; }
.msg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.msg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--surface);
}
.msg-head-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.msg-sender { font-size: 13px; font-weight: 600; }
.msg-date { font-size: 11px; color: var(--text-muted); }
.msg-body {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.6;
}
.msg-body pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-sans);
  font-size: 13.5px;
}
.msg-iframe {
  width: 100%;
  min-height: 280px;
  border: none;
  background: #fff;
}

.attachments-section h3 { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.attachments-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.att-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.att-actions { display: flex; gap: 6px; }

.reply-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.reply-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.reply-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.select-sm {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  background: var(--bg);
}
.reply-box textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  resize: vertical;
}
.reply-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.modal-card {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.compose-form { display: flex; flex-direction: column; gap: 10px; }
.compose-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.compose-form input, .compose-form select, .compose-form textarea {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  font-family: var(--font-sans);
  font-size: 13px;
}
.modal-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }

/* Cleanup & History Cards */
.cleanup-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface);
}
.history-ask-box { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.history-answer {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
}

.mobile-only { display: none; }

@media (max-width: 960px) {
  .mobile-only { display: inline-grid; }
  .app-shell { grid-template-columns: 1fr; position: relative; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,0.15); }
  .reader-col {
    position: fixed;
    inset: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }
  .reader-col.open { transform: translateX(0); }
}
