:root {
  color-scheme: light;
  --ink: #2f2a25;
  --muted: #766d64;
  --paper: #fffdf9;
  --canvas: #f5f0e8;
  --line: #e5ddd1;
  --green: #506544;
  --green-dark: #34442d;
  --green-soft: #e8eee3;
  --amber: #a96836;
  --amber-soft: #f4e7d7;
  --red: #a34f45;
  --red-soft: #f8e7e3;
  --shadow: 0 16px 40px rgba(61, 48, 34, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background: radial-gradient(circle at 50% 5%, #fffdf8 0, var(--canvas) 55%); }
.login-card { width: min(420px, 100%); padding: 42px; border: 1px solid var(--line); border-radius: 24px; background: var(--paper); box-shadow: var(--shadow); }
.brand-mark { width: 54px; height: 54px; display: inline-flex; align-items: center; justify-content: center; border-radius: 17px; color: #fff; background: var(--green); font-family: "Songti SC", serif; font-size: 26px; font-weight: 700; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 20px; }
.eyebrow { margin: 20px 0 7px; color: var(--amber); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.login-card h1 { margin: 0; font: 700 30px/1.3 "Songti SC", serif; }
.login-copy { margin: 10px 0 28px; color: var(--muted); }
.security-note { margin: 22px 0 0; text-align: center; color: #91877e; font-size: 12px; }

.stack-form { display: grid; gap: 16px; }
label { min-width: 0; display: grid; gap: 8px; color: #544d46; font-size: 13px; font-weight: 650; }
input, select { width: 100%; min-height: 44px; border: 1px solid #d9d0c4; border-radius: 11px; padding: 10px 13px; outline: none; color: var(--ink); background: #fff; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(80, 101, 68, .12); }
input::placeholder { color: #aaa198; font-weight: 400; }
.form-error { min-height: 18px; margin: -5px 0 0; color: var(--red); font-size: 13px; }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 11px; padding: 9px 18px; font-weight: 750; line-height: 1.25; text-align: center; transition: transform .12s, opacity .12s, background .12s; }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .58; }
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { color: #fff; background: var(--amber); }
.button.ghost { color: var(--green-dark); border-color: #cad4c4; background: #f5f8f2; }
.button.danger { min-height: 34px; color: var(--red); border-color: #e9c9c4; padding: 6px 11px; background: #fff7f5; font-size: 12px; }
.button.wide { width: 100%; }
.text-button { border: 0; padding: 4px 0; color: var(--green); background: transparent; font-weight: 700; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 18px 20px; color: #f7f4ee; background: #2f3b2b; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 17px; }
.sidebar-brand span { margin-top: 2px; color: #bdc8b7; font-size: 12px; }
.nav-list { display: grid; gap: 7px; }
.nav-item { display: grid; gap: 2px; border: 0; border-radius: 12px; padding: 11px 13px; text-align: left; color: #d8e0d3; background: transparent; }
.nav-item span { font-size: 14px; font-weight: 750; }
.nav-item small { color: #9eac98; font-size: 11px; }
.nav-item:hover, .nav-item.active { color: #2f352c; background: #f0e9dc; }
.nav-item:hover small, .nav-item.active small { color: #766d64; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid rgba(255,255,255,.12); padding: 18px 8px 0; color: #aeb9a8; font-size: 12px; }
.sidebar-foot .text-button { color: #f1d8bd; font-size: 12px; }

.main-content { width: min(1220px, 100%); min-width: 0; padding: 38px clamp(24px, 4vw, 58px) 72px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-header .eyebrow { margin-top: 0; }
.page-header h1 { margin: 0; font: 700 32px/1.25 "Songti SC", serif; }
.page-header p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.service-state { display: inline-flex; align-items: center; gap: 8px; border: 1px solid #d6dfd0; border-radius: 999px; padding: 8px 12px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 700; white-space: nowrap; }
.service-state i { width: 7px; height: 7px; border-radius: 50%; background: #668258; box-shadow: 0 0 0 4px rgba(102,130,88,.13); }

.tab-panel { min-width: 0; display: none; }
.tab-panel.active { display: block; }
.panel-card { min-width: 0; border: 1px solid var(--line); border-radius: 18px; padding: 22px; background: var(--paper); box-shadow: 0 8px 24px rgba(61,48,34,.045); }
.panel-heading, .panel-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.panel-heading { margin-bottom: 18px; }
.panel-heading h2, .panel-toolbar h2 { margin: 0; font-size: 18px; }
.panel-heading p, .panel-toolbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; font-weight: 400; }
.panel-toolbar { margin-bottom: 18px; }
.filter-grid { display: grid; grid-template-columns: minmax(260px, 1fr) 180px auto; align-items: end; gap: 12px; }
.filter-grid.compact { grid-template-columns: minmax(240px, 520px) auto; justify-content: start; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.result-area { min-width: 0; margin-top: 16px; }
.empty-state, .loading-state, .error-state { border: 1px dashed #d8cec1; border-radius: 16px; padding: 40px 24px; text-align: center; color: var(--muted); background: rgba(255,253,249,.7); }
.error-state { color: var(--red); border-color: #e9c9c4; background: var(--red-soft); }

.data-table-wrap { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; min-width: 790px; }
.data-table th, .data-table td { border-bottom: 1px solid #eee7de; padding: 14px 15px; text-align: left; vertical-align: middle; font-size: 13px; }
.data-table th { color: var(--muted); background: #faf7f1; font-size: 12px; font-weight: 750; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table strong { display: block; font-weight: 750; }
.data-table small { display: block; margin-top: 4px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.status { display: inline-flex; align-items: center; justify-content: center; min-height: 25px; border-radius: 999px; padding: 4px 9px; color: #645b52; background: #eee9e1; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status.success { color: #416038; background: var(--green-soft); }
.status.warning { color: #8d5b29; background: var(--amber-soft); }
.status.danger { color: var(--red); background: var(--red-soft); }

.user-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--line); border-radius: 15px; padding: 17px 18px; background: var(--paper); }
.user-card + .user-card { margin-top: 10px; }
.user-card h3 { margin: 0; font-size: 16px; }
.user-meta { display: flex; flex-wrap: wrap; gap: 7px 16px; margin-top: 7px; color: var(--muted); font-size: 12px; }
.user-workspace { margin-top: 22px; }
.selected-user-bar { display: flex; align-items: center; justify-content: space-between; border: 1px solid #cad5c4; border-radius: 14px; margin-bottom: 14px; padding: 13px 17px; background: var(--green-soft); }
.selected-user-bar span, .selected-user-bar strong { display: block; }
.selected-user-bar span { color: var(--muted); font-size: 11px; }
.selected-user-bar strong { margin-top: 3px; font-size: 15px; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.action-card { box-shadow: none; }
.sub-list { margin-top: 22px; display: grid; gap: 9px; }
.entitlement { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 13px; }
.entitlement p { margin: 0; font-size: 13px; font-weight: 700; }
.entitlement small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-card { border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: var(--paper); }
.metric-card span { display: block; color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; margin-top: 7px; font-size: 26px; font-variant-numeric: tabular-nums; }
.funnel-controls { display: flex; align-items: end; gap: 10px; }
.funnel-controls label { min-width: 145px; }
.funnel-bar { width: 180px; height: 6px; overflow: hidden; border-radius: 99px; margin-top: 8px; background: #ece6dd; }
.funnel-bar i { height: 100%; display: block; border-radius: inherit; background: var(--green); }
.funnel-table { min-width: 680px; }
.table-card { padding-bottom: 8px; }
.audit-card { border: 1px solid var(--line); border-radius: 14px; padding: 15px 17px; background: var(--paper); }
.audit-card + .audit-card { margin-top: 9px; }
.audit-top { display: flex; justify-content: space-between; gap: 14px; }
.audit-top strong { font-size: 14px; }
.audit-top time { color: var(--muted); font-size: 12px; }
.audit-card p { margin: 8px 0 0; color: var(--muted); font-size: 12px; word-break: break-word; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 620px) minmax(220px, 300px); align-items: start; gap: 16px; }
.settings-card { box-shadow: none; }
.password-notice { margin-bottom: 18px; border: 1px solid #e8c993; border-radius: 12px; padding: 12px 14px; color: #825729; background: var(--amber-soft); font-size: 13px; line-height: 1.55; }
.password-rule { margin: -4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.account-summary span, .account-summary strong { display: block; }
.account-summary span { color: var(--muted); font-size: 12px; }
.account-summary strong { margin-top: 8px; font-size: 22px; word-break: break-word; }
.account-summary p { margin: 13px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.toast { position: fixed; z-index: 20; right: 24px; bottom: 24px; max-width: min(380px, calc(100vw - 32px)); border-radius: 12px; padding: 13px 16px; color: #fff; background: var(--green-dark); box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: #7e3d36; }

@media (max-width: 900px) {
  .app-shell { width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr); overflow-x: hidden; }
  .sidebar { position: sticky; z-index: 10; width: 100%; min-width: 0; max-width: 100vw; height: auto; overflow: hidden; padding: 12px 14px 0; }
  .sidebar-brand { display: none; }
  .nav-list { width: 100%; min-width: 0; max-width: 100%; display: flex; overflow-x: auto; gap: 7px; padding-bottom: 11px; }
  .nav-item { min-width: 105px; padding: 8px 11px; }
  .nav-item small { display: none; }
  .sidebar-foot { display: none; }
  .main-content { max-width: 100vw; padding: 26px 18px 60px; }
  .two-column { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .funnel-controls { width: 100%; align-items: stretch; flex-direction: column; }
}

@media (max-width: 620px) {
  .login-card { padding: 30px 24px; }
  .page-header { align-items: flex-end; }
  .page-header h1 { font-size: 27px; }
  .page-header p:last-child { max-width: 260px; }
  .service-state { display: none; }
  .panel-card { padding: 18px; border-radius: 15px; }
  .filter-grid, .filter-grid.compact { grid-template-columns: 1fr; }
  .filter-grid .button { width: 100%; }
  .panel-heading, .panel-toolbar { align-items: flex-start; }
  .metrics-grid { gap: 9px; }
  .metric-card { padding: 15px; }
  .metric-card strong { font-size: 23px; }
  .user-card { align-items: flex-start; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .toast { right: 16px; bottom: 16px; }
}
