:root {
  color-scheme: light;
  --ink: #17211e;
  --muted: #65716d;
  --line: #dfe6e3;
  --canvas: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #edf3f1;
  --green: #1d6b52;
  --green-dark: #143c31;
  --green-soft: #e5f1ed;
  --orange: #c66d2e;
  --red: #a94343;
  --focus: #2a8065;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
.nav-scrim, .nav-close { display: none; }
[hidden] { display: none !important; }
html { background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { outline: none; }
:focus-visible { box-shadow: 0 0 0 3px rgba(42, 128, 101, .25); }
::selection { color: #fff; background: var(--green); }

.login-screen { display: grid; min-height: 100vh; grid-template-columns: minmax(280px,.8fr) minmax(420px,1.2fr); background: #fff; }
.login-brand { display: flex; align-items: flex-start; gap: 14px; padding: 42px; color: #fff; background: var(--green-dark); }
.login-brand .brand-mark { width: 48px; height: 48px; }
.login-brand div { display: grid; gap: 3px; }
.login-brand strong { font-size: 20px; }
.login-brand small { color: #aec7be; }
.login-card { display: grid; width: min(420px, calc(100% - 48px)); align-self: center; gap: 18px; justify-self: center; }
.login-card h1 { margin: 0; font-size: 30px; letter-spacing: -.03em; }
.login-card p { max-width: 38ch; margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.login-card label { display: grid; gap: 7px; color: #45534e; font-size: 13px; font-weight: 700; }
.login-card input { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid #cbd7d2; border-radius: 10px; color: var(--ink); background: #fff; }
.login-card .button { min-height: 46px; }
.login-card > small { color: var(--muted); text-align: center; }

.admin-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; width: 248px;
  flex-direction: column; padding: 24px 18px; color: #fff; background: var(--green-dark);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 13px; color: var(--green-dark); background: #fff; font-size: 19px; font-weight: 800; }
.brand span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 17px; letter-spacing: -.01em; }
.brand small { color: #a9c1b9; font-size: 12px; }
#primary-nav { display: grid; gap: 14px; min-height: 0; overflow-y: auto; padding-right: 3px; scrollbar-width: thin; }
.nav-group { display: grid; gap: 3px; }
.nav-group > strong { padding: 0 12px 5px; color: #78988d; font-size: 10px; letter-spacing: .09em; text-transform: uppercase; }
#primary-nav button {
  display: flex; width: 100%; min-height: 44px; align-items: center; gap: 11px; padding: 0 12px;
  border: 0; border-radius: 10px; color: #bed0ca; background: transparent; cursor: pointer; text-align: left;
}
#primary-nav button:hover { color: #fff; background: rgba(255,255,255,.07); }
#primary-nav button.active { color: #fff; background: rgba(255,255,255,.13); font-weight: 700; }
#primary-nav svg { width: 19px; height: 19px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.sidebar-note { margin-top: 16px; padding: 12px 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; background: rgba(255,255,255,.05); }
.sidebar-note strong { font-size: 13px; }
.sidebar-note p { margin: 7px 0 0; color: #a9c1b9; font-size: 12px; line-height: 1.65; }
.admin-account { display: grid; gap: 3px; margin-top: 12px; padding: 13px 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; }
.admin-account span { font-size: 13px; font-weight: 700; }
.admin-account small { color: #a9c1b9; }
.admin-account button { min-height: 34px; margin-top: 7px; border: 1px solid rgba(255,255,255,.17); border-radius: 8px; color: #d9e6e1; background: transparent; cursor: pointer; }
.admin-account button:hover { color: #fff; background: rgba(255,255,255,.07); }

.main-column { min-height: 100vh; margin-left: 248px; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; min-height: 84px; align-items: center; gap: 18px;
  padding: 16px 30px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96);
  box-shadow: 0 8px 24px rgba(20, 60, 49, .04);
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.today { display: grid; gap: 3px; margin-left: auto; text-align: right; }
.today span { color: var(--muted); font-size: 11px; }
.today strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.menu-button { display: none; min-height: 40px; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--green-dark); cursor: pointer; }
main { width: min(1500px, 100%); margin: 0 auto; padding: 24px 30px 42px; }
.domain-bar { display: flex; align-items: center; gap: 24px; justify-content: space-between; margin-bottom: 20px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.domain-bar > div:first-child { display: grid; gap: 4px; }
.domain-bar strong { font-size: 13px; }
.domain-bar span { color: var(--muted); font-size: 12px; }
.domain-tabs { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: thin; }
.domain-tabs button { min-height: 36px; flex: 0 0 auto; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: #fff; cursor: pointer; }
.domain-tabs button:hover { border-color: #9ebbb2; color: var(--green); }
.domain-tabs button.active { border-color: var(--green); color: var(--green); background: var(--green-soft); font-weight: 700; }

.page-stack { display: grid; gap: 18px; }
.section-head { display: flex; align-items: flex-end; gap: 20px; justify-content: space-between; }
.section-head h2, .panel h2 { margin: 0; font-size: 18px; letter-spacing: -.015em; }
.section-head p, .panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; padding: 0 14px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 700; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: #175c46; }
.button.secondary { border-color: var(--line); color: var(--ink); background: #fff; }
.button.danger { border-color: #eccdcd; color: var(--red); background: #fff; }
.button.small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.button:disabled { cursor: not-allowed; opacity: .52; transform: none; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.metric { min-height: 128px; padding: 20px; border-radius: 14px; background: var(--surface); box-shadow: 0 8px 26px rgba(20,60,49,.06); }
.metric header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.metric header span { color: var(--muted); font-size: 12px; }
.metric header i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.metric strong { display: block; margin-top: 19px; font-size: 30px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.metric small { color: var(--muted); font-size: 11px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(300px,.55fr); gap: 18px; }
.panel { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.panel-heading { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; margin-bottom: 16px; }
.domain-summary { display: grid; gap: 14px; }
.summary-row { display: grid; grid-template-columns: 86px 1fr 48px; align-items: center; gap: 12px; }
.summary-row span, .summary-row strong { font-size: 12px; }
.summary-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.summary-track { height: 8px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
.summary-track i { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.activity-list { display: grid; gap: 0; }
.activity-row { display: grid; grid-template-columns: 116px 92px minmax(0,1fr); gap: 12px; padding: 12px 0; border-bottom: 1px solid #edf1ef; font-size: 12px; }
.activity-row:last-child { border-bottom: 0; }
.activity-row time { color: var(--muted); font-variant-numeric: tabular-nums; }
.activity-row b { font-weight: 700; }

.finance-summary { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.finance-summary > div { padding: 18px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.finance-summary span { display: block; color: var(--muted); font-size: 12px; }
.finance-summary strong { display: block; margin-top: 9px; font-size: 22px; font-variant-numeric: tabular-nums; }
.money-cell { color: #176044; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-cell.negative { color: #984747; }
.progress-panel { scroll-margin-top: 96px; }
.progress-layout { display: grid; grid-template-columns: minmax(250px,.72fr) minmax(340px,1.28fr); gap: 24px; }
.progress-timeline { display: grid; align-content: start; }
.progress-timeline article { display: grid; grid-template-columns: 114px minmax(0,1fr); gap: 14px; position: relative; padding: 0 0 20px; }
.progress-timeline article::before { content: ""; position: absolute; left: 121px; top: 7px; width: 7px; height: 7px; border: 2px solid #fff; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px #bfd5cd; }
.progress-timeline article::after { content: ""; position: absolute; left: 124px; top: 16px; bottom: 0; width: 1px; background: #dbe6e2; }
.progress-timeline article:last-child::after { display: none; }
.progress-timeline time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.progress-timeline article > div { padding-left: 14px; }
.progress-timeline p { margin: 5px 0; color: #45534f; font-size: 12px; line-height: 1.5; }
.progress-timeline small { color: var(--muted); }
.upload-form { display: grid; gap: 12px; padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: #f8faf9; }
.upload-form h3 { margin: 0; font-size: 15px; }
.upload-form > p { margin: -5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.upload-form label { display: grid; gap: 6px; color: #52605b; font-size: 12px; font-weight: 700; }
.upload-form input { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid #ccd7d3; border-radius: 9px; background: #fff; }
.file-picker input { padding: 6px; }
.photo-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 11px; margin-top: 13px; }
.photo-grid figure { overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.photo-grid img, .photo-unavailable { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--surface-soft); }
.photo-unavailable { display: grid; place-content: center; color: var(--muted); font-size: 11px; }
.photo-grid figcaption { display: grid; gap: 4px; padding: 9px; color: #45534f; font-size: 11px; }
.photo-grid time, .photo-empty { color: var(--muted); font-size: 10px; }
.legacy-shell { overflow: hidden; min-height: calc(100vh - 140px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.legacy-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.legacy-toolbar h2 { margin: 0; font-size: 18px; }
.legacy-toolbar p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.legacy-notice { padding: 9px 20px; color: #6a5737; background: #fff9e9; font-size: 11px; }
.legacy-frame { display: block; width: 100%; height: calc(100vh - 245px); min-height: 580px; border: 0; background: #fff; }

.table-panel { overflow: hidden; padding: 0; }
.table-toolbar { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.table-toolbar .search { position: relative; width: min(340px, 100%); }
.table-toolbar input, .employee-form input, .employee-form select, .employee-form textarea, .admin-dialog input {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid #ccd7d3; border-radius: 9px; color: var(--ink); background: #fff;
}
.table-toolbar input::placeholder, input::placeholder, textarea::placeholder { color: #7a8682; }
.table-toolbar .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 11px 14px; color: #596762; background: #f7f9f8; font-size: 11px; font-weight: 700; text-align: left; white-space: nowrap; }
td { padding: 13px 14px; border-top: 1px solid #edf1ef; vertical-align: top; }
tbody tr:hover { background: #fafcfb; }
.cell-main { display: grid; gap: 4px; min-width: 120px; }
.cell-main small { color: var(--muted); font-size: 11px; }
.date-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
.status { display: inline-flex; min-height: 25px; align-items: center; padding: 0 8px; border-radius: 999px; color: #52625d; background: #eef2f0; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status.active, .status.completed, .status.resolved, .status.success { color: #176044; background: #e5f2ec; }
.status.pending, .status.dispatched { color: #9a571e; background: #fff0e3; }
.status.disabled, .status.rejected, .status.cancelled, .status.failed { color: #984747; background: #fbeaea; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 150px; }
.row-actions input { min-width: 170px; min-height: 32px; padding: 0 9px; border: 1px solid #ccd7d3; border-radius: 8px; }
.empty-state { display: grid; min-height: 210px; place-content: center; padding: 28px; color: var(--muted); text-align: center; }
.empty-state strong { color: #44514d; }
.empty-state p { max-width: 46ch; margin: 7px 0 0; font-size: 12px; line-height: 1.65; }
.loading-state { display: grid; min-height: 280px; place-content: center; color: var(--muted); text-align: center; }
.loading-state::before { content: ""; width: 28px; height: 28px; margin: 0 auto 12px; border: 3px solid #dce8e4; border-top-color: var(--green); border-radius: 50%; animation: admin-spin .8s linear infinite; }
.error-panel { display: grid; min-height: 220px; place-content: center; padding: 28px; border: 1px solid #efcccc; border-radius: 14px; color: var(--red); background: #fffafa; text-align: center; }
.error-panel p { max-width: 52ch; margin: 8px auto 14px; color: #7a5555; font-size: 12px; }
@keyframes admin-spin { to { transform: rotate(360deg); } }

.employee-form { display: grid; gap: 15px; }
.employee-form[hidden] { display: none; }
.form-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 13px; }
.employee-form label, .admin-dialog label { display: grid; align-content: start; gap: 6px; color: #52605b; font-size: 12px; font-weight: 700; }
.employee-form textarea { min-height: 72px; resize: vertical; }
.domain-checks { display: flex; flex-wrap: wrap; gap: 9px; margin: 0; padding: 13px; border: 1px solid var(--line); border-radius: 11px; }
.domain-checks legend { padding: 0 6px; font-size: 12px; font-weight: 700; }
.domain-checks label { display: flex; min-height: 34px; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.domain-checks input { width: 16px; height: 16px; accent-color: var(--green); }
.branch-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 9px; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 12px; }
.field-help { margin: -3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.admin-dialog { width: min(460px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 15px; color: var(--ink); background: #fff; box-shadow: 0 24px 80px rgba(20,60,49,.25); }
.admin-dialog::backdrop { background: rgba(13,30,25,.48); }
.admin-dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.dialog-head > button { min-height: 34px; border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 360px; padding: 12px 15px; border-radius: 10px; color: #fff; background: #173b31; box-shadow: 0 12px 30px rgba(20,60,49,.22); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .progress-layout { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { min-height: 150px; padding: 28px 24px; }
  .login-card { padding: 42px 0; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after { content: ""; position: fixed; inset: 0; z-index: 15; background: rgba(13,30,25,.4); }
  .main-column { margin-left: 0; }
  .menu-button { display: inline-flex; align-items: center; }
  .topbar { min-height: 76px; padding: 13px 16px; }
  .topbar h1 { font-size: 19px; }
  .topbar p { display: none; }
  .today { display: none; }
  main { padding: 16px; }
  .domain-bar { align-items: stretch; flex-direction: column; gap: 12px; }
  .domain-tabs { padding-bottom: 3px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 112px; padding: 16px; }
  .metric strong { margin-top: 15px; font-size: 26px; }
  .section-head { align-items: stretch; flex-direction: column; gap: 10px; }
  .section-head .button { width: 100%; }
  .form-grid, .branch-fields { grid-template-columns: 1fr; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .table-toolbar .search { width: 100%; }
  .table-toolbar .count { margin-left: 0; }
  .activity-row { grid-template-columns: 92px minmax(0,1fr); }
  .activity-row b { display: none; }
  .finance-summary { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .legacy-toolbar { align-items: stretch; flex-direction: column; }
  .legacy-toolbar .button { width: 100%; }
  .legacy-frame { height: calc(100vh - 280px); min-height: 520px; }
}

@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr; }
  .domain-tabs { margin-right: -16px; padding-right: 16px; }
  .form-actions, .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button, .dialog-actions .button { width: 100%; }
  .toast { right: 14px; bottom: 14px; left: 14px; max-width: none; }
  .photo-grid { grid-template-columns: 1fr; }
  .progress-timeline article { grid-template-columns: 92px minmax(0,1fr); }
  .progress-timeline article::before { left: 99px; }
  .progress-timeline article::after { left: 102px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .loading-state::before { animation: none; }
}

@media (max-width: 780px) {
  body.nav-open { overflow: hidden; }
  body.nav-open::after { display: none; }
  body.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 19; border: 0; background: rgba(13,30,25,.45); }
  .sidebar { width: min(310px, 88vw); height: 100dvh; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); visibility: hidden; }
  body.nav-open .sidebar { visibility: visible; }
  .sidebar .nav-close { display: block; align-self: flex-end; flex-shrink: 0; margin-bottom: 12px; }
  .sidebar .brand { padding-bottom: 18px; }
  #primary-nav { flex: 1; }
  .sidebar-note { display: none; }
  .admin-account { flex-shrink: 0; }
  .topbar { padding-top: max(13px, env(safe-area-inset-top)); }
  main { padding: 16px 12px max(28px, env(safe-area-inset-bottom)); }
  .domain-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 0; padding: 0; overflow: visible; }
  .domain-tabs button, .button, .button.small, .menu-button, #primary-nav button, .admin-account button { min-height: 44px; }
  input, select, textarea, .table-toolbar input, .employee-form input, .employee-form select, .employee-form textarea, .upload-form input { font-size: 16px; min-height: 44px; max-width: 100%; }
  .table-scroll { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  tbody tr { padding: 16px; border-top: 1px solid var(--line); }
  tbody tr:first-child { border-top: 0; }
  td { display: grid; grid-template-columns: 88px minmax(0,1fr); gap: 12px; padding: 8px 0; border: 0; font-size: 14px; overflow-wrap: anywhere; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 500; }
  td:first-child { padding-top: 0; }
  .date-cell { white-space: normal; }
  .cell-main, .row-actions { min-width: 0; }
  .cell-main small, .status, .count, .field-help, .photo-grid figcaption, .photo-grid time, .photo-empty, .progress-timeline time, .upload-form > p { font-size: 12px; }
  .row-actions { flex-direction: column; }
  .row-actions input { min-width: 0; width: 100%; }
  .panel { padding: 16px; }
  .table-panel { padding: 0; }
  .panel-heading h2 { overflow-wrap: anywhere; }
  .panel-heading > button { flex-shrink: 0; }
  .progress-layout { grid-template-columns: minmax(0,1fr); }
  .upload-form { padding: 12px; }
  .upload-form label { min-width: 0; }
  .photo-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .legacy-toolbar, .legacy-notice { padding: 14px; }
  .legacy-notice { font-size: 12px; line-height: 1.6; }
  .button:hover { transform: none; }
  .button:active { opacity: .8; }
}
