:root {
  --bg: #f3f0e8;
  --paper: #fffdf8;
  --ink: #16201c;
  --muted: #51625b;
  --line: #d8d0c2;
  --deep: #14352c;
  --red: #dc3f2e;
  --gold: #f7c948;
  --green: #2f7a55;
  --shadow: 6px 6px 0 #16201c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background:
    linear-gradient(90deg, rgba(20,53,44,.08) 1px, transparent 0),
    linear-gradient(0deg, rgba(20,53,44,.08) 1px, transparent 0),
    var(--bg);
  background-size: 26px 26px;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 18px;
  align-items: stretch;
}

.brand-panel,
.login-card {
  border: 2px solid var(--ink);
  border-radius: 8px;
}

.brand-panel {
  min-height: 560px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 30px;
  background:
    linear-gradient(rgba(20,53,44,.15), rgba(20,53,44,.15)),
    linear-gradient(135deg, var(--gold), var(--gold) 48%, var(--red) 0, var(--red) 64%, var(--deep) 0);
  box-shadow: 8px 8px 0 var(--ink);
}

.eyebrow {
  margin: 0;
  color: #6b3f00;
  font-size: 12px;
  font-weight: 800;
}

h1, h2, h3, p { letter-spacing: 0; }

.brand-panel h1 {
  max-width: 460px;
  margin: 8px 0 0;
  color: #fffdf8;
  font-size: clamp(42px, 8vw, 72px);
  line-height: .98;
  text-shadow: 0 2px 0 var(--ink);
}

.summary {
  max-width: 520px;
  margin: 20px 0 0;
  color: #fffdf8;
  font-size: 16px;
  line-height: 1.7;
}

.route-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
}

.route-line span {
  padding: 9px 12px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  font-size: 13px;
  font-weight: 800;
}

.route-line i {
  width: 28px;
  height: 2px;
  background: var(--paper);
}

.login-card {
  padding: 22px;
  background: var(--paper);
}

.card-head { margin-bottom: 16px; }
.card-head h2 { margin: 4px 0 0; font-size: 28px; }

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-tabs button {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.mode-tabs button {
  min-height: 42px;
}

.mode-tabs button.active {
  background: var(--deep);
  color: #fff;
}

.role-badge {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  color: #fff;
  background: var(--deep);
  font-weight: 900;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #cfc6b4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}

.field textarea {
  min-height: 94px;
  padding-block: 10px;
  resize: vertical;
}

.login-btn,
.primary-btn,
.ghost-btn,
.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  border-radius: 8px;
  font-weight: 900;
}

.login-btn,
.primary-btn {
  border: 0;
  color: #fff;
  background: var(--red);
}

.login-btn {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
}

.ghost-btn {
  border: 1px solid var(--ink);
  color: var(--ink);
  background: #fff;
}

.danger-btn {
  border: 1px solid var(--red);
  color: var(--red);
  background: #fff;
}

.error-text {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

.app-shell {
  min-height: 100vh;
  background: var(--bg);
}

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  background: var(--deep);
  color: #fff;
  box-shadow: 0 6px 18px rgba(10,26,21,.18);
}

.mobile-topbar strong,
.mobile-topbar span { display: block; }
.mobile-topbar strong { font-size: 17px; line-height: 22px; }
.mobile-topbar span { color: #c6d9d1; font-size: 12px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: rgba(255,255,255,.11);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.workbench {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 14px 12px 96px;
}

.hero-strip {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  min-height: 138px;
  padding: 18px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--gold);
  box-shadow: var(--shadow);
}

.hero-strip h1 {
  margin: 3px 0 8px;
  font-size: clamp(26px, 8vw, 48px);
  line-height: 1;
  word-break: break-all;
}

.hero-strip .route {
  color: #304037;
  font-size: 13px;
}

.hero-stat {
  min-width: 92px;
  padding: 10px;
  border-left: 2px solid rgba(22,32,28,.25);
  text-align: right;
}

.hero-stat strong,
.hero-stat span { display: block; }
.hero-stat strong { font-size: 36px; line-height: 1; }
.hero-stat span { font-size: 14px; }

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
  margin-top: 20px;
}

