:root {
  --brand: #c8102e;
  --brand-dark: #9c0b22;
  --brand-soft: #fbecee;
  --on-brand: #fff;
  --ink: #202124;
  --ink-soft: #3c4043;
  --muted: #74716c;
  --bg: #f6f3ee;
  --card: #ffffff;
  --line: #e8e2d9;
  --line-strong: #d7cfc3;
  --gold: #b5895a;
  --green: #2f7d5b;
  --green-soft: #e9f5ef;
  --amber: #a86b12;
  --amber-soft: #fdf3e2;
  --red-soft: #fdecec;
  --shadow: 0 12px 36px rgba(37, 30, 22, .07);
  --radius: 14px;
  --sidebar: 246px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.25; letter-spacing: -.02em; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 16px; line-height: 1.4; }
.muted { color: var(--muted); }
.eyebrow { font-size: 10px; letter-spacing: .2em; color: var(--brand); font-weight: 700; text-transform: uppercase; }
.sub { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }

/* ---------- Shell ---------- */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 30;
  background: #1e1d1b; color: #e9e2d8;
  display: flex; flex-direction: column; padding: 26px 18px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 22px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-mark { width: 44px; height: 32px; border-radius: 4px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-size: 14px; font-weight: 800; letter-spacing: .04em; flex: none; }
