:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f5;
  --sidebar: #f1f3f6;
  --text: #17191d;
  --text-2: #626874;
  --text-3: #969ca7;
  --line: rgba(20, 27, 37, 0.10);
  --line-strong: rgba(20, 27, 37, 0.17);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.11);
  --green: #218a47;
  --green-soft: #e8f7ed;
  --orange: #b96a05;
  --orange-soft: #fff3de;
  --red: #d83b34;
  --red-soft: #fff0ef;
  --shadow: 0 12px 36px rgba(28, 38, 54, 0.10), 0 1px 2px rgba(28, 38, 54, 0.06);
  --font: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #171819;
  --surface: #222324;
  --surface-2: #282a2c;
  --surface-3: #303236;
  --sidebar: #1d1e20;
  --text: #f4f4f5;
  --text-2: #a7a9ae;
  --text-3: #73767d;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #4da3ff;
  --accent-soft: rgba(77, 163, 255, 0.14);
  --green: #56c77a;
  --green-soft: rgba(58, 190, 104, 0.13);
  --orange: #ffad3d;
  --orange-soft: rgba(255, 161, 34, 0.13);
  --red: #ff756d;
  --red-soft: rgba(255, 79, 70, 0.13);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; height: 100%; background: var(--bg); }
body { color: var(--text); font: 13px/1.45 var(--font); overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }

.app-shell {
  display: grid;
  grid-template: 64px minmax(0, 1fr) / 224px minmax(500px, 1fr) 330px;
  height: 100vh;
  background: var(--bg);
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 224px minmax(260px, 560px) 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px);
  z-index: 5;
}

.brand, .login-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none; width: 31px; height: 31px; border-radius: 8px;
  background: linear-gradient(145deg, #adf36c, #70c83c); color: #14240d; font: 800 18px/1 var(--mono);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 3px 8px rgba(91, 167, 49, .24);
}
.brand strong, .login-brand strong { display: block; font-size: 14px; letter-spacing: .02em; }
.brand small, .login-brand small { display: block; color: var(--text-3); font-size: 9px; letter-spacing: .16em; text-transform: uppercase; }

.search-box {
  display: flex; align-items: center; gap: 9px; min-width: 0; height: 36px; padding: 0 10px 0 12px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--text-3);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search-box:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; }
.search-box input::placeholder { color: var(--text-3); }
.search-box kbd { padding: 2px 5px; border: 1px solid var(--line); border-radius: 5px; color: var(--text-3); background: var(--surface); font: 10px var(--mono); }

.top-actions, .toolbar-actions, .modal-foot > div, .mail-send-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.button, .icon-button, .more-button {
  display: inline-flex; align-items: center; justify-content: center; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text-2);
  text-decoration: none; white-space: nowrap; box-shadow: 0 1px 2px rgba(0,0,0,.035);
  transition: transform .12s, border-color .12s, color .12s, background .12s;
}
.button:hover, .icon-button:hover, .more-button:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-2); }
.button:active, .icon-button:active, .more-button:active { transform: scale(.97); }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; font-weight: 650; }
.button.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, var(--line)); }
.button.wide { width: 100%; height: 42px; }
.button:disabled, .icon-button:disabled { opacity: .45; cursor: wait; }
.icon-button { width: 34px; padding: 0; font-size: 17px; }

