/* ============================================================
   os.st.xmail.client — Apple / macOS Light design system
   Tokens follow the spec: white cards, #F3F4F6 canvas, #E5E7EB
   borders, gray text hierarchy, system blue + emerald accents.
   ============================================================ */
:root {
  --bg: #f3f4f6;
  --bg-blur: rgba(249, 250, 251, .82);
  --card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #6b7280;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --blue-soft: #eff6ff;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --amber: #f59e0b;
  --amber-soft: #fffbeb;
  --red: #ef4444;
  --red-soft: #fef2f2;
  --r-lg: 12px;
  --r-md: 10px;
  --r-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .16);
  --font: Inter, -apple-system, "SF Pro Text", "Segoe UI", system-ui, "PingFang HK", "Microsoft JhengHei", sans-serif;
  --ease: cubic-bezier(.21, 1.02, .73, 1);
}

* { box-sizing: border-box; }
/* Class rules like .switch { display:inline-flex } would otherwise defeat the
   hidden attribute — keep [hidden] authoritative for the JS visibility toggles. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 85% -10%, #e8f0fe 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 110%, #eef7f2 0%, transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--blue); text-decoration: none; }
.muted { color: var(--text-3); font-size: 13px; }
.mono { font-family: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ---------- top navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px;
  background: var(--bg-blur);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: -.02em; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--blue) 0%, #3b82f6 60%, #60a5fa 100%);
  color: #fff; box-shadow: var(--shadow-sm);
}
nav.tabs { display: flex; gap: 4px; }
nav.tabs button {
  display: flex; align-items: center; gap: 7px;
  border: 0; background: transparent; color: var(--text-2);
  padding: 7px 13px; border-radius: 999px; font: inherit; font-weight: 500; cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
nav.tabs button:hover { background: #eceff3; color: var(--text); }
nav.tabs button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.spacer { flex: 1; }
.search {
  display: flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; width: 240px; color: var(--text-3);
  transition: box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .14); }
.search input { border: 0; outline: 0; background: transparent; font: inherit; color: var(--text); width: 100%; }
.userchip {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px 5px 8px; font-size: 13px; color: var(--text-2); box-shadow: var(--shadow-sm);
}
.userchip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }

/* language picker on the login card — top-right corner, same look as the topbar one */
.login-langsel { position: absolute; top: 12px; right: 12px; width: auto; }

.loading-wait { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 34px 0; }
.loading-wait .upd-spin { width: 40px; height: 40px; border-width: 3px; }

/* clickable BAN-type chips on the filter-log card: active state = currently filtering */
.logchip.active { outline: 2px solid var(--blue); outline-offset: 1px; }

/* role-scoped manuals (markdown rendered) */
.manual-sec { margin-top: 6px; }
.md-h { font-size: 14px; font-weight: 650; margin: 14px 0 6px; }
h2.md-h { font-size: 17px; } /* manual title (#) — must lead its subsections */
h3.md-h { font-size: 15px; }
.md-p { font-size: 13px; line-height: 1.65; margin: 5px 0; color: var(--text-2); }
.md-ul, .md-ol { margin: 6px 0 10px 22px; font-size: 13px; line-height: 1.7; color: var(--text-2); }
.md-ul code, .md-ol code, .md-p code, .manual-sec code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.md-hr { border: none; border-top: 1px solid var(--border); margin: 18px 0 6px; }
.manual-sec a { color: var(--blue); }