.brand-logo { width: 48px; height: 29px; object-fit: cover; border-radius: 3px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; letter-spacing: .02em; color: #fff; }
.brand-text small { color: #a9a094; font-size: 11px; margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 22px 0; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 9px;
  color: #c8c0b5; font-size: 14px; transition: .15s ease;
}
.nav-item svg { width: 17px; height: 17px; opacity: .8; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--brand); color: var(--on-brand); box-shadow: 0 8px 18px rgba(200,16,46,.25); }
.nav-item.active svg { opacity: 1; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 14px 6px 0; border-top: 1px solid rgba(255,255,255,.09); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-meta strong { font-size: 13px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { font-size: 11px; color: #9f9689; }
.user-chip .icon-btn { color: #b2a99c; font-size: 11px; padding: 4px; }
.user-chip .icon-btn:hover { color: #fff; background: transparent; }

.app-main { margin-left: var(--sidebar); min-height: 100vh; }
.topbar {
  height: 64px; display: flex; align-items: center; gap: 14px; padding: 0 30px;
  background: rgba(246,243,238,.86); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 14px; color: var(--ink-soft); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { padding: 30px 30px 60px; max-width: 1600px; margin: 0 auto; }
.menu-btn { display: none !important; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; transition: .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: var(--on-brand); box-shadow: 0 8px 18px rgba(200,16,46,.18); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.04); color: var(--ink); }
.btn-small { height: 32px; padding: 0 12px; font-size: 12px; border-radius: 7px; }
.btn-lg { height: 46px; font-size: 14px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 7px;
  border: 0; background: transparent; border-radius: 7px; color: var(--muted); font-size: 14px;
}
.icon-btn:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--brand); }
.text-btn { border: 0; background: transparent; color: var(--brand); font-size: 12px; padding: 0; }
.text-link { color: var(--brand); font-size: 13px; font-weight: 600; }
.text-link:hover { text-decoration: underline; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
  padding: 9px 11px; outline: none; transition: .15s ease; min-height: 38px;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(200,16,46,.08); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.field > span { font-weight: 600; }
.field em { color: var(--brand); font-style: normal; }
.field input, .field select, .field textarea { font-size: 13px; }
.form-stack { display: flex; flex-direction: column; gap: 15px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.compact select, .compact input { min-height: 34px; padding: 6px 9px; }

/* ---------- Cards / tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 0 rgba(37,30,22,.02); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 24px 0; }
.card-head h2 { margin-top: 4px; }
.card-head p { margin-top: 4px; font-size: 12px; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 13px 16px; font-size: 11px; letter-spacing: .06em; color: var(--muted);
  border-bottom: 1px solid var(--line); background: #fbfaf8; white-space: nowrap; font-weight: 600;
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid #f0ece5; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fcfaf7; }
.data-table .num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clickable { cursor: pointer; }
.inline-form { display: inline; }
.status { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-active { color: var(--green); background: var(--green-soft); }
.status-done { color: var(--muted); background: #f0eeea; }
.status-warn { color: var(--amber); background: var(--amber-soft); }

/* ---------- Page head / dashboard ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-head.compact { align-items: center; margin-bottom: 20px; }
.page-head h1 { margin-top: 5px; font-size: 28px; }
.page-head .muted { font-size: 13px; margin-top: 5px; }
.head-note { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font-size: 11px; color: var(--muted); }
.head-note strong { color: var(--ink-soft); font-size: 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 19px 20px; display: flex; flex-direction: column; gap: 5px; }
.stat-card.accent { background: linear-gradient(135deg, #262321, #3a332d); border-color: #3a332d; color: #fff; }
.stat-card.accent .stat-label, .stat-card.accent .stat-foot { color: #c8bfb3; }
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.stat-value { font-size: 27px; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 14px; font-weight: 500; margin-right: 3px; color: var(--muted); }
.stat-card.accent .stat-value small { color: #c8bfb3; }
.stat-foot { font-size: 11px; color: var(--muted); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .8fr); gap: 18px; }
.dashboard-side { display: flex; flex-direction: column; gap: 18px; }
.quick-card { padding-bottom: 12px; }
.quick-card h2 { padding: 4px 22px 10px; }
.quick-item { display: flex; gap: 13px; align-items: center; padding: 13px 22px; border-top: 1px solid #f0ece5; transition: .15s; }
.quick-item:hover { background: #fcfaf7; }
.quick-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.quick-item strong { display: block; font-size: 13px; }
.quick-item small { color: var(--muted); font-size: 11px; }
.tip-card { padding: 22px; }
.tip-card h3 { margin: 6px 0 7px; }
.tip-card p { font-size: 12px; color: var(--muted); }
.tip-card code { display: inline-block; margin-top: 12px; padding: 6px 10px; border-radius: 6px; background: #f4eee7; color: var(--brand); font-family: Consolas, monospace; font-size: 12px; }
.empty-state { padding: 60px 24px; text-align: center; }
.empty-state h3 { margin: 12px 0 5px; }
.empty-state p { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.empty-icon { width: 46px; height: 46px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto; font-size: 22px; }
.error-state { max-width: 560px; margin: 40px auto; }
.error-code { font-size: 54px; font-weight: 800; color: var(--brand); letter-spacing: -.05em; }

/* ---------- Project cards ---------- */
.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar select { width: auto; min-width: 130px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted); }
.search-box input { padding-left: 34px; }
.search-box.small { flex: none; width: 210px; min-width: 0; }
.search-box.small input { min-height: 32px; font-size: 12px; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.project-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 19px 20px 15px; transition: .18s ease; display: flex; flex-direction: column; }
.project-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.project-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 13px; }
.project-code { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.project-card h3 { font-size: 18px; margin-bottom: 4px; }
.project-client { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 15px 0 13px; margin-top: 10px; border-top: 1px solid #f0ece5; }
.project-metrics span { display: block; font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.project-metrics strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.project-card-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; padding-top: 10px; border-top: 1px solid #f0ece5; }

/* ---------- Forms layout ---------- */
.form-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .7fr); gap: 18px; align-items: start; }
.form-card { padding-bottom: 24px; }
.form-card .form-grid { padding: 20px 24px 0; }
.form-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 84px; }
.step-list { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; gap: 5px; }

/* ---------- Auth ---------- */
.auth-shell { background: #f2eee8; }
.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.05fr) minmax(420px, .95fr); }
.auth-brand { background: #211f1c; color: #fff; position: relative; display: flex; flex-direction: column; padding: 56px 64px 34px; overflow: hidden; }
.auth-brand::after { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; border: 1px solid rgba(255,255,255,.08); right: -190px; bottom: -220px; }
.auth-brand::before { content: ""; position: absolute; width: 300px; height: 300px; border-radius: 50%; background: radial-gradient(circle, rgba(200,16,46,.35), transparent 65%); left: -100px; top: 20%; }
.auth-brand-inner { position: relative; z-index: 1; max-width: 500px; margin: auto 0; }
.auth-logo { width: 94px; height: 56px; object-fit: cover; border-radius: 3px; margin-bottom: 36px; }
.auth-mark { width: 88px; height: 64px; border-radius: 6px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-size: 26px; font-weight: 800; letter-spacing: .06em; margin-bottom: 34px; }
.auth-brand .eyebrow { color: #e8a4ae; }
.auth-brand h1 { font-size: 46px; line-height: 1.22; margin: 12px 0 18px; letter-spacing: -.03em; }
.auth-desc { color: #bdb4a8; font-size: 14px; max-width: 360px; line-height: 1.8; }
.auth-points { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.auth-points span { border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: 5px 11px; font-size: 11px; color: #d8d0c5; }
.auth-brand-foot { position: relative; z-index: 1; color: #7f776c; font-size: 10px; letter-spacing: .16em; }
.auth-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-form-card { width: 100%; max-width: 390px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 36px; box-shadow: var(--shadow); }
.auth-form-card h2 { margin: 5px 0 4px; font-size: 26px; }
.auth-form-card > .muted { font-size: 12px; margin-bottom: 22px; }
.auth-hint { margin-top: 20px; font-size: 12px; color: var(--muted); text-align: center; }
.auth-hint a { color: var(--brand); font-weight: 600; }
.auth-error { max-width: 480px; margin: 20vh auto; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 40px; text-align: center; }

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 20px; align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 84px; }
.settings-nav a { padding: 9px 13px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.settings-nav a:hover, .settings-nav a.active { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.settings-content { display: flex; flex-direction: column; gap: 18px; }
.settings-content .card { padding-bottom: 22px; }
.settings-content .form-grid { padding: 20px 24px 0; }
.user-create { padding-top: 18px !important; border-top: 1px solid var(--line); margin-top: 12px; }
.notice { margin: 16px 24px 0; padding: 12px 14px; background: #fbf7f0; border: 1px solid #eee3d3; border-radius: 9px; color: #6e6253; font-size: 12px; line-height: 1.8; }

/* ---------- Templates / catalog ---------- */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.template-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.template-top { display: flex; justify-content: space-between; align-items: center; }
.template-card h3 { font-size: 18px; }
.template-card p { font-size: 12px; min-height: 20px; }
.template-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; margin-top: auto; border-top: 1px solid #f0ece5; color: var(--muted); font-size: 11px; }
.catalog-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.category-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 12px; font-size: 12px; color: var(--ink-soft); }
.category-pill strong { font-weight: 600; }
.category-pill span { color: var(--muted); font-size: 11px; }
.category-pill:hover, .category-pill.active { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.catalog-head { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.catalog-head .filter-bar { margin: 0; flex: 1; }
.catalog-table-wrap { max-height: 620px; }
.catalog-table td { padding-top: 11px; padding-bottom: 11px; }
.catalog-table .item-desc { display: block; color: var(--muted); font-size: 11px; max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(24, 21, 18, .48); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal.show { display: flex; }
.modal-dialog { width: min(520px, 100%); max-height: 90vh; background: #fff; border-radius: 15px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.modal-dialog.modal-lg { width: min(980px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 22px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin-top: 3px; }
.modal-body { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 13px; }
.modal-foot { padding: 13px 22px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: flex-end; gap: 8px; background: #fcfbf9; }
.modal-foot .muted { margin-right: auto; font-size: 11px; }
.modal-toolbar { display: flex; align-items: center; gap: 9px; padding: 12px 22px; border-bottom: 1px solid var(--line); }
.modal-toolbar .search-box { min-width: 0; }
.modal-toolbar select { width: 150px; }
.flash-stack { position: fixed; top: 74px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 9px; font-size: 12px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.flash-success { border-color: #b9dfcd; background: var(--green-soft); color: var(--green); }
.flash-error { border-color: #f0c4c8; background: var(--red-soft); color: var(--brand); }

/* ---------- Utility ---------- */
.inline-form { display: inline; }
.kbd, kbd { font-family: Consolas, monospace; background: #f4efe8; border: 1px solid #e2d9cc; border-bottom-width: 2px; border-radius: 5px; padding: 2px 6px; font-size: 11px; color: #5e564c; }
.shortcut-grid { display: grid; grid-template-columns: 1fr auto; gap: 10px 18px; font-size: 12px; align-items: center; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-layout { grid-template-columns: 1fr; }
  .form-side { position: static; }
}
@media (max-width: 900px) {
  :root { --sidebar: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: 246px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .app-main { margin-left: 0; }
  .menu-btn { display: inline-grid !important; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 50px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-head h1 { font-size: 24px; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-brand { min-height: 260px; padding: 30px 28px; }
  .auth-brand h1 { font-size: 32px; }
  .auth-brand-inner { margin: 0; }
  .auth-brand-foot { display: none; }
  .auth-form-wrap { padding: 24px 16px 40px; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; position: static; overflow-x: auto; }
  .settings-nav a { white-space: nowrap; }
}
@media (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .project-grid { grid-template-columns: 1fr; }
  .topbar-actions .btn { display: none; }
  .topbar-actions .btn-primary { display: inline-flex; }
  .flash-stack { top: 70px; left: 16px; right: 16px; }
  .modal { padding: 8px; }
  .modal-dialog { max-height: 96vh; }
}

/* ============================================================
   Display preferences: font size / theme / dark mode
   ============================================================ */
.company-switch { display: flex; align-items: center; margin-right: 2px; }
.sidebar-company { display: none; margin: 0 0 8px; }
.sidebar-company select {
  width: 100%; min-height: 32px; padding: 4px 24px 4px 8px; border-radius: 7px;
  background-color: #2a2724; border: 1px solid rgba(255,255,255,.14); color: #e9e2d8;
  font-size: 12px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #e9e2d8 50%), linear-gradient(135deg, #e9e2d8 50%, transparent 50%);
  background-position: calc(100% - 12px) 14px, calc(100% - 8px) 14px;
  background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
}
.company-switch select {
  width: auto; max-width: 132px; min-height: 32px; padding: 4px 8px;
  border-radius: 7px; font-size: 12px; background: #fff; border-color: var(--line);
}
.display-btn { font-size: 13px; font-weight: 800; letter-spacing: -.05em; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.display-btn:hover { border-color: var(--brand); color: var(--brand); }
.display-section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.display-section:last-child { border-bottom: 0; }
.display-label { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 8px; letter-spacing: .06em; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; background: #f2eee8; border-radius: 9px; }
.segmented button { border: 0; background: transparent; border-radius: 7px; padding: 7px 18px; font-size: 13px; color: var(--muted); }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); font-weight: 700; }
.theme-swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.theme-swatches button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 10px; font-size: 11px; color: var(--ink-soft); }
.theme-swatches button i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.theme-swatches button.active { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }

/* Font scales */
:root { --fs-base: 14px; --fs-table: 13.5px; --fs-item: 13px; --fs-th: 11px; --fs-small: 12px; }
html[data-font="small"] { --fs-base: 13px; --fs-table: 12.5px; --fs-item: 12px; --fs-th: 10px; --fs-small: 11px; }
html[data-font="large"] { --fs-base: 15px; --fs-table: 14.5px; --fs-item: 14px; --fs-th: 12px; --fs-small: 13px; }
html[data-font="xlarge"] { --fs-base: 17px; --fs-table: 16px; --fs-item: 15.5px; --fs-th: 13px; --fs-small: 14px; }
html[data-font="xxlarge"] { --fs-base: 19px; --fs-table: 18px; --fs-item: 17px; --fs-th: 14px; --fs-small: 15px; }
body { font-size: var(--fs-base); }
html[data-font] .data-table td,
html[data-font] .project-card h3,
html[data-font] .template-card h3,
html[data-font] .quick-item strong,
html[data-font] .settings-content .form-grid,
html[data-font] .field input,
html[data-font] .field select,
html[data-font] .field textarea { font-size: var(--fs-table); }
html[data-font] .data-table th,
html[data-font] .fee-table th,
html[data-font] .payment-table th,
html[data-font] .project-metrics span,
html[data-font] .stat-label,
html[data-font] .eyebrow { font-size: var(--fs-th); }
html[data-font] .data-table .sub,
html[data-font] .project-client,
html[data-font] .muted,
html[data-font] .field > span,
html[data-font] .nav-item,
html[data-font] .settings-nav a { font-size: var(--fs-small); }
html[data-font] .page-head h1 { font-size: calc(28px + (var(--fs-base) - 14px)); }
html[data-font="small"] .page-head h1 { font-size: 25px; }
html[data-font="large"] .page-head h1 { font-size: 31px; }
html[data-font="xlarge"] .page-head h1 { font-size: 34px; }
html[data-font="xxlarge"] .page-head h1 { font-size: 38px; }
html[data-font] .stat-value { font-size: calc(27px + (var(--fs-base) - 14px)); }
html[data-font] .btn { font-size: var(--fs-small); }

/* Color themes */
html[data-theme="red"] { --brand: #c8102e; --brand-dark: #9c0b22; --brand-soft: #fbecee; }
html[data-theme="forest"] { --brand: #2f6b52; --brand-dark: #234f3e; --brand-soft: #e8f2ed; --gold: #9b7b4f; }
html[data-theme="blue"] { --brand: #2d5f8a; --brand-dark: #214866; --brand-soft: #eaf1f7; --gold: #8d7658; }
html[data-theme="amber"] { --brand: #a86b12; --brand-dark: #7d4e0b; --brand-soft: #fbf1df; --gold: #8b6b47; }
html[data-theme="purple"] { --brand: #6b4c9a; --brand-dark: #4f3675; --brand-soft: #f1ecf8; --gold: #8b7355; }
html[data-theme="teal"] { --brand: #0f766e; --brand-dark: #0b5b55; --brand-soft: #e6f5f3; --gold: #8a7454; }
html[data-theme="wine"] { --brand: #8a1c3c; --brand-dark: #67132c; --brand-soft: #f8e9ee; --gold: #8a7050; }
html[data-theme="graphite"] { --brand: #4b5563; --brand-dark: #374151; --brand-soft: #eef0f3; --gold: #8a7454; }
html[data-theme="gold"] { --brand: #8a6a1f; --brand-dark: #654d15; --brand-soft: #f7f0df; --gold: #8a6a1f; }
html[data-theme="rose"] { --brand: #b8325a; --brand-dark: #8f2345; --brand-soft: #fbeaef; --gold: #8a7050; }
html[data-theme="cyan"] { --brand: #0e7490; --brand-dark: #0a586d; --brand-soft: #e5f4f8; --gold: #8a7454; }
html[data-theme="orange"] { --brand: #b45309; --brand-dark: #8a3f07; --brand-soft: #fdf0e3; --gold: #8a6b47; }

/* Dark mode */
html[data-mode="dark"] {
  --bg: #151412;
  --card: #1e1c19;
  --ink: #f1ebe2;
  --ink-soft: #ddd3c6;
  --muted: #a79d90;
  --line: #37312a;
  --line-strong: #4b4339;
  --brand-soft: #3a1b20;
  --green: #6fbf95;
  --green-soft: #1d3328;
  --amber: #e0ad60;
  --amber-soft: #382a18;
  --red-soft: #3a1b20;
  --shadow: 0 16px 40px rgba(0, 0, 0, .35);
}
html[data-mode="dark"][data-theme="forest"] { --brand-soft: #1d3329; }
html[data-mode="dark"][data-theme="blue"] { --brand-soft: #1b2a38; }
html[data-mode="dark"][data-theme="amber"] { --brand-soft: #382a18; }
html[data-mode="dark"][data-theme="purple"] { --brand-soft: #2c203d; }
html[data-mode="dark"][data-theme="teal"] { --brand-soft: #15332f; }
html[data-mode="dark"][data-theme="wine"] { --brand-soft: #351724; }
html[data-mode="dark"][data-theme="graphite"] { --brand-soft: #262a31; }
html[data-mode="dark"][data-theme="gold"] { --brand-soft: #322917; }
html[data-mode="dark"][data-theme="rose"] { --brand-soft: #3a1c27; }
html[data-mode="dark"][data-theme="cyan"] { --brand-soft: #123039; }
html[data-mode="dark"][data-theme="orange"] { --brand-soft: #3a2415; }
html[data-mode="dark"] body { background: var(--bg); color: var(--ink); }
html[data-mode="dark"] .app-main,
html[data-mode="dark"] .content { background: var(--bg); }
html[data-mode="dark"] .topbar { background: rgba(21, 20, 18, .9); border-color: var(--line); }
html[data-mode="dark"] .topbar-title { color: var(--ink-soft); }
html[data-mode="dark"] .card,
html[data-mode="dark"] .stat-card,
html[data-mode="dark"] .project-card,
html[data-mode="dark"] .template-card,
html[data-mode="dark"] .auth-form-card,
html[data-mode="dark"] .modal-dialog { background: var(--card); border-color: var(--line); }
html[data-mode="dark"] .stat-card.accent { background: linear-gradient(135deg, #262321, #38312a); border-color: #443c33; }
html[data-mode="dark"] .data-table th { background: #24211d; border-color: var(--line); }
html[data-mode="dark"] .data-table td { border-color: #2c2823; }
html[data-mode="dark"] .data-table tbody tr:hover { background: #26221e; }
html[data-mode="dark"] .card-head,
html[data-mode="dark"] .modal-head,
html[data-mode="dark"] .modal-foot { border-color: var(--line); }
html[data-mode="dark"] .modal-foot { background: #191816; }
html[data-mode="dark"] input,
html[data-mode="dark"] select,
html[data-mode="dark"] textarea { background: #171614; border-color: var(--line-strong); color: var(--ink); }
html[data-mode="dark"] .btn-secondary,
html[data-mode="dark"] .display-btn,
html[data-mode="dark"] .company-switch select,
html[data-mode="dark"] .theme-swatches button,
html[data-mode="dark"] .settings-nav a:hover,
html[data-mode="dark"] .settings-nav a.active { background: #24211d; border-color: var(--line); color: var(--ink); }
html[data-mode="dark"] .btn-ghost:hover { background: rgba(255,255,255,.06); }
html[data-mode="dark"] .search-box input { background: #171614; border-color: var(--line); }
html[data-mode="dark"] .quick-item { border-color: var(--line); }
html[data-mode="dark"] .quick-item:hover { background: #26221e; }
html[data-mode="dark"] .project-metrics,
html[data-mode="dark"] .project-card-foot { border-color: var(--line); }
html[data-mode="dark"] .project-card:hover { border-color: var(--line-strong); }
html[data-mode="dark"] .status-done { color: var(--muted); background: #2a2621; }
html[data-mode="dark"] .tip-card code,
html[data-mode="dark"] .notice,
html[data-mode="dark"] .formula-preview { background: #26221d; border-color: #443a2d; color: var(--ink-soft); }
html[data-mode="dark"] .settings-nav a:hover,
html[data-mode="dark"] .settings-nav a.active { border-color: var(--line); }
html[data-mode="dark"] .auth-form-wrap { background: var(--bg); }
html[data-mode="dark"] .auth-form-card h2,
html[data-mode="dark"] .auth-form-card .muted { color: var(--ink); }
html[data-mode="dark"] .flash { background: var(--card); border-color: var(--line); color: var(--ink); }
html[data-mode="dark"] .flash-success { background: var(--green-soft); color: var(--green); border-color: #315d47; }
html[data-mode="dark"] .flash-error { background: var(--red-soft); color: #ff9ca8; border-color: #623038; }
html[data-mode="dark"] .segmented { background: #171614; }
html[data-mode="dark"] .segmented button.active { background: #302b25; color: var(--ink); }
html[data-mode="dark"] .category-pill { background: var(--card); border-color: var(--line); }
html[data-mode="dark"] .category-pill:hover,
html[data-mode="dark"] .category-pill.active { background: var(--brand-soft); border-color: var(--brand); }
html[data-mode="dark"] .empty-icon { background: var(--brand-soft); }
html[data-mode="dark"] .auth-page { background: var(--bg); }
html[data-mode="dark"] .auth-brand { background: #0f0e0d; }
html[data-mode="dark"] .auth-hint { color: var(--muted); }

@media (max-width: 900px) {
  .company-switch { display: none; }
  .display-btn { display: inline-grid; }
  .sidebar-company { display: block; }
}

/* Dashboard company quick switch */
.company-quick { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 20px; margin-bottom: 18px; }
.company-quick-copy h2 { margin: 3px 0 4px; font-size: 18px; }
.company-quick-copy p { font-size: 12px; color: var(--muted); }
.company-quick-list { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.company-quick-list form { margin: 0; }
.company-quick-chip { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 7px 12px; text-align: left; color: var(--ink); min-width: 100px; }
.company-quick-chip span { display: block; font-size: 13px; font-weight: 700; }
.company-quick-chip small { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }
.company-quick-chip:hover { border-color: var(--brand); }
.company-quick-chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.company-quick-chip.active small { color: var(--brand); }
html[data-mode="dark"] .company-quick-chip { background: #24211d; border-color: var(--line); color: var(--ink); }
html[data-mode="dark"] .company-quick-chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
@media (max-width: 900px) {
  .company-quick { flex-direction: column; align-items: flex-start; }
  .company-quick-list { justify-content: flex-start; }
}

/* Theme palette additions */
.custom-theme-row { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.custom-theme-row input[type=color] { width: 42px; height: 30px; padding: 2px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--card); }
.theme-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
/* Cost privacy on dashboards/lists */
.hide-cost .cost-sensitive { display: none !important; }
/* Mobile desktop-view fallback: keep a readable width and allow horizontal scroll */
html[data-view="desktop"] body { min-width: 1180px; }
html[data-view="desktop"] .sidebar { position: fixed; }
@media (max-width: 900px) {
  html[data-view="desktop"] .sidebar { transform: translateX(0); width: 220px; }
  html[data-view="desktop"] .app-main { margin-left: 220px; }
}

/* Mobile: keep fee/payment/catalog tables readable instead of squeezing labels vertically */
#feesContent, #paymentContent { overflow-x: auto; }
.fee-table, .payment-table { min-width: 760px; }
.catalog-table { min-width: 820px; }
@media (max-width: 900px) {
  .card-head { flex-wrap: wrap; gap: 10px; }
  .card-head > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
  .fee-table, .payment-table { min-width: 720px; }
  .catalog-table { min-width: 760px; }
  .catalog-stats { flex-wrap: wrap; }
  .filter-bar { align-items: stretch; }
  .filter-bar select, .filter-bar input { min-width: 0; }
  .page-head.compact { flex-direction: column; align-items: flex-start; gap: 6px; }
}

/* Dashboard task board */
.task-card h2 { margin: 2px 0 6px; }
.task-form { display: flex; flex-direction: column; gap: 7px; margin: 10px 0 12px; }
.task-form input, .task-form select { font-size: 12px; }
.task-form-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: center; }
.task-list { display: flex; flex-direction: column; gap: 6px; max-height: 210px; overflow-y: auto; }
.task-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px dashed var(--line); }
.task-item:first-child { border-top: 0; }
.task-item strong { display: block; font-size: 12px; line-height: 1.4; }
.task-item small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.task-item .text-btn { white-space: nowrap; font-size: 11px; }
html[data-mode="dark"] .task-item { border-color: var(--line); }
@media (max-width: 900px) {
  .task-form-row { grid-template-columns: 1fr 1fr; }
  .task-form-row .btn { grid-column: span 2; }
}

/* Microsoft To Do-ish task rows */
.task-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; border-top: 1px dashed var(--line); }
.task-item:first-child { border-top: 0; }
.task-content { flex: 1; min-width: 0; }
.task-check { width: 20px; height: 20px; border: 1.5px solid var(--line-strong); border-radius: 50%; background: transparent; color: var(--muted); font-size: 12px; line-height: 1; display: grid; place-items: center; }
.task-check:hover { border-color: var(--brand); color: var(--brand); }
.task-delete { width: 20px; height: 20px; border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; opacity: .55; }
.task-delete:hover { color: var(--brand); opacity: 1; }

/* Compact mobile topbar */
@media (max-width: 900px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
  .save-state span:last-child { display: none; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .btn-primary { padding: 0 12px; }
}

/* Make the reminder board prominent */
.dashboard-side { display: flex; flex-direction: column; gap: 16px; }
.dashboard-side .task-card { order: -1; border-left: 4px solid var(--brand); background: linear-gradient(180deg, var(--brand-soft), var(--card) 62%); }
.task-card h2 { display: flex; align-items: center; gap: 8px; font-size: 22px; }
.task-count { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--brand); color: var(--on-brand); font-size: 12px; }
html[data-mode="dark"] .dashboard-side .task-card { background: linear-gradient(180deg, var(--brand-soft), var(--card) 62%); }

/* Text danger button */
.btn.danger { color: var(--brand); border-color: var(--brand-soft); }
.btn.danger:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.template-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.template-actions form { margin: 0; }
.template-actions .text-btn.danger { color: var(--brand); }

/* Refined reminder card */
.task-card {
  border-left: 4px solid var(--brand);
  border-radius: 14px;
  padding: 16px 16px 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand-soft) 82%, var(--card)) 0, var(--card) 92px);
}
.task-card .eyebrow { font-size: 10px; letter-spacing: .18em; margin-bottom: 4px; }
.task-card h2 { font-size: 20px; line-height: 1.25; margin: 0 0 5px; letter-spacing: .01em; }
.task-count { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; font-size: 11px; }
.task-card > p.muted { font-size: 11px; line-height: 1.55; margin: 0 0 12px; }
.task-form { gap: 7px; margin: 0 0 12px; }
.task-form > input[name="title"] { height: 36px; font-size: 12px; background: var(--card); }
.task-form-row { grid-template-columns: minmax(0, .9fr) minmax(0, 1.2fr) auto; gap: 6px; }
.task-form-row input,
.task-form-row select { height: 32px; font-size: 11px; padding: 0 8px; background: var(--card); }
.task-form-row .btn { height: 32px; min-height: 32px; padding: 0 12px; border-radius: 7px; font-size: 11px; }
.task-list { gap: 5px; max-height: 230px; }
.task-item {
  align-items: center; gap: 8px; padding: 8px 9px; border: 1px solid var(--line);
  border-radius: 9px; background: color-mix(in srgb, var(--bg) 60%, var(--card)); border-top: 1px solid var(--line);
}
.task-item:first-child { border-top: 1px solid var(--line); }
.task-item:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--card); }
.task-check { width: 21px; height: 21px; border-width: 1.4px; font-size: 11px; flex: none; }
.task-content strong { font-size: 12px; font-weight: 650; line-height: 1.35; }
.task-content small { font-size: 10px; margin-top: 2px; }
.task-delete { width: 18px; height: 18px; opacity: .28; flex: none; }
.task-item:hover .task-delete { opacity: .8; }
@media (max-width: 900px) {
  .task-card { padding: 14px; }
  .task-form-row { grid-template-columns: 1fr 1fr; }
  .task-form-row .btn { grid-column: span 2; height: 34px; }
}
html[data-mode="dark"] .task-item { background: #201d1a; border-color: var(--line); }
html[data-mode="dark"] .task-item:hover { background: #26221e; }

/* Local draft recovery banner */
.draft-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; margin: 0 0 12px; border: 1px solid var(--brand); background: var(--brand-soft); border-radius: 10px; color: var(--ink-soft); }
.draft-banner[hidden] { display: none; }
.draft-banner div:first-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.draft-banner strong { font-size: 13px; color: var(--ink); }
.draft-banner span { font-size: 11px; color: var(--muted); }
.draft-banner-actions { display: flex; gap: 6px; flex: none; }
@media (max-width: 900px) { .draft-banner { flex-direction: column; align-items: flex-start; } .draft-banner-actions { width: 100%; justify-content: flex-end; } }

/* Multi-site project cards */
.project-card { position: relative; }
.project-card-link { display: block; color: inherit; text-decoration: none; }
.project-card-link h3 { color: var(--ink); }
.project-card-pinned { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.project-top-right { display: flex; align-items: center; gap: 5px; }
.pin-form { margin: 0; }
.pin-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; cursor: pointer; }
.pin-btn.active { color: #c9973f; }
.project-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.project-tags span { font-size: 10px; color: var(--brand); background: var(--brand-soft); border-radius: 999px; padding: 2px 7px; }
.project-next-text { display: block; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px !important; }
.check-inline { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.status-warning { background: #f6e7cf; color: #875a1d; }
html[data-mode="dark"] .status-warning { background: #33291d; color: #d8b27a; }
@media (max-width: 700px) {
  .filter-bar { flex-wrap: wrap; }
  .project-next-text { max-width: 110px; }
}

/* Today's sites */
.work-sites { margin-bottom: 18px; }
.work-site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.work-site-card { display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; color: inherit; text-decoration: none; background: var(--card); min-width: 0; }
.work-site-card:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.work-site-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.work-site-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.work-site-meta, .work-site-foot { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.work-site-next { font-size: 11px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 3px 0; }
.work-site-foot { margin-top: 2px; padding-top: 5px; border-top: 1px solid var(--line); }
.attention { font-size: 10px; border-radius: 999px; padding: 2px 6px; white-space: nowrap; }
.attention-danger { background: var(--brand-soft); color: var(--brand); }
.attention-today { background: #f6e7cf; color: #875a1d; }
.stat-card.danger .stat-value { color: var(--brand); }
.compact-empty { padding: 12px; }
@media (max-width: 700px) {
  .work-site-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .work-site-card { padding: 9px; }
  .work-site-name { font-size: 12px; }
}
@media (max-width: 420px) { .work-site-grid { grid-template-columns: 1fr; } }
