:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-muted: #f8f8f6;
  --ink: #202426;
  --muted: #6d7372;
  --line: #dde1dd;
  --line-strong: #c8cec9;
  --coral: #d95f4c;
  --coral-soft: #f9e9e5;
  --green: #267864;
  --green-soft: #e4f2ed;
  --amber: #a96b10;
  --amber-soft: #f8eedc;
  --red: #b43b3b;
  --red-soft: #fae8e7;
  --sidebar: #252a29;
  --sidebar-text: #eef1ee;
  --sidebar-muted: #aeb6b2;
  --shadow: 0 8px 24px rgba(27, 34, 31, 0.08);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; stroke-width: 1.8; flex: 0 0 auto; }
h1, h2, h3, p { margin-top: 0; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; width: 232px; display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-text); padding: 22px 16px 16px; }
.brand { height: 52px; display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.brand strong { display: block; max-width: 145px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 15px; }
.brand small { display: block; margin-top: 1px; color: var(--sidebar-muted); }
.brand-mark { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 7px; background: var(--coral); color: #fff; }
.brand-mark svg { width: 20px; height: 20px; }
.nav-list { display: grid; gap: 4px; margin-top: 24px; }
.nav-item { min-height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border-radius: 6px; color: var(--sidebar-muted); transition: background .15s, color .15s; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: #3a403e; color: #fff; box-shadow: inset 3px 0 0 var(--coral); }
.sidebar-footer { margin-top: auto; min-height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 8px; color: var(--sidebar-muted); border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; }
.sidebar-footer form { margin-left: auto; }
.sidebar-footer .icon-button { color: var(--sidebar-muted); }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: #58ba8e; box-shadow: 0 0 0 3px rgba(88,186,142,.12); }

.content-shell { grid-column: 2; min-width: 0; }
.topbar { height: 84px; display: flex; align-items: center; gap: 14px; padding: 0 30px; border-bottom: 1px solid var(--line); background: rgba(244,245,242,.95); position: sticky; top: 0; z-index: 20; }
.topbar h1 { margin: 0; font-size: 21px; line-height: 1.25; font-weight: 700; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.topbar-meta { margin-left: auto; color: var(--muted); max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.icon-button.mobile-menu { display: none; }
.main-content { width: min(1460px, 100%); margin: 0 auto; padding: 26px 30px 48px; }

.notice { min-height: 44px; display: flex; align-items: center; gap: 10px; border: 1px solid; border-radius: 6px; padding: 9px 13px; margin-bottom: 18px; }
.notice.success { color: #1f6655; background: var(--green-soft); border-color: #b9dfd0; }
.notice.error { color: #9b3333; background: var(--red-soft); border-color: #edc5c2; }

.icon-button { width: 36px; height: 36px; padding: 0; border: 0; background: transparent; border-radius: 6px; display: inline-grid; place-items: center; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: rgba(60,70,65,.08); color: var(--ink); }
.icon-button.danger:hover { color: var(--red); background: var(--red-soft); }
.button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 6px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.button.primary { background: var(--coral); color: #fff; }
.button.primary:hover { background: #c9513f; }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.button.secondary:hover { background: var(--surface-muted); }
.button.danger-outline { background: var(--surface); color: var(--red); border-color: #e3b6b3; }
.button.danger-outline:hover { background: var(--red-soft); }
.button.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.text-link { display: inline-flex; align-items: center; gap: 5px; color: var(--green); font-weight: 650; }
.text-link svg { width: 15px; height: 15px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { min-height: 92px; display: flex; align-items: center; gap: 14px; padding: 17px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.stat-icon { width: 42px; height: 42px; display: inline-grid; place-items: center; border-radius: 7px; }
.stat-icon.coral { color: var(--coral); background: var(--coral-soft); }
.stat-icon.green { color: var(--green); background: var(--green-soft); }
.stat-icon.amber { color: var(--amber); background: var(--amber-soft); }
.stat-icon.ink { color: #4d5552; background: #ecefed; }
.stat small { display: block; color: var(--muted); margin-bottom: 3px; }
.stat strong { display: block; font-size: 22px; line-height: 1; }

.content-grid { display: grid; gap: 18px; }
.dashboard-grid { grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); align-items: start; }
.detail-grid { grid-template-columns: minmax(320px, .8fr) minmax(420px, 1.2fr); align-items: start; }
.panel, .table-panel, .approval-card { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.panel { padding: 19px; }
.panel-header { min-height: 34px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.panel-header > svg { color: var(--muted); }
.side-stack { display: grid; gap: 18px; }
.section-gap { margin-top: 18px; }

.mail-list { margin: 0 -19px -19px; }
.mail-row { min-height: 64px; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto 120px; align-items: center; gap: 10px; padding: 10px 18px; border-top: 1px solid var(--line); }
.mail-row:hover { background: var(--surface-muted); }
.mail-row time { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.mail-main { min-width: 0; display: block; }
.mail-main strong, .mail-main span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mail-main strong { font-size: 13px; }
.mail-main span { margin-top: 2px; color: var(--muted); }
.direction { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 6px; }
.direction.incoming { color: var(--green); background: var(--green-soft); }
.direction.outgoing, .direction.system { color: var(--coral); background: var(--coral-soft); }
.role-badge, .status-label, .status-pill, .direction-label { min-height: 24px; padding: 2px 8px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; border-radius: 999px; font-size: 11px; white-space: nowrap; border: 1px solid transparent; }
.status-label { align-self: flex-start; }
.role-badge.primary_owner { color: #a63d2f; background: var(--coral-soft); border-color: #f0c9c1; }
.role-badge.owner { color: #87530b; background: var(--amber-soft); border-color: #ecd4ab; }
.role-badge.friend { color: #1f6d59; background: var(--green-soft); border-color: #bee0d3; }
.role-badge.stranger { color: #5b6260; background: #eef0ee; border-color: #d9ddda; }
.role-badge.blocked { color: #9c3636; background: var(--red-soft); border-color: #ebc1be; }
.role-badge.system { color: #5b6260; background: #eef0ee; }
.status-pill { color: var(--green); background: var(--green-soft); }
.status-pill span { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.status-list { margin: 0; }
.status-list div { min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-top: 1px solid var(--line); }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; font-weight: 600; text-align: right; }
.creator-panel > p { color: #3f4643; line-height: 1.75; }
.creator-panel blockquote { margin: 14px 0; padding: 10px 12px; border-left: 3px solid var(--coral); background: var(--surface-muted); color: var(--muted); }

.toolbar-band { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 3px; background: #e9ece9; border-radius: 7px; overflow-x: auto; }
.tabs a { min-height: 34px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; color: var(--muted); white-space: nowrap; }
.tabs a.active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 3px rgba(20,30,25,.1); }
.result-count { color: var(--muted); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { min-height: 56px; padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { height: 44px; color: var(--muted); background: var(--surface-muted); font-size: 12px; font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfa; }
.person-cell { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.person-cell > span { width: 34px; height: 34px; display: inline-grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--green); background: var(--green-soft); font-weight: 700; }
.person-cell strong, .person-cell small { display: block; }
.person-cell small { color: var(--muted); max-width: 260px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.detail-heading { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.back-link:hover { color: var(--ink); }
.inline-form { display: flex; align-items: center; gap: 8px; }
.role-form { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 18px; }
.primary-owner-action { margin-top: 10px; }
.memory-list { display: grid; gap: 8px; }
.memory-item { min-height: 52px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-muted); }
.memory-item p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.memory-kind { min-width: 42px; padding: 2px 7px; border-radius: 4px; text-align: center; font-size: 11px; color: var(--green); background: var(--green-soft); }
.memory-item .locked { width: 15px; height: 15px; color: var(--amber); }

.filter-form select { min-width: 220px; }
.mail-list.expanded { margin-top: -1px; }
.mail-list.expanded .mail-row { grid-template-columns: 36px minmax(0, 1fr) auto 130px; }
.direction-label { color: var(--muted); background: #e9ece9; }
.message-paper { max-width: 900px; margin: 0 auto; padding: 28px 34px 42px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
.message-paper header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.message-paper h2 { margin: 26px 0 22px; font-size: 20px; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.85; color: #2e3431; }
.attachment-list { display: grid; gap: 8px; }
.attachment-item { min-height: 54px; display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; }
.attachment-item > div { min-width: 0; flex: 1; }
.attachment-item strong, .attachment-item small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.attachment-item small { color: var(--muted); }
.status-label.processed, .status-label.approved { color: var(--green); background: var(--green-soft); }
.status-label.quarantined, .status-label.pending { color: var(--amber); background: var(--amber-soft); }
.status-label.rejected, .status-label.failed { color: var(--red); background: var(--red-soft); }

.approval-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.approval-card { padding: 19px; }
.approval-card > header { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.approval-card h2 { margin: 8px 0 0; font-size: 16px; }
.approval-card header p { margin: 2px 0 0; color: var(--muted); }
.approval-token { display: inline-block; font-family: Consolas, monospace; color: var(--coral); background: var(--coral-soft); padding: 2px 7px; border-radius: 4px; }

.section-form { display: grid; gap: 15px; }
.section-form.compact { gap: 12px; }
.form-section { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.form-section > h2 { font-size: 16px; margin-bottom: 18px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #3f4643; font-weight: 600; }
input, textarea, select { width: 100%; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); padding: 8px 10px; outline: none; }
textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(38,120,100,.12); }
input[readonly], textarea[readonly] { background: var(--surface-muted); color: var(--muted); }
.check-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.check-label input { width: 17px; height: 17px; min-height: 0; accent-color: var(--green); }
.toggle-row { display: flex; flex-wrap: wrap; gap: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 2px; }
.form-actions.split { justify-content: space-between; }
.section-form hr { width: 100%; height: 1px; margin: 7px 0; border: 0; background: var(--line); }
.section-title { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.section-title h2 { margin: 0; font-size: 17px; }
.section-title p { margin: 2px 0 0; color: var(--muted); }
.persona-form { max-width: 980px; margin: 0 auto; }
.sticky-actions { position: sticky; bottom: 16px; display: flex; justify-content: flex-end; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.96); box-shadow: var(--shadow); }

.settings-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .75fr); gap: 18px; align-items: start; }
.settings-layout > .panel { padding: 21px; }

.pairing-code { min-height: 82px; display: grid; place-items: center; border: 1px dashed var(--coral); border-radius: 7px; background: var(--coral-soft); color: #9f3f31; font: 700 30px/1 Consolas, monospace; letter-spacing: 0; }
.muted-line { margin: 10px 0 0; color: var(--muted); text-align: center; }
.table-heading { padding: 18px 18px 0; }
.handset-text { max-width: 420px; white-space: normal; overflow-wrap: anywhere; }
.command-result { max-width: 260px; margin-top: 5px; color: var(--muted); font-size: 12px; white-space: normal; overflow-wrap: anywhere; }

.timeline { max-width: 860px; margin: 0 auto; }
.journal-entry { position: relative; margin-left: 22px; padding: 0 0 28px 28px; border-left: 1px solid var(--line-strong); }
.journal-entry:last-child { border-left-color: transparent; }
.timeline-mark { position: absolute; top: 1px; left: -7px; width: 13px; height: 13px; padding: 3px; border-radius: 50%; background: var(--bg); border: 1px solid var(--green); }
.timeline-mark span { display: block; width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.journal-entry header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.journal-entry time { font-weight: 700; }
.journal-entry > p { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); white-space: pre-wrap; line-height: 1.8; }
.mood { display: inline-flex; align-items: center; gap: 5px; color: var(--amber); }

.empty-state { min-height: 120px; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--muted); }
.empty-state.large { min-height: 260px; }
.empty-state svg { width: 28px; height: 28px; }
.empty-state p { margin: 0; }

.modal { width: min(480px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 20px 60px rgba(20,25,23,.22); }
.modal::backdrop { background: rgba(25,30,28,.45); }
.modal form { padding: 20px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.stack-form { display: grid; gap: 14px; }

.auth-page, .setup-page { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; background: #edf0ed; }
.auth-panel { width: min(420px, 100%); padding: 32px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-panel h1 { margin-bottom: 22px; font-size: 22px; }
.auth-panel .button { width: 100%; margin-top: 4px; }
.auth-foot { margin: 20px 0 0; color: var(--muted); text-align: center; font-size: 12px; }
.auth-link { display: block; margin-top: 16px; color: var(--green); text-align: center; font-weight: 650; }
.full-button { width: 100%; }
.otp-input { text-align: center; font-family: Consolas, monospace; font-size: 24px; letter-spacing: 6px; }
.setup-panel { width: min(860px, 100%); }
.setup-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 18px; }
.setup-heading h1 { margin: 0; font-size: 23px; }
.setup-heading p { margin: 2px 0 0; color: var(--muted); }
.setup-panel > .section-form { gap: 14px; }
.locked-state { min-height: 320px; display: grid; place-items: center; align-content: center; gap: 8px; padding: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); text-align: center; }
.locked-state svg { width: 34px; height: 34px; color: var(--coral); }
.locked-state h2, .locked-state p { margin: 0; }
.locked-state p { color: var(--muted); }

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .settings-layout { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-layout .side-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-layout .side-stack > :last-child { grid-column: 1 / -1; }
  .approval-list { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 12px 0 30px rgba(15,20,18,.18); }
  .sidebar.open { transform: translateX(0); }
  .content-shell { min-width: 0; }
  .topbar { height: 72px; padding: 0 16px; }
  .topbar h1 { font-size: 18px; }
  .topbar p { max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .topbar-meta { display: none; }
  .icon-button.mobile-menu { display: inline-grid; }
  .main-content { padding: 18px 14px 40px; }
  .detail-grid { grid-template-columns: 1fr; }
  .side-stack, .settings-layout .side-stack { grid-template-columns: 1fr; }
  .settings-layout .side-stack > :last-child { grid-column: auto; }
  .mail-row, .mail-list.expanded .mail-row { grid-template-columns: 34px minmax(0, 1fr) auto; }
  .mail-row .role-badge { display: none; }
  .mail-row time { grid-column: 2; text-align: left; }
  .message-paper { padding: 20px 17px 30px; }
  .message-paper header { align-items: flex-start; }
  .form-grid.two { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .toolbar-band { align-items: flex-start; }
  .tabs { max-width: 100%; }
}

@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .stat { min-height: 82px; padding: 12px; gap: 9px; }
  .stat-icon { width: 36px; height: 36px; }
  .stat strong { font-size: 18px; }
  .panel, .approval-card, .form-section { padding: 15px; }
  .mail-list { margin: 0 -15px -15px; }
  .mail-row { padding-inline: 14px; }
  .toolbar-band { flex-wrap: wrap; }
  .toolbar-band > .button { width: 100%; }
  .tabs { width: 100%; }
  .tabs a { flex: 1; }
  .approval-card > header { flex-direction: column; }
  .form-actions.split { gap: 8px; }
  .form-actions.split .button { flex: 1; padding-inline: 8px; white-space: normal; }
  .auth-panel { padding: 24px 19px; }
  .setup-page { padding: 18px 10px; }
  .setup-heading { padding: 0 5px; }
}