.side-nav {
  position: sticky;
  top: 74px;
  align-self: start;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.side-nav button {
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  font-weight: 800;
}

.side-nav button.active {
  border-color: var(--ink);
  color: #fff;
  background: var(--deep);
}

.side-nav .nav-logout {
  margin-top: 10px;
  border-color: rgba(220, 63, 46, .55);
  color: var(--red);
  background: #fff;
}

.main-stack {
  position: relative;
  display: grid;
  gap: 12px;
  min-width: 0;
  align-content: start;
}

.main-stack > [data-message] {
  position: fixed;
  top: 72px;
  right: 18px;
  z-index: 5;
  max-width: min(420px, calc(100vw - 36px));
  min-height: 0;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(220, 63, 46, .25);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 10px 24px rgba(22, 32, 28, .16);
}

.main-stack > [data-message]:empty {
  display: none;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title h2 {
  margin: 2px 0 0;
  font-size: 19px;
  line-height: 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: min(460px, 100%);
}

.toolbar input {
  height: 38px;
  min-height: 38px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid #cfc6b4;
  border-radius: 8px;
  background: #fff;
}

.toolbar .ghost-btn {
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.quick-grid div {
  min-height: 74px;
  padding: 10px;
  border: 1px solid #cfc6b4;
  border-radius: 8px;
  background: #fff;
}

.quick-grid small,
.quick-grid strong { display: block; }
.quick-grid small { color: #64736d; font-size: 12px; }
.quick-grid strong { margin-top: 5px; font-size: 22px; word-break: break-word; }

.admin-quick-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.overview-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.overview-metrics div {
  min-height: 86px;
  padding: 10px;
  border: 1px solid #cfc6b4;
  border-radius: 8px;
  background: #fff;
}

.overview-metrics small,
.overview-metrics strong,
.overview-metrics span {
  display: block;
}

.overview-metrics small {
  color: #64736d;
  font-size: 12px;
  font-weight: 800;
}

.overview-metrics strong {
  margin-top: 5px;
  font-size: 22px;
  line-height: 28px;
  word-break: break-word;
}

.overview-metrics strong span {
  display: inline;
}

.overview-metrics > div > span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.chart-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid #cfc6b4;
  border-radius: 8px;
  background: #fff;
}

.chart-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 22px;
}

.chart-card-wide {
  grid-column: 1 / -1;
}

.bar-chart {
  display: grid;
  gap: 9px;
}

.bar-row {
  display: grid;
  grid-template-columns: 76px 1fr 44px;
  gap: 8px;
  align-items: center;
  min-height: 28px;
}

.bar-label,
.bar-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.bar-value {
  color: var(--ink);
  text-align: right;
}

.bar-track {
  display: block;
  height: 14px;
  overflow: hidden;
  border: 1px solid rgba(22, 32, 28, .18);
  border-radius: 8px;
  background: #f4efe4;
}

.bar-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 8px;
  background: var(--deep);
}

.bar-fill.warn { background: var(--gold); }
.bar-fill.red { background: var(--red); }
.bar-fill.green { background: var(--green); }

.recent-list {
  display: grid;
  gap: 8px;
}

.recent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 50px;
  padding: 8px 10px;
  border: 1px solid #eee6d8;
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf8;
  text-align: left;
}

.recent-item b,
.recent-item small,
.recent-item i,
.recent-item em {
  display: block;
}

