:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-subtle: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --primary: #111827;
  --primary-hover: #1f2937;
  --accent: #0f766e;
  --accent-bg: #ecfdf5;
  --accent-text: #047857;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --overlay: rgba(17, 24, 39, 0.36);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-drawer: -12px 0 40px rgba(17, 24, 39, 0.14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --sidebar-w: 232px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
code, pre, .code-area { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon { display: inline-block; flex: none; vertical-align: middle; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.num { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.panel-open { overflow: hidden; }

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100svh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #111827 0%, #374151 100%);
  color: #ffffff;
}

.brand-mark--lg { width: 44px; height: 44px; border-radius: 12px; }
.brand-mark--lg .icon { width: 22px; height: 22px; }

.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: 14px; font-weight: 700; letter-spacing: -0.02em; }
.brand-text small { font-size: 11px; color: var(--muted); margin-top: 2px; }

.env-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-link .icon { width: 17px; height: 17px; color: var(--muted); }
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link[aria-current="page"] {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}
.nav-link[aria-current="page"] .icon { color: var(--text); }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.tz-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
}

.tz-badge .icon { width: 14px; height: 14px; }

.nav-logout {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.nav-logout:hover { background: var(--bg); color: var(--text); }
.nav-logout .icon { width: 16px; height: 16px; color: var(--muted); }

/* Workspace */
.workspace {
  padding: 32px 36px 56px;
  min-width: 0;
}

.workspace-inner {
  max-width: 1040px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-head h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.page-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* Cards & Buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn .icon { width: 15px; height: 15px; }
.btn:hover:not(:disabled) { background: var(--bg); }

.btn--primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}
.btn--primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.btn--subtle {
  border-color: var(--border);
  background: var(--surface-subtle);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}
.btn--ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn--danger {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}
.btn--danger:hover:not(:disabled) { border-color: var(--danger); }

.btn--sm { min-height: 30px; padding: 0 10px; font-size: 12px; }
.btn--sm .icon { width: 13px; height: 13px; }
.btn--block { width: 100%; min-height: 40px; }

.btn-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.btn-link:hover { text-decoration: underline; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge > i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--green { background: var(--accent-bg); color: var(--accent-text); }
.badge--red { background: var(--danger-bg); color: var(--danger); }

.chip-list, .chip-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  word-break: break-all;
}

/* Toast */
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

.toast--success {
  border-color: #a7f3d0;
  background: var(--accent-bg);
  color: var(--accent-text);
}

.toast-icon { display: flex; flex: none; }
.toast-icon .icon { width: 16px; height: 16px; }
.stack > .toast { margin-bottom: 0; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-value--accent { color: var(--accent); }

/* Account Cards */
.account-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.account-card {
  padding: 20px 22px;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.account-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.account-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.account-who {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.account-who-text { min-width: 0; }
.account-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.account-title-row h2 { font-size: 15px; font-weight: 700; }
.account-sub-row { display: flex; align-items: center; gap: 10px; margin-top: 2px; flex-wrap: wrap; }

.account-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.account-meta-grid {
  display: grid;
  grid-template-columns: 110px 140px minmax(0, 1.2fr) minmax(0, 1.4fr);
  gap: 14px 20px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.meta-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.meta-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.meta-value { font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.meta-hint { font-size: 11px; color: var(--muted); }

/* Empty Box */
.empty-box {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 10px;
  padding: 56px 24px;
}

.empty-badge {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}

.empty-badge .icon { width: 22px; height: 22px; }
.empty-box h2 { font-size: 16px; font-weight: 700; margin-top: 4px; }
.empty-box p { font-size: 13px; max-width: 360px; }
.empty-box .btn { margin-top: 6px; }

/* Notifications Page */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.log-card { overflow: hidden; }

.log-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.log-head-left { display: grid; gap: 8px; min-width: 0; }
.log-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.log-title-row h2 { font-size: 14px; font-weight: 700; }
.log-meta-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.log-head-right { display: flex; align-items: center; gap: 8px; flex: none; }

.log-card-body { padding: 16px 20px; background: var(--surface-subtle); }

.mail-frame {
  display: block;
  width: 100%;
  height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.mail-pre {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log-error { margin-top: 10px; font-weight: 500; }

/* SMTP Page */
.smtp-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
}

.panel-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}

.panel-card-head h2 { font-size: 15px; font-weight: 700; }
.panel-card-body { padding: 20px 22px; }

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 14px;
}

.field-row--equal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-actions { padding-top: 4px; }

.kv-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.kv-value { font-size: 13px; overflow-wrap: anywhere; }

/* Form Controls */
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.08);
  outline: none;
}

.field textarea { resize: vertical; line-height: 1.5; }
.code-area { min-height: 132px; font-size: 12px; }

.cron-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.cron-hint .icon { width: 13px; height: 13px; }
.cron-hint output { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.cron-hint output[data-error] { color: var(--danger); }

/* Drawer */
.drawer-layer, .drawer-backdrop { position: fixed; inset: 0; }
.drawer-layer { z-index: 20; }
.drawer-backdrop { background: var(--overlay); backdrop-filter: blur(2px); }

.drawer {
  position: absolute;
  inset: 0 0 0 auto;
  width: min(100%, 480px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-drawer);
}

.drawer:focus { outline: none; }

.drawer-head, .drawer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding: 18px 22px;
}

.drawer-head { border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 16px; font-weight: 700; }
.drawer-head p { margin-top: 2px; }
.drawer-foot { justify-content: end; border-top: 1px solid var(--border); background: var(--surface-subtle); }

.drawer-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 20px 22px;
}

.drawer-empty { padding: 32px 0; text-align: center; }

.sub-box {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.sub-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
.replace-toggle { margin-top: 10px; }
.replace-toggle > summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.replace-toggle > summary .icon { width: 14px; height: 14px; transition: transform 0.15s ease; }
.replace-toggle[open] > summary .icon { transform: rotate(90deg); }
.replace-toggle .stack { margin-top: 12px; }

.danger-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-md);
  background: var(--danger-bg);
}
.danger-box strong { font-size: 13px; color: var(--danger); }

.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-item {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}
.task-item-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.task-item-top strong { font-size: 13px; font-weight: 650; line-height: 1.4; overflow-wrap: anywhere; }
.task-item-grid { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.task-reward { color: var(--accent-text); font-weight: 700; }

/* Login Page */
.auth-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(15, 118, 110, 0.08), transparent 70%),
    var(--bg);
}

.auth-container {
  width: min(100%, 380px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.auth-brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.auth-brand p { font-size: 13px; }
.auth-card { padding: 24px; box-shadow: var(--shadow-md); }

/* Responsive */
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-top { padding: 0; }
  .brand-text small, .tz-badge { display: none; }
  .nav-menu { flex-direction: row; flex: 0 1 auto; }
  .nav-link { padding: 7px 10px; font-size: 13px; }
  .sidebar-footer { flex-direction: row; padding-top: 0; border-top: 0; }
  .nav-logout span { display: none; }
  .workspace { padding: 20px 16px 40px; }
  .account-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .meta-cell--wide { grid-column: 1 / -1; }
  .smtp-layout { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .page-head { flex-direction: column; align-items: start; }
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 20px; }
  .nav-link span { display: none; }
  .field-row, .field-row--equal { grid-template-columns: 1fr; }
  .drawer { width: 100%; border-left: 0; }
}
