/* ============================================================
   Zabi Mail Box — giao dien mail client 3 cot
   Light theme mac dinh, co dark mode qua [data-theme="dark"]
   ============================================================ */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f4;
  --border: #e3e6ec;
  --border-strong: #d2d7e0;

  --text: #0f1729;
  --text-2: #5a6478;
  --text-3: #98a0b3;

  --accent: #5b5bd6;
  --accent-hover: #4a4ac4;
  --accent-soft: #eeeeff;
  --accent-ring: rgba(91, 91, 214, 0.18);

  --success: #0f9d58;
  --success-soft: #e6f6ed;
  --warn: #c2790b;
  --warn-soft: #fdf3e2;
  --danger: #d92d20;
  --danger-soft: #fdeceb;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 18px 44px rgba(16, 24, 40, 0.16);

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;

  --sidebar-w: 268px;
  --list-w: 392px;
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
}

[data-theme='dark'] {
  --bg: #0a0c12;
  --surface: #12141c;
  --surface-2: #171a24;
  --surface-3: #1e222e;
  --border: #252936;
  --border-strong: #333848;

  --text: #e8eaf0;
  --text-2: #98a0b3;
  --text-3: #697087;

  --accent: #8b8bf5;
  --accent-hover: #9d9dff;
  --accent-soft: #1c1d35;
  --accent-ring: rgba(139, 139, 245, 0.22);

  --success: #3ccb7f;
  --success-soft: #11271d;
  --warn: #f5a524;
  --warn-soft: #2a2010;
  --danger: #f97066;
  --danger-soft: #2d1515;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ============================ SHELL ============================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ============================ SIDEBAR ============================ */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand img { width: 36px; height: 36px; border-radius: 10px; flex: none; }

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.brand-tag {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
}

.side-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

/* --- o nhap dia chi --- */
.field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  padding: 9px 0;
  font-family: var(--mono);
  font-size: 12.5px;
}

.field input::placeholder { color: var(--text-3); font-family: var(--font); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-soft {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  width: 100%;
}
.btn-soft:hover { background: var(--surface-3); color: var(--text); }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--r-sm);
  color: var(--text-2);
  flex: none;
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* --- the hop thu dang mo --- */
.active-box {
  background: linear-gradient(140deg, var(--accent-soft), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 13px 14px;
}

.active-box.idle { background: var(--surface-2); }

.active-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent);
  animation: ping 2s ease-out infinite;
  flex: none;
}

@keyframes ping {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.active-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--success);
}

.active-email {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  word-break: break-all;
  margin-bottom: 10px;
}

.active-actions { display: flex; gap: 6px; }

.chip-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  padding: 6px 8px;
  transition: all 0.15s;
}
.chip-btn:hover { color: var(--text); border-color: var(--border-strong); }
.chip-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.chip-btn.ok { color: var(--success); border-color: var(--success); }

/* --- lich su hop thu --- */
.recent { display: flex; flex-direction: column; gap: 2px; }

.recent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border-radius: var(--r-sm);
  padding: 7px 9px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.recent-item:hover { background: var(--surface-2); color: var(--text); }
.recent-item.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.recent-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-3);
}

.meta-line b { color: var(--text-2); font-weight: 600; }

.side-links { display: flex; gap: 6px; }
.side-links .btn-soft { font-size: 11.5px; padding: 7px 10px; }

/* ============================ LIST PANE ============================ */

.list-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-width: 0;
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.pane-title { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }

.count-badge {
  background: var(--surface-3);
  color: var(--text-2);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
}