.recent-item small {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-item i {
  min-width: 58px;
  color: var(--deep);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-align: right;
}

.recent-item em {
  margin-top: 3px;
  color: var(--red);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-align: right;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.scan-video {
  width: min(420px, 100%);
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions .ghost-btn,
.row-actions .primary-btn {
  min-height: 34px;
  padding: 0 9px;
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 32, 28, .42);
}

.modal {
  width: min(860px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  overflow: auto;
  padding: 16px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #eee6d8;
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  padding: 10px 9px;
  border-bottom: 1px solid #eee6d8;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: #f8f4eb;
  font-weight: 900;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 8px;
  color: var(--deep);
  background: #e7f1ec;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.money {
  color: var(--red);
  font-weight: 900;
  white-space: nowrap;
}

.hidden { display: none !important; }

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.notice {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

@media (max-width: 860px) {
  .login-page { display: block; padding: 12px; }
  .login-shell { grid-template-columns: 1fr; }
  .brand-panel {
    min-height: 280px;
    padding: 20px;
    box-shadow: 5px 5px 0 var(--ink);
  }
  .summary { font-size: 14px; }
  .layout { grid-template-columns: 1fr; }
  .side-nav {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .quick-grid,
  .admin-quick-grid,
  .overview-metrics,
  .form-grid,
  .charts-grid,
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .quick-grid,
  .admin-quick-grid,
  .overview-metrics,
  .form-grid,
  .charts-grid,
  .detail-grid,
  .side-nav { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr; }
  .hero-strip {
    align-items: stretch;
    flex-direction: column;
  }
  .hero-stat {
    min-width: 0;
    border-top: 2px solid rgba(22,32,28,.25);
    border-left: 0;
    text-align: left;
  }

  .recent-item {
    grid-template-columns: 1fr;
  }

  .recent-item i,
  .recent-item em {
    text-align: left;
  }

  html[data-entry-role="user"] .workbench {
    padding: 10px 12px 64px;
  }

  html[data-entry-role="user"] .hero-strip {
    gap: 10px;
    min-height: 0;
    padding: 14px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  html[data-entry-role="user"] .hero-strip h1 {
    font-size: 34px;
  }

  html[data-entry-role="user"] .hero-strip .route {
    font-size: 12px;
    line-height: 1.45;
  }

  html[data-entry-role="user"] .hero-stat {
    padding: 8px 0 0;
  }

  html[data-entry-role="user"] .hero-stat strong {
    font-size: 30px;
  }

  html[data-entry-role="user"] .layout {
    gap: 10px;
    margin-top: 14px;
  }

  html[data-entry-role="user"] .side-nav {
    position: sticky;
    top: 60px;
    z-index: 12;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
    box-shadow: 0 8px 18px rgba(22, 32, 28, .08);
  }

  html[data-entry-role="user"] .side-nav button {
    min-height: 42px;
    padding: 0 8px;
    text-align: center;
  }

  html[data-entry-role="user"] .side-nav .nav-logout {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  html[data-entry-role="user"] .panel {
    padding: 12px;
  }

  html[data-entry-role="user"] .panel-title {
    margin-bottom: 10px;
  }

  html[data-entry-role="user"] .field textarea {
    min-height: 92px;
  }

  html[data-entry-role="user"] .action-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  html[data-entry-role="user"] .action-row .primary-btn,
  html[data-entry-role="user"] .action-row .ghost-btn {
    width: 100%;
    min-width: 0;
    padding: 0 6px;
  }

  html[data-entry-role="user"] .notice {
    margin-top: 10px;
    font-size: 12px;
  }

  html[data-entry-role="user"] .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  html[data-entry-role="user"] table,
  html[data-entry-role="user"] tbody,
  html[data-entry-role="user"] tr,
  html[data-entry-role="user"] td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  html[data-entry-role="user"] thead {
    display: none;
  }

  html[data-entry-role="user"] tbody tr {
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #eee6d8;
    border-radius: 8px;
    background: #fff;
  }

  html[data-entry-role="user"] tbody td {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid #f0e8d8;
  }

  html[data-entry-role="user"] tbody td:last-child {
    border-bottom: 0;
  }

  html[data-entry-role="user"] tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
  }

  html[data-entry-role="user"] tbody td[colspan] {
    display: block;
  }

  html[data-entry-role="user"] tbody td[colspan]::before {
    content: "";
  }
}

@media print {
  .mobile-topbar,
  .hero-strip,
  .side-nav,
  .toolbar,
  .action-row,
  .no-print { display: none !important; }
  body, .app-shell, .workbench { background: #fff; padding: 0; }
  .layout { display: block; margin: 0; }
  .panel { border: 0; }
}