/* build version chip — visible to every signed-in user (static build-number.json) */
.verchip { font-size: 11px; color: var(--muted, #8a94a6); padding: 3px 9px; border: 1px solid rgba(125, 125, 125, .25); border-radius: 999px; white-space: nowrap; }
/* Standing rule: OST copyright line at the bottom of every page (all views, login included). */
.app-footer { text-align: center; font-size: 11px; color: var(--muted, #8a94a6); padding: 14px 8px 16px; letter-spacing: .02em; }
.login-ver { margin-top: 12px; text-align: center; font-size: 11px; color: var(--muted, #8a94a6); }
.login-copy { margin-top: 18px; text-align: center; font-size: 11px; color: var(--muted, #8a94a6); }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: .45; } 100% { opacity: 1; } }

/* ---------- buttons ---------- */
button { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-strong); background: var(--card); color: var(--text);
  border-radius: var(--r-sm); padding: 8px 14px; font-weight: 500;
  transition: all .16s var(--ease); box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
.btn.danger { color: var(--red); border-color: #fecaca; background: var(--card); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: #eceff3; color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ---------- layout & cards ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 26px 24px 60px; }
.view { display: none; animation: fade .25s var(--ease); }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 980px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}
.card.hoverable:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card h3 { font-size: 13px; color: var(--text-3); font-weight: 550; text-transform: uppercase; letter-spacing: .04em; }
.card .big { font-size: 30px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; }
.card .sub { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; }
.card-head .spacer { flex: 1; }
.icon-tile { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.icon-tile.blue { background: var(--blue-soft); color: var(--blue); }
.icon-tile.green { background: var(--green-soft); color: var(--green); }
.icon-tile.amber { background: var(--amber-soft); color: var(--amber); }
.icon-tile.red { background: var(--red-soft); color: var(--red); }

/* ---------- badges & status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  padding: 2.5px 9px; border-radius: 999px;
  background: #f1f3f6; color: var(--text-2); border: 1px solid var(--border);
}
.badge.green { background: var(--green-soft); color: #047857; border-color: #a7f3d0; }
.badge.blue { background: var(--blue-soft); color: #1e40af; border-color: #bfdbfe; }
.badge.amber { background: var(--amber-soft); color: #b45309; border-color: #fde68a; }
.badge.red { background: var(--red-soft); color: #b91c1c; border-color: #fecaca; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- progress ---------- */
.progress { height: 8px; border-radius: 999px; background: #eef0f3; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--blue), #60a5fa); transition: width .5s var(--ease); }
.progress.warn > i { background: linear-gradient(90deg, var(--amber), #fbbf24); }
.progress.ok > i { background: linear-gradient(90deg, var(--green), #34d399); }

/* ---------- tables ---------- */
.tablewrap { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fafbfc;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid #f1f2f5; font-size: 13.5px; }
tbody tr { transition: background .12s var(--ease); }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 6px; }
.empty { padding: 34px; text-align: center; color: var(--text-3); }

/* ---------- forms ---------- */
.field { display: grid; gap: 5px; margin-bottom: 13px; }
.field label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
input[type=text], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 9px 12px; outline: 0; width: 100%;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .14); }
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.formgrid .full { grid-column: 1 / -1; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.switch input { width: 36px; height: 21px; appearance: none; border-radius: 999px; background: #d6dae1; position: relative; transition: background .18s var(--ease); cursor: pointer; border: 0; padding: 0; }
.switch input::after { content: ""; position: absolute; inset: 2px auto 2px 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .18s var(--ease); }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(15px); }

/* ---------- login ---------- */
.login-stage { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.login-card {
  position: relative;
  width: 400px; max-width: 94vw; background: var(--card);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
  padding: 34px 34px 28px; animation: fade .35s var(--ease);
}
.login-card .logo-lg {
  width: 56px; height: 56px; border-radius: 15px; margin: 0 auto 14px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, var(--blue), #60a5fa);
  box-shadow: 0 10px 24px rgba(37, 99, 235, .35);
}
.login-card h1 { text-align: center; font-size: 20px; }
.login-card .sub { text-align: center; color: var(--text-3); font-size: 13px; margin: 4px 0 22px; }
.login-card .btn.primary { width: 100%; justify-content: center; padding: 11px; font-size: 15px; border-radius: 10px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: rgba(17, 24, 39, .35); backdrop-filter: blur(3px);
  place-items: center;
}
.modal-backdrop.open { display: grid; animation: fade .18s var(--ease); }
.modal {
  width: 560px; max-width: 94vw; max-height: 86vh; overflow: auto;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: pop .22s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(8px); } to { opacity: 1; transform: none; } }

/* modal busy state: Save (or any ok-action) covers the form with a spinner until the
   server answers; the form stays in the DOM so a failure uncovers it untouched. */
#modalBody { position: relative; }
.modal-loading { position: absolute; inset: -6px; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--card) 80%, transparent); border-radius: 12px; z-index: 5; }
.modal-loading .upd-spin { width: 40px; height: 40px; border-width: 3px; }

/* V1 WebMail upgrade notice settings table (compact 5-column layout inside the modal) */
.v1tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.v1tbl th, .v1tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border, #e5e7eb); vertical-align: top; }
.v1tbl th { color: var(--muted, #8a94a6); font-weight: 600; }
.v1tbl code { background: var(--bg2, #f6f7f9); padding: 1px 6px; border-radius: 5px; }

/* animated update overlay (the os.st.ost pattern): spinner + indeterminate bar + entrance */
.upd-backdrop { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; background: rgba(0, 0, 0, .6); animation: fade .25s ease-out; }
.upd-card { width: 380px; max-width: 92vw; background: #fff; border-radius: 14px; padding: 24px; text-align: center; box-shadow: var(--shadow-lg); animation: upd-pop .3s cubic-bezier(.2, .9, .3, 1.15); }
.upd-card h3 { font-size: 16px; font-weight: 600; }
.upd-versions { margin-top: 4px; font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-3); }
.upd-card .sub { margin-top: 8px; }
.upd-spin { width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 50%; border: 4px solid #e2e8f0; border-top-color: #059669; animation: upd-spin .9s linear infinite; }
@keyframes upd-spin { to { transform: rotate(360deg); } }
@keyframes upd-pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.upd-bar { margin-top: 16px; height: 6px; width: 100%; border-radius: 999px; background: #f1f5f9; overflow: hidden; }
.upd-bar i { display: block; height: 100%; width: 33%; border-radius: 999px; background: #059669; animation: upd-slide 1.2s ease-in-out infinite; }
@keyframes upd-slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(330%); } }

/* forced license gate overlay — blocks the whole app until a god login activates */
.licgate-backdrop {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: rgba(17, 24, 39, .55); backdrop-filter: blur(4px); animation: fade .18s var(--ease);
}
.licgate-card {
  width: 460px; max-width: 94vw; background: var(--card); border-radius: 16px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border); padding: 28px;
  animation: pop .22s var(--ease);
}
.licgate-card .logo-lg { margin: 0 auto 10px; }
.licgate-card h2 { text-align: center; font-size: 18px; }
.licgate-card .sub { text-align: center; color: var(--text-3); font-size: 13px; margin: 6px 0 18px; }
.licgate-card .btn { justify-content: center; }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal header h2 { font-size: 15.5px; flex: 1; }
.modal .body { padding: 18px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfc; border-radius: 0 0 16px 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  z-index: 200; display: flex; align-items: center; gap: 9px;
  background: #111827; color: #fff; border-radius: 11px; padding: 11px 18px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: #7f1d1d; }

/* ---------- misc ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 13px; }
.kv b { color: var(--text-3); font-weight: 500; }
.feed { display: grid; gap: 0; }
.feed .row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f1f2f5; font-size: 13px; }
.feed .row:last-child { border-bottom: 0; }
.feed .when { color: var(--text-3); font-size: 12px; margin-left: auto; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar h2 { font-size: 19px; letter-spacing: -.02em; }
.skeleton { position: relative; overflow: hidden; background: #eef0f3; border-radius: 6px; height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
select.langsel { width: auto; padding: 6px 10px; border-radius: 999px; font-size: 12.5px; background: var(--card); border: 1px solid var(--border); color: var(--text-2); }
