/* ===== Design tokens ===== */
:root {
  --brand-600: #2f5bea; --brand-700: #2449c4; --brand-50: #eef3ff; --brand-100: #dde6ff;
  --ink-900: #111827; --ink-700: #374151; --ink-500: #6b7280; --ink-400: #9ca3af; --ink-300: #d1d5db;
  --line: #e5e7eb; --line-soft: #f0f1f4; --bg: #f6f7f9; --panel: #ffffff; --sidebar: #f8f9fb;
  --ok: #16a34a; --ok-50: #ecfdf3; --warn: #b45309; --warn-50: #fffbeb; --danger: #dc2626; --danger-50: #fef2f2;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / .06);
  --shadow: 0 4px 16px rgb(16 24 40 / .08), 0 1px 3px rgb(16 24 40 / .06);
  --shadow-lg: 0 24px 48px -12px rgb(16 24 40 / .25);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink-900); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand-600); text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Buttons & inputs ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel); color: var(--ink-700); font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { background: #f9fafb; border-color: var(--ink-300); }
.btn:focus-visible, .input:focus-visible, .nav-item:focus-visible { outline: 3px solid var(--brand-100); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand-600); border-color: var(--brand-600); color: #fff; box-shadow: 0 1px 2px rgb(47 91 234 / .3); }
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--line-soft); border-color: transparent; }
.btn-lg { height: 44px; padding: 0 18px; font-size: 15px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--ink-700); }
.field-hint { font-size: 12px; color: var(--ink-500); }
.input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--ink-300); border-radius: var(--radius-sm); background: #fff; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--brand-600); box-shadow: 0 0 0 3px var(--brand-100); outline: none; }
.input-group { display: flex; align-items: stretch; border: 1px solid var(--ink-300); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.input-group:focus-within { border-color: var(--brand-600); box-shadow: 0 0 0 3px var(--brand-100); }
.input-group .input { border: 0; box-shadow: none; border-radius: 0; }
.input-addon { display: flex; align-items: center; padding: 0 12px; background: #f9fafb; color: var(--ink-500); border-left: 1px solid var(--line); white-space: nowrap; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--line-soft); border-radius: var(--radius); }
.segmented button { height: 32px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-700); cursor: pointer; font-weight: 500; }
.segmented button[aria-pressed="true"] { background: #fff; color: var(--brand-700); box-shadow: var(--shadow-sm); }
.form-error { margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-50); color: var(--danger); font-size: 13px; }

/* ===== Login ===== */
.login { display: grid; grid-template-columns: minmax(360px, 44%) 1fr; min-height: 100vh; }
.login-brand { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; color: #fff;
  background: radial-gradient(1200px 600px at -10% -10%, #5b7cff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #1d3fb8 0%, transparent 55%), linear-gradient(160deg, #2a4fd8, #1b2f8f); }
.login-brand::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgb(255 255 255 / .06) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / .06) 1px, transparent 1px); background-size: 40px 40px; mask-image: linear-gradient(to bottom, #000, transparent 85%); }
.login-brand > * { position: relative; z-index: 1; }
.brand-mark { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 16px; }
.logo-tile { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: rgb(255 255 255 / .16); border: 1px solid rgb(255 255 255 / .28); }
.logo-tile svg.icon { width: 20px; height: 20px; }
.login-hero h1 { margin: 0 0 14px; font-size: 34px; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
.login-hero p { margin: 0; max-width: 420px; color: rgb(255 255 255 / .78); font-size: 15px; }
.login-points { display: grid; gap: 12px; margin-top: 32px; }
.login-points div { display: flex; align-items: center; gap: 10px; color: rgb(255 255 255 / .88); }
.login-foot { color: rgb(255 255 255 / .55); font-size: 12px; }
.login-main { display: grid; place-items: center; padding: 40px 24px; background: #fff; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { margin: 0 0 6px; font-size: 24px; font-weight: 650; }
.login-card .sub { margin: 0 0 28px; color: var(--ink-500); }
.login-help { margin-top: 20px; text-align: center; color: var(--ink-500); font-size: 13px; }
@media (max-width: 860px) { .login { grid-template-columns: 1fr; } .login-brand { padding: 28px 24px; min-height: 0; } .login-hero h1 { font-size: 24px; } .login-points, .login-foot { display: none; } }

/* ===== App shell ===== */
.app { display: grid; grid-template-columns: 248px 1fr; height: 100vh; }
.sidebar { display: flex; flex-direction: column; gap: 6px; padding: 16px 12px; background: var(--sidebar); border-right: 1px solid var(--line); min-height: 0; }
.org { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.org-tile { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(145deg, #4a6cf7, #2445c2); color: #fff; font-weight: 650; }
.org-name { font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-sub { font-size: 12px; color: var(--ink-500); }
.sidebar .btn-primary { margin: 0 4px 10px; }
.nav-section { margin: 14px 10px 4px; font-size: 12px; font-weight: 500; color: var(--ink-400); letter-spacing: .02em; }
.nav-item { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 8px; color: var(--ink-700); cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--line-soft); }
.nav-item[aria-current="page"] { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.nav-count { margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--brand-600); color: #fff; font-size: 12px; font-weight: 600; text-align: center; line-height: 20px; }
.nav-count.muted { background: transparent; color: var(--ink-400); font-weight: 500; }
.sidebar-foot { margin-top: auto; }
.user-chip { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: var(--radius); border: 0; background: none; cursor: pointer; text-align: left; }
.user-chip:hover { background: var(--line-soft); }
.user-meta { min-width: 0; flex: 1; }
.user-name { font-weight: 600; font-size: 13px; }
.user-mail { font-size: 12px; color: var(--ink-500); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.topbar { display: none; }

/* ===== Avatars, badges ===== */
.avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-weight: 600; font-size: 13px; }
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 40px; height: 40px; font-size: 15px; }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--line-soft); color: var(--ink-700); }
.badge-brand { background: var(--brand-50); color: var(--brand-700); }
.badge-ok { background: var(--ok-50); color: var(--ok); }
.badge-muted { background: #f3f4f6; color: var(--ink-500); }

/* ===== Mail ===== */
.mail { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; flex: 1; min-height: 0; }
.list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.list-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line-soft); }
.list-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.list-title h1 { margin: 0; font-size: 20px; font-weight: 650; }
.list-title span { color: var(--ink-500); font-size: 13px; }
.search { position: relative; }
.search svg.icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-400); width: 16px; height: 16px; }
.search .input { padding-left: 34px; height: 36px; background: var(--bg); border-color: transparent; }
.search .input:focus { background: #fff; }
.messages { flex: 1; overflow-y: auto; }
.msg { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); cursor: pointer; position: relative; }
.msg:hover { background: #fafbfc; }
.msg[aria-current="true"] { background: var(--brand-50); }
.msg.unread::before { content: ""; position: absolute; left: 6px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--brand-600); }
.msg-top { display: flex; align-items: center; gap: 8px; }
.msg-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-700); }
.msg.unread .msg-from, .msg.unread .msg-subject { color: var(--ink-900); font-weight: 650; }
.msg-date { flex: none; font-size: 12px; color: var(--ink-500); }
.msg-subject { display: flex; align-items: center; gap: 6px; margin-top: 2px; color: var(--ink-500); overflow: hidden; }
.msg-subject span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-subject svg.icon { width: 14px; height: 14px; color: var(--ink-400); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; border-top: 1px solid var(--line-soft); color: var(--ink-500); font-size: 13px; }
.reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.reader-head { padding: 22px 28px 16px; border-bottom: 1px solid var(--line-soft); }
.reader-subject { margin: 0 0 16px; font-size: 21px; font-weight: 650; line-height: 1.35; word-break: break-word; }
.reader-meta { display: flex; align-items: center; gap: 12px; }
.reader-who { min-width: 0; flex: 1; }
.reader-who strong { font-weight: 600; }
.reader-who .addr { color: var(--ink-500); margin-left: 6px; font-size: 13px; }
.reader-who .to { color: var(--ink-500); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-date { color: var(--ink-500); font-size: 13px; white-space: nowrap; }
.reader-actions { display: flex; gap: 4px; }
.notice { display: flex; align-items: center; gap: 10px; margin: 12px 28px 0; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--warn-50); color: var(--warn); font-size: 13px; }
.notice .btn { height: 28px; margin-left: auto; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 28px 0; }
.attachment { display: inline-flex; align-items: center; gap: 8px; max-width: 280px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink-700); background: #fff; }
.attachment:hover { border-color: var(--brand-600); color: var(--brand-700); }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment small { color: var(--ink-400); }
.reader-body { flex: 1; min-height: 0; padding-top: 8px; }
.reader-body iframe { width: 100%; height: 100%; border: 0; display: block; }
.view-banner { display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: #fff7e6; border-bottom: 1px solid #fde4b8; color: #8a5300; font-size: 13px; }
.view-banner .btn { height: 28px; margin-left: auto; }

/* ===== Empty / loading ===== */
.empty { display: grid; place-items: center; align-content: center; gap: 10px; height: 100%; min-height: 240px; padding: 32px; text-align: center; color: var(--ink-500); }
.empty-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--brand-50); color: var(--brand-600); }
.empty-icon svg.icon { width: 26px; height: 26px; }
.empty h3 { margin: 4px 0 0; color: var(--ink-900); font-size: 16px; font-weight: 600; }
.empty p { margin: 0; max-width: 320px; }
.skeleton { height: 64px; margin: 10px 18px; border-radius: 8px; background: linear-gradient(90deg, #f3f4f6 25%, #eceef1 50%, #f3f4f6 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===== Members ===== */
.page { flex: 1; overflow-y: auto; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; font-weight: 650; }
.page-head p { margin: 0; color: var(--ink-500); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: #fff; box-shadow: var(--shadow-sm); }
.stat-label { display: flex; align-items: center; gap: 6px; color: var(--ink-500); font-size: 13px; }
.stat-value { margin: 8px 0 10px; font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--ink-500); }
.stat-link { display: flex; align-items: center; gap: 8px; margin: 8px 0 6px; font-family: var(--mono); font-size: 13px; color: var(--ink-900); }
.bar { height: 6px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--brand-600); }
.bar.warn > i { background: #f59e0b; }
.bar.danger > i { background: var(--danger); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { height: 40px; padding: 0 14px; border: 0; background: none; color: var(--ink-500); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--brand-700); border-bottom-color: var(--brand-600); }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.toolbar .search { width: 280px; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; text-align: left; font-size: 12px; font-weight: 500; color: var(--ink-500); background: #fafbfc; border-bottom: 1px solid var(--line); }
td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person-name { font-weight: 600; }
.person-mail { color: var(--ink-500); font-size: 13px; }
.usage { width: 140px; }
.usage-text { font-size: 12px; color: var(--ink-500); margin-bottom: 5px; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.muted { color: var(--ink-500); }
.audit-action { font-weight: 500; }

/* ===== Menus, modals, toasts ===== */
.menu { position: fixed; z-index: 60; min-width: 180px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--ink-700); text-align: left; }
.menu button:hover { background: var(--line-soft); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line-soft); margin: 6px 0; }
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgb(17 24 39 / .45); animation: fade .15s ease-out; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 40px); overflow-y: auto; border-radius: var(--radius-lg); background: #fff; box-shadow: var(--shadow-lg); animation: rise .18s ease-out; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 24px 6px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.modal-head p { margin: 4px 0 0; color: var(--ink-500); font-size: 13px; }
.modal-body { padding: 16px 24px 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 24px 22px; }
.success-mark { display: grid; place-items: center; width: 52px; height: 52px; margin: 6px auto 14px; border-radius: 50%; background: var(--ok-50); color: var(--ok); }
.success-mark svg.icon { width: 26px; height: 26px; stroke-width: 2.4; }
.success-title { margin: 0 0 4px; text-align: center; font-size: 18px; font-weight: 650; }
.success-sub { margin: 0 0 18px; text-align: center; color: var(--ink-500); }
.cred { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cred-row { display: grid; grid-template-columns: 80px 1fr; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); }
.cred-row:last-child { border-bottom: 0; }
.cred-row dt { color: var(--ink-500); font-size: 13px; }
.cred-row dd { margin: 0; font-family: var(--mono); font-size: 13.5px; word-break: break-all; }
.cred-note { margin: 12px 0 0; font-size: 12px; color: var(--ink-500); }
.toast-stack { position: fixed; left: 50%; bottom: 28px; z-index: 70; display: grid; gap: 8px; transform: translateX(-50%); }
.toast { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius); background: var(--ink-900); color: #fff; box-shadow: var(--shadow); animation: rise .18s ease-out; }
.toast.error { background: var(--danger); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ===== Responsive ===== */
@media (max-width: 1100px) { .stats { grid-template-columns: 1fr 1fr; } .usage { width: 110px; } .col-login { display: none; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fff; }
  .topbar-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 55; width: 280px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open::after { content: ""; position: fixed; inset: 0; z-index: 54; background: rgb(17 24 39 / .4); }
  .mail { grid-template-columns: 1fr; }
  .mail.reading .list-pane { display: none; }
  .mail:not(.reading) .reader { display: none; }
  .reader-head, .attachments { padding-left: 18px; padding-right: 18px; }
  .page { padding: 20px 16px 40px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .stats { grid-template-columns: 1fr; }
  .toolbar .search { width: 100%; }
  .col-usage, .col-role, .col-login { display: none; }
  .back-btn { display: inline-flex !important; }
}
.back-btn { display: none !important; }
