:root {
  --ink: #172326;
  --muted: #6b787a;
  --line: #dce4e4;
  --paper: #f5f7f5;
  --card: #ffffff;
  --teal: #315c65;
  --teal-dark: #23474e;
  --mint: #dfeee9;
  --amber: #a76017;
  --amber-bg: #fff1d8;
  --red: #b53a34;
  --red-bg: #fbe8e6;
  --green: #246344;
  --green-bg: #e4f2ea;
  --blue: #315d9b;
  --blue-bg: #e8f0fb;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-size: 15px; line-height: 1.55; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { background: #eef1ef; padding: 2px 5px; border-radius: 5px; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, #c7ded7 0, transparent 36%),
    radial-gradient(circle at 95% 90%, #d8e3ee 0, transparent 32%),
    #edf2ef;
}
.login-card {
  width: min(100%, 430px);
  background: var(--card);
  padding: 34px;
  border-radius: 24px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(35, 71, 78, .12);
}
.login-card h1 { margin: 6px 0 4px; font-size: 28px; letter-spacing: -.5px; }
.login-card form { margin-top: 24px; display: grid; gap: 16px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
.login-card input { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfb; }
.login-card input:focus { outline: 3px solid #dbe9e5; border-color: var(--teal); }
.brand-mark {
  width: 54px; height: 54px; display: grid; place-items: center;
  background: var(--teal); color: white; border-radius: 16px; font-size: 25px; font-weight: 800;
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 18px; }
.eyebrow { margin: 18px 0 0; color: var(--teal); font-weight: 700; font-size: 12px; letter-spacing: .8px; text-transform: uppercase; }
.login-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; }
.form-error { color: var(--red); font-size: 13px; min-height: 20px; margin: -4px 0 0; }

.app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  padding: 13px 22px; background: rgba(250, 252, 250, .96);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.brand-row { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-row h1 { font-size: 17px; margin: 0; }
.brand-row p { margin: 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.site-picker { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.site-picker select { padding: 8px 28px 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: white; }
.user-chip { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.role { font-size: 11px; font-weight: 700; color: var(--teal); background: var(--mint); border-radius: 20px; padding: 2px 8px; }
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 10px 22px;
  background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 65px; z-index: 25;
}
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 8px 13px; border-radius: 9px; white-space: nowrap; font-weight: 650; }
.tabs button.active { background: var(--teal); color: white; }
main { max-width: 1420px; margin: 0 auto; padding: 22px; }
.loading, .empty { color: var(--muted); padding: 26px; text-align: center; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 3px 0 17px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 25px; letter-spacing: -.4px; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.analysis-subnav {
  position: sticky; top: 112px; z-index: 22;
  display: flex; gap: 5px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 7px; margin: 0 0 14px; background: rgba(250, 252, 250, .97);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 5px 16px rgba(35, 71, 78, .07); backdrop-filter: blur(10px);
}
.analysis-subnav a {
  flex: 0 0 auto; color: var(--muted); text-decoration: none; white-space: nowrap;
  padding: 6px 11px; border-radius: 8px; font-size: 12px; font-weight: 650;
}
.analysis-subnav a.active, .analysis-subnav a:hover { color: white; background: var(--teal); }
.analysis-target { scroll-margin-top: 174px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card, .panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-card { padding: 16px; }
.stat-card .label { font-size: 12px; color: var(--muted); }
.stat-card .value { margin-top: 5px; font-size: 25px; font-weight: 800; letter-spacing: -.5px; }
.stat-card .note { font-size: 11px; color: var(--muted); margin-top: 2px; }
.panel { padding: 16px; margin-bottom: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 13px; }
.filters label, .field label { display: grid; gap: 4px; font-size: 12px; font-weight: 650; color: var(--muted); }
.filters input, .filters select, .field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; background: white; min-height: 40px;
}
.filters input { min-width: 220px; }
.field textarea { min-height: 80px; resize: vertical; }
.checkbox-label { display: flex !important; align-items: center; gap: 7px; }
.checkbox-label input { min-height: auto; }

button.primary, button.secondary, button.ghost, button.danger, button.warn {
  border-radius: 9px; min-height: 38px; padding: 8px 13px; font-weight: 700; border: 1px solid transparent;
}
button.primary { background: var(--teal); color: white; }
button.primary:hover { background: var(--teal-dark); }
button.secondary { background: var(--mint); color: var(--teal-dark); border-color: #c8ded7; }
button.ghost { background: white; color: var(--ink); border-color: var(--line); }
button.danger { background: var(--red-bg); color: var(--red); border-color: #efcfcb; }
button.warn { background: var(--amber-bg); color: var(--amber); border-color: #efdbad; }
button.compact { min-height: 32px; padding: 5px 10px; font-size: 12px; }
button.wide { width: 100%; min-height: 44px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.icon-button { border: 0; background: transparent; font-size: 24px; color: var(--muted); padding: 0 4px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; color: var(--muted); background: #f8faf8; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #edf1ef; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fbfcfb; }
.nowrap { white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.tag { display: inline-block; border-radius: 20px; padding: 2px 8px; font-size: 11px; font-weight: 700; background: #edf1ef; color: var(--muted); white-space: nowrap; }
.tag.good { color: var(--green); background: var(--green-bg); }
.tag.warn { color: var(--amber); background: var(--amber-bg); }
.tag.bad { color: var(--red); background: var(--red-bg); }
.tag.info { color: var(--blue); background: var(--blue-bg); }
.tag.deleted { color: var(--red); background: var(--red-bg); }
.row-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.row-actions button { border: 1px solid var(--line); background: white; border-radius: 7px; padding: 4px 7px; font-size: 12px; }
.row-actions button.void { color: var(--red); border-color: #efcfcb; }
.row-actions button.restore { color: var(--green); border-color: #cbe4d5; }

.site-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.site-box { border: 1px solid var(--line); border-radius: 12px; padding: 13px; background: #fbfcfb; }
.site-box strong { display: block; font-size: 14px; }
.site-box span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.activity { display: grid; gap: 8px; }
.activity-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 12px; }
.activity-row:last-child { border-bottom: 0; }
.activity-time { color: var(--muted); min-width: 120px; font-variant-numeric: tabular-nums; }

.banner { border-radius: 12px; padding: 11px 13px; margin-bottom: 14px; font-size: 13px; background: var(--blue-bg); color: var(--blue); border: 1px solid #d6e2f4; }
.banner.green { color: var(--green); background: var(--green-bg); border-color: #cde5d7; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.detail-item { background: #f8faf8; border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-width: 0; }
.detail-item .k { font-size: 11px; color: var(--muted); }
.detail-item .v { margin-top: 3px; font-size: 13px; font-weight: 650; word-break: break-word; }
.detail-section { margin-top: 17px; }
.detail-section h3 { margin: 0 0 8px; font-size: 14px; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 7px; }
.attachment-list a { display: inline-block; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--teal); text-decoration: none; font-size: 12px; background: white; }
.upload-row { display: flex; gap: 8px; align-items: center; margin-top: 9px; flex-wrap: wrap; }
.upload-row input { max-width: 280px; }
.item-row {
  display: grid; grid-template-columns: 1.3fr .8fr .7fr .6fr .8fr auto;
  gap: 6px; align-items: center; border: 1px solid var(--line);
  border-radius: 9px; padding: 8px;
}
.item-row input, .item-row select {
  width: 100%; min-width: 0; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; background: white; min-height: 38px;
}

.modal {
  position: fixed; inset: 0; z-index: 80; display: flex; justify-content: flex-end;
  background: rgba(18, 28, 30, .46);
}
.modal-panel {
  width: min(100%, 660px); height: 100%; background: white; display: flex; flex-direction: column;
  box-shadow: -20px 0 50px rgba(0, 0, 0, .16); animation: slidein .18s ease-out;
}
@keyframes slidein { from { transform: translateX(25px); opacity: .7; } }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-actions { margin-top: auto; padding: 13px 20px calc(13px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: white; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field { display: grid; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.readonly-note { padding: 10px; background: #f7f9f7; border-radius: 9px; color: var(--muted); font-size: 12px; }
.toast {
  position: fixed; z-index: 120; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #1d292b; color: white; padding: 10px 16px;
  border-radius: 22px; box-shadow: 0 8px 28px rgba(0,0,0,.2); max-width: 88vw; text-align: center; font-size: 13px;
}
.toast.bad { background: var(--red); }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .topbar { position: static; display: grid; padding: 11px 13px; }
  .top-actions { justify-content: space-between; }
  .site-picker { flex: 1; }
  .site-picker select { flex: 1; width: 100%; }
  .tabs { top: 0; padding: 8px 10px; }
  .tabs button { padding: 8px 11px; }
  main { padding: 14px 11px 34px; }
  .analysis-subnav { top: 58px; margin-bottom: 11px; padding: 5px; }
  .analysis-subnav a { padding: 7px 10px; }
  .analysis-target { scroll-margin-top: 116px; }
  .page-head h2 { font-size: 22px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 13px; }
  .stat-card .value { font-size: 21px; }
  .site-summary { grid-template-columns: 1fr; }
  .panel { padding: 12px; border-radius: 13px; }
  .filters input { min-width: 0; width: 100%; }
  .filters label { flex: 1 1 140px; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { border: 1px solid var(--line); border-radius: 11px; margin-bottom: 9px; padding: 3px 0; }
  .table-wrap td { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; border-bottom: 1px dashed var(--line); text-align: right; }
  .table-wrap td::before { content: attr(data-label); text-align: left; color: var(--muted); font-size: 11px; font-weight: 700; flex: 0 0 auto; }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td.row-actions { justify-content: flex-end; }
  .table-wrap td.row-actions::before { content: ""; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .modal { align-items: flex-end; }
  .modal-panel { height: 94vh; border-radius: 18px 18px 0 0; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row button { grid-column: 2; justify-self: end; }
  .login-card { padding: 26px 22px; }
}