.sidebar {
  display: flex; flex-direction: column; min-height: 0; padding: 14px 10px;
  border-right: 1px solid var(--line); background: var(--sidebar); overflow: auto;
}
.nav-stack, .category-list { display: grid; gap: 3px; }
.nav-item, .category-item {
  display: grid; grid-template-columns: 23px minmax(0, 1fr) auto; align-items: center; gap: 7px;
  width: 100%; min-height: 37px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-2); text-align: left;
}
.category-item { grid-template-columns: 23px minmax(0, 1fr) auto 22px; }
.nav-item:hover, .category-item:hover { background: color-mix(in srgb, var(--text) 5%, transparent); color: var(--text); }
.nav-item.active, .category-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-item b, .category-item b { color: var(--text-3); font-size: 11px; font-weight: 500; }
.nav-icon { text-align: center; font-size: 16px; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; margin: 22px 9px 8px; color: var(--text-3); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; }
.sidebar-heading button { width: 25px; height: 25px; border: 0; border-radius: 6px; background: transparent; color: var(--text-2); font-size: 18px; }
.sidebar-heading button:hover { background: var(--surface-3); color: var(--text); }
.category-item { position: relative; }
.category-item[data-drop="true"] { background: var(--accent); color: white; transform: translateX(3px); }
.category-item[data-drop="true"] b { color: rgba(255,255,255,.75); }
.category-dot { width: 9px; height: 9px; margin-left: 3px; border-radius: 50%; background: var(--category-color); box-shadow: 0 0 0 3px color-mix(in srgb, var(--category-color) 14%, transparent); }
.category-more { display: none; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: currentColor; }
.category-item:hover .category-more { display: block; }
.category-item.dragging { opacity: .4; }
.category-item[data-sort="before"] { box-shadow: inset 0 2px var(--accent); }
.category-item[data-sort="after"] { box-shadow: inset 0 -2px var(--accent); }
.sidebar-summary { display: grid; gap: 8px; margin-top: auto; padding: 15px 10px 4px; border-top: 1px solid var(--line); }
.sidebar-summary div { display: flex; justify-content: space-between; color: var(--text-3); font-size: 11px; }
.sidebar-summary b { color: var(--text-2); font: 600 11px var(--mono); }

.content { min-width: 0; min-height: 0; padding: 18px; overflow: auto; }
.content-toolbar { position: sticky; top: -18px; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 70px; margin: -18px -18px 12px; padding: 17px 18px 12px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(16px); }
.content-toolbar h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.content-toolbar p { margin: 3px 0 0; color: var(--text-3); font-size: 11px; }
.toolbar-actions { position: relative; flex-wrap: wrap; }
.toolbar-actions select { height: 34px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: var(--surface); color: var(--text-2); }
.tools-menu { position: absolute; top: 41px; right: 0; z-index: 10; width: 180px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.tools-menu button { width: 100%; padding: 9px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); text-align: left; }
.tools-menu button:hover { background: var(--surface-3); color: var(--text); }
.drop-hint { margin: 0 0 10px; padding: 9px 12px; border: 1px dashed var(--accent); border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }

.account-list { display: grid; gap: 8px; }
.account-row {
  position: relative; display: grid; grid-template-columns: 42px minmax(230px, 1.2fr) minmax(230px, .9fr) auto;
  align-items: center; gap: 12px; min-height: 70px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
  transition: border-color .13s, background .13s, transform .13s, box-shadow .13s;
}
.account-row:hover { border-color: var(--line-strong); box-shadow: 0 3px 14px rgba(25, 34, 48, .06); transform: translateY(-1px); }
.account-row.selected { border-color: color-mix(in srgb, var(--accent) 46%, var(--line)); background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface)); box-shadow: inset 3px 0 var(--accent); }
.account-row.todo { border-color: color-mix(in srgb, var(--orange) 34%, var(--line)); background: color-mix(in srgb, var(--orange-soft) 45%, var(--surface)); box-shadow: inset 3px 0 var(--orange); }
.account-row.todo.selected { background: color-mix(in srgb, var(--orange-soft) 42%, var(--accent-soft)); box-shadow: inset 3px 0 var(--orange), 0 3px 14px rgba(25, 34, 48, .06); }
.account-row.dragging { opacity: .45; }
.account-avatar {
  display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 11px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--plan-color) 65%, white), var(--plan-color)); color: white;
  font: 750 10px var(--mono); text-shadow: 0 1px 2px rgba(0,0,0,.35); box-shadow: inset 0 1px rgba(255,255,255,.45), 0 2px 7px color-mix(in srgb, var(--plan-color) 28%, transparent);
}
.account-main { min-width: 0; }
.account-email { overflow: hidden; margin-bottom: 5px; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.account-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; color: var(--text-3); font-size: 11px; }
.tag { display: inline-flex; align-items: center; gap: 4px; min-height: 21px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: 10.5px; }
.tag.ok { background: var(--green-soft); color: var(--green); }
.tag.warn { background: var(--orange-soft); color: var(--orange); }
.tag.bad { background: var(--red-soft); color: var(--red); }
.tag.todo-tag { max-width: 250px; overflow: hidden; background: var(--orange-soft); color: var(--orange); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.credential-strip { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.credential-button { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 8px; border: 0; border-radius: 7px; background: var(--surface-3); color: var(--text-2); font-size: 11px; }
.credential-button:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }
.credential-button:disabled { opacity: .52; cursor: default; }
.credential-button b { color: var(--accent); font: 700 12px var(--mono); letter-spacing: .04em; }
.countdown { min-width: 27px; padding: 2px 5px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font: 700 10px var(--mono); text-align: center; }
.countdown.expiring { background: var(--red-soft); color: var(--red); }
.row-actions { display: flex; align-items: center; gap: 6px; }
.row-action { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--text-3); }
.row-action:hover { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.row-action.starred { color: #e6a300; }
.empty-state { display: grid; place-items: center; gap: 7px; min-height: 240px; padding: 30px; color: var(--text-3); text-align: center; }
.empty-state strong { color: var(--text); font-size: 15px; }

.detail-panel { min-width: 0; min-height: 0; border-left: 1px solid var(--line); background: var(--surface); overflow: auto; }
.detail-empty { display: grid; place-items: center; align-content: center; gap: 8px; height: 100%; padding: 30px; color: var(--text-3); text-align: center; }
.detail-empty > span { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: var(--surface-3); font-size: 26px; }
.detail-empty strong { color: var(--text); }
.detail-empty p { max-width: 220px; margin: 0; font-size: 12px; }
.detail-head { padding: 24px 20px 17px; border-bottom: 1px solid var(--line); }
.detail-avatar { display: grid; place-items: center; width: 50px; height: 50px; margin-bottom: 14px; border-radius: 15px; color: white; font: 800 12px var(--mono); background: linear-gradient(145deg, color-mix(in srgb, var(--plan-color) 65%, white), var(--plan-color)); box-shadow: inset 0 1px rgba(255,255,255,.5), 0 6px 16px color-mix(in srgb, var(--plan-color) 25%, transparent); }
.detail-head h2 { margin: 0; overflow-wrap: anywhere; font-size: 17px; line-height: 1.3; }
.detail-head p { margin: 5px 0 0; color: var(--text-3); font-size: 11px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 16px; }
.detail-actions .button { width: 100%; }
.detail-section { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 10px; color: var(--text-3); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.detail-todo { background: var(--orange-soft); color: var(--orange); }
.detail-todo h3 { color: var(--orange); }.detail-todo strong { color: var(--text); font-size: 12px; line-height: 1.5; }
.detail-grid { display: grid; gap: 9px; }
.detail-field { display: grid; grid-template-columns: 82px minmax(0, 1fr) auto; align-items: start; gap: 8px; min-height: 25px; }
.detail-field > span { color: var(--text-3); font-size: 11px; }
.detail-field > b, .detail-field > p { min-width: 0; margin: 0; color: var(--text-2); font-size: 11.5px; font-weight: 500; overflow-wrap: anywhere; }
.copy-mini { padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 11px; }
.detail-totp { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
.detail-totp button { border: 0; background: transparent; color: var(--accent); font: 800 20px var(--mono); letter-spacing: .09em; }

.login-layer, .modal-layer { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(17, 20, 25, .38); backdrop-filter: blur(12px); }
.login-layer { background: radial-gradient(circle at 50% 15%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 40%), var(--bg); }
.login-card { width: min(390px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.login-brand { margin-bottom: 32px; }
.login-card h2 { margin: 0 0 7px; font-size: 25px; }
.login-card > p { margin: 0 0 24px; color: var(--text-2); }
.field-label { display: block; margin-bottom: 7px; color: var(--text-2); font-size: 11px; }
.field, .field-area { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: var(--surface-2); color: var(--text); }
.field { min-height: 38px; }
.field:focus, .field-area:focus { border-color: color-mix(in srgb, var(--accent) 65%, var(--line)); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .field { margin-bottom: 12px; }
.error { min-height: 20px; margin-top: 8px; color: var(--red); font-size: 12px; }
.modal { width: min(860px, 100%); max-height: 92vh; overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.compact-modal { width: min(720px, 100%); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 19px 22px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); }
.modal-head small { color: var(--text-3); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.modal-head h3 { margin: 3px 0 0; font-size: 20px; }
.close { display: grid; place-items: center; width: 31px; height: 31px; padding: 0; border: 0; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 20px 22px; }
.form-grid label > span, .mail-send-grid label > span { display: block; margin-bottom: 6px; color: var(--text-2); font-size: 11px; }
.form-grid .full, .mail-send-grid .full { grid-column: 1 / -1; }
.web-todo-editor { display: grid; gap: 9px; padding: 11px; border: 1px solid color-mix(in srgb, var(--orange) 32%, var(--line)); border-radius: 9px; background: var(--orange-soft); }
.web-todo-editor label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }.web-todo-editor label input { margin-top: 2px; accent-color: var(--orange); }.web-todo-editor label span, .web-todo-editor label b, .web-todo-editor label small { display: block; }.web-todo-editor label small { margin-top: 2px; color: var(--text-3); font-size: 10px; }
.color-field { padding: 4px; }
.modal-foot { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 22px; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); }
.helper { color: var(--text-3); font-size: 11px; line-height: 1.6; }
.helper code { color: var(--accent); font-family: var(--mono); }

.mail-grid { display: grid; grid-template-columns: minmax(220px, .72fr) minmax(320px, 1.28fr); min-height: 390px; border-bottom: 1px solid var(--line); }
.mail-list { border-right: 1px solid var(--line); overflow: auto; }
.mail-item { display: block; width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.mail-item:hover, .mail-item.active { background: var(--accent-soft); }
.mail-item strong, .mail-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item small { margin-top: 4px; color: var(--text-3); }
.mail-body { padding: 20px; overflow: auto; }
.mail-body h4 { margin: 0 0 7px; font-size: 18px; }
.mail-body pre { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-2); font: 12px/1.65 var(--mono); }
.mail-send { padding: 18px 22px 20px; }
.mail-send h4 { margin: 0 0 12px; }
.mail-send-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mail-send-foot { margin-top: 12px; }
.monitor-results { max-height: 65vh; overflow: auto; padding: 0 22px 22px; }
.monitor-table { width: 100%; border-collapse: collapse; }
.monitor-table th, .monitor-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 11px; }
.monitor-table th { color: var(--text-3); }
.monitor-table .ok { color: var(--green); }.monitor-table .warn { color: var(--orange); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 40; max-width: min(410px, calc(100% - 44px)); padding: 11px 14px; border: 1px solid color-mix(in srgb, var(--green) 35%, var(--line)); border-radius: 9px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: none; }.toast.error { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); color: var(--red); }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 210px minmax(480px, 1fr); }
  .detail-panel { display: none; }
  .topbar { grid-template-columns: 210px minmax(260px, 1fr) auto; }
  .account-row { grid-template-columns: 42px minmax(220px, 1fr) minmax(210px, .9fr) auto; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell { grid-template: auto auto minmax(0, 1fr) / 1fr; min-height: 100vh; height: auto; }
  .topbar { position: sticky; top: 0; grid-column: 1; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 12px; }
  .search-box { grid-column: 1 / -1; grid-row: 2; }
  .sync-link { display: none; }
  .sidebar { grid-row: 2; flex-direction: row; gap: 8px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .nav-stack, .category-list { display: flex; flex: none; }
  .nav-item, .category-item { width: auto; min-width: max-content; }
  .sidebar-heading, .sidebar-summary { display: none; }
  .content { grid-row: 3; padding: 12px; }
  .content-toolbar { position: static; display: block; margin: -12px -12px 10px; padding: 13px 12px; }
  .toolbar-actions { justify-content: flex-start; margin-top: 10px; }
  .account-row { grid-template-columns: 38px minmax(0, 1fr) auto; }
  .credential-strip { grid-column: 2 / -1; }
  .modal-layer { padding: 8px; }
  .form-grid, .mail-grid, .mail-send-grid { grid-template-columns: 1fr; }
  .form-grid .full, .mail-send-grid .full { grid-column: auto; }
  .mail-list { max-height: 220px; border-right: 0; border-bottom: 1px solid var(--line); }
}