.sync-note {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.pane-tools { padding: 10px 16px; border-bottom: 1px solid var(--border); }

.list-scroll { flex: 1; overflow-y: auto; }

/* --- mot dong thu --- */
.mail-row {
  display: flex;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  transition: background 0.12s;
}

.mail-row:hover { background: var(--surface-2); }

.mail-row.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 10px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.mail-main { min-width: 0; flex: 1; }

.mail-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.mail-sender {
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.mail-time { font-size: 11px; color: var(--text-3); flex: none; font-variant-numeric: tabular-nums; }

.mail-subject {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
}

.mail-snippet {
  font-size: 12px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.otp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  background: var(--success-soft);
  color: var(--success);
  border-radius: 7px;
  padding: 3px 9px;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 1px;
}

.otp-chip small {
  font-family: var(--font);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  opacity: 0.8;
}

/* ============================ READER ============================ */

.reader {
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  min-width: 0;
}

.reader-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.reader-content[hidden] { display: none; }

.reader-empty {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 40px;
  gap: 6px;
}

.reader-empty .glyph {
  width: 60px; height: 60px;
  border-radius: 18px;
  background: var(--surface-3);
  display: grid; place-items: center;
  color: var(--text-3);
  margin-bottom: 8px;
}

.reader-empty h3 { font-size: 15px; font-weight: 650; }
.reader-empty p { font-size: 13px; color: var(--text-3); max-width: 340px; }

.reader-head {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 22px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.reader-subject {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 7px;
  word-break: break-word;
}

.reader-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12.5px;
  color: var(--text-2);
}

.reader-meta .k { color: var(--text-3); }
.reader-meta .mono { font-family: var(--mono); font-size: 12px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
}

.tag.warn { background: var(--warn-soft); color: var(--warn); }

.reader-body { flex: 1; overflow-y: auto; padding: 18px 22px 26px; }

/* --- khoi OTP noi bat --- */
.otp-card {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-lg);
  padding: 16px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.otp-card.show { display: flex; }

.otp-card-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 4px;
}

.otp-card-code {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 6px;
  line-height: 1.1;
}

.btn-copy {
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 650;
  padding: 10px 18px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-copy:hover { background: var(--accent-hover); }
.btn-copy.done { background: var(--success); }

/* --- tabs + khung noi dung --- */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }

.tab {
  border-radius: var(--r-sm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-3);
  padding: 6px 12px;
  transition: all 0.15s;
}
.tab:hover { background: var(--surface-3); color: var(--text-2); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.frame-box {
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.frame-box.show { display: block; }
.frame-box iframe { display: block; width: 100%; height: 62vh; border: none; }

.text-box {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.text-box.show { display: block; }

/* ============================ EMPTY / LOADING ============================ */

.pane-empty {
  padding: 46px 24px;
  text-align: center;
  color: var(--text-3);
}

.pane-empty .glyph {
  width: 48px; height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-3);
  display: grid; place-items: center;
}

.pane-empty strong { display: block; color: var(--text-2); font-size: 13.5px; margin-bottom: 5px; }
.pane-empty p { font-size: 12.5px; line-height: 1.6; }
.pane-empty .mono { font-family: var(--mono); color: var(--accent); }

.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.banner-error {
  display: none;
  margin: 12px 16px;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: var(--r-md);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
  padding: 10px 13px;
}
.banner-error.show { display: block; }

/* ============================ TOAST ============================ */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  align-items: center;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--text);
  color: var(--surface);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 550;
  padding: 10px 16px;
  box-shadow: var(--shadow-lg);
  animation: toast-up 0.2s ease both;
}

.toast.ok::before { content: '✓'; color: #4ade80; font-weight: 800; }
.toast.err::before { content: '!'; color: #fca5a5; font-weight: 800; }

.toast.out { animation: toast-down 0.2s ease both; }

@keyframes toast-up { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-down { to { opacity: 0; transform: translateY(10px); } }

/* ============================ MOBILE / TABLET ============================ */

.mobile-bar { display: none; }
.scrim { display: none; }

@media (max-width: 1180px) {
  .app { grid-template-columns: var(--sidebar-w) 1fr; }

  .reader {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(620px, 100%);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(102%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 60;
  }

  body.reading .reader { transform: none; }
  .frame-box iframe { height: 58vh; }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .mobile-bar .brand-name { font-size: 14px; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 282px;
    z-index: 80;
    transform: translateX(-102%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }

  body.nav-open .sidebar { transform: none; }

  body.nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(8, 11, 20, 0.45);
    z-index: 70;
  }

  .reader { width: 100%; }
  .reader-head { padding: 14px 16px; }
  .reader-body { padding: 14px 16px 22px; }
  .otp-card-code { font-size: 25px; letter-spacing: 4px; }
  .frame-box iframe { height: 64vh; }
}
