
:root {
  --bg: #f6f5f0;
  --panel: #ffffff;
  --ink: #202323;
  --muted: #66706c;
  --line: #dedbd0;
  --blue: #2f6f9f;
  --blue-dark: #1f4f73;
  --green: #407a58;
  --gold: #a66f22;
  --rose: #a94d4d;
  --soft-blue: #dfeef7;
  --soft-green: #e4f0e8;
  --soft-gold: #f5ead7;
  --soft-rose: #f4e2df;
  --shadow: 0 16px 35px rgba(42, 40, 33, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "YuGothic", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
}

a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 68px;
  padding: 12px 32px;
  background: rgba(255, 255, 255, 0.93);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: #fff;
  background: var(--blue-dark);
  border-radius: 7px;
  font-weight: 900;
}

nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 650;
  font-size: 14px;
}

nav a.active, nav a:hover {
  color: var(--ink);
  background: #ece8dc;
  text-decoration: none;
}

.logout-form { margin: 0; }
.nav-button {
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
.nav-button:hover {
  color: var(--ink);
  background: #ece8dc;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f6f5f0 0%, #e9efe8 100%);
}
.login-shell {
  width: min(100% - 28px, 500px);
  padding: 24px 0;
}
.login-panel {
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-brand { margin-bottom: 20px; }

main {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 32px 36px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  margin: 12px 0 22px;
}

.compact-head { margin-top: 6px; }
.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  font-size: 34px;
  line-height: 1.2;
  letter-spacing: 0;
}
h2 {
  margin-bottom: 14px;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}
.lead {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { text-decoration: none; border-color: #bcb7a8; }
.button.primary {
  color: #fff;
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}
.button.ghost { background: transparent; }
.button.large { min-height: 44px; padding-inline: 18px; }
.button.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.button.danger { color: var(--rose); }

.notice {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid #d7ccb0;
  border-left: 5px solid var(--gold);
  background: #fff8ea;
  border-radius: 7px;
  color: #6c4a18;
}
.notice.success {
  border-color: #c8dccf;
  border-left-color: var(--green);
  background: #f2fbf4;
  color: #27553a;
}
.notice.danger {
  border-color: #e5c2bf;
  border-left-color: var(--rose);
  background: #fff1f0;
  color: #7c3333;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 22px;
}
.metric-card {
  min-height: 126px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric-card.ink { border-top: 5px solid var(--blue-dark); }
.metric-card.green { border-top: 5px solid var(--green); }
.metric-card.gold { border-top: 5px solid var(--gold); }
.metric-card.rose { border-top: 5px solid var(--rose); }
.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.metric-value {
  margin: 9px 0 3px;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 850;
}
.metric-value.small-value { font-size: 20px; }
.metric-sub {
  color: var(--muted);
  font-size: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.panel {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel.wide { grid-column: 1 / -1; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; }
.subtle, .muted {
  color: var(--muted);
  font-size: 12px;
}
.text-link { font-size: 13px; font-weight: 750; }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr)) auto auto;
  gap: 10px;
  align-items: end;
  margin: 18px 0;
  padding: 14px;
  background: #ebe7dc;
  border: 1px solid #d7d1c1;
  border-radius: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #cfcabd;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.field textarea { min-height: 82px; resize: vertical; }
.field.wide { grid-column: 1 / -1; }
.field.compact input, .field.compact select { min-height: 36px; }

.month-chart {
  display: flex;
  align-items: end;
  gap: 8px;
  min-height: 250px;
  padding: 18px 4px 4px;
  border-bottom: 1px solid var(--line);
}
.month-col {
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: end;
  justify-items: center;
  flex: 1;
  min-width: 28px;
  height: 250px;
}
.month-bar {
  width: min(34px, 75%);
  background: var(--blue-dark);
  border-radius: 6px 6px 0 0;
}
.month-label {
  min-height: 20px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.bar-row { margin: 14px 0; }
.bar-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 13px;
}
.bar-top strong { white-space: nowrap; }
.bar-track {
  height: 11px;
  background: #eee9dc;
  border-radius: 999px;
  overflow: hidden;
}
.bar-track span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: inherit;
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.spec-grid div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  min-height: 42px;
  border-bottom: 1px solid #ece8de;
}
.spec-grid div:nth-last-child(-n+2) { border-bottom: 0; }
.spec-grid dt,
.spec-grid dd {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
}
.spec-grid dt {
  color: var(--muted);
  background: #faf8f1;
  font-weight: 850;
}
.spec-grid dd {
  overflow-wrap: anywhere;
  border-left: 1px solid #ece8de;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid #ece8de;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}
th {
  color: var(--muted);
  background: #faf8f1;
  font-size: 12px;
  font-weight: 850;
}
tr:last-child td { border-bottom: 0; }
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.pill.high, .pill.danger { color: #7e2f2f; background: var(--soft-rose); }
.pill.medium { color: #714b17; background: var(--soft-gold); }
.pill.low { color: #2f5a40; background: var(--soft-green); }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}
.upload-panel { min-height: 252px; }
.drop-zone {
  display: grid;
  place-items: center;
  min-height: 130px;
  margin: 12px 0;
  padding: 20px;
  color: var(--muted);
  border: 2px dashed #c9c0ad;
  border-radius: 8px;
  background: #fbfaf5;
  text-align: center;
}
.drop-zone input { max-width: 100%; }
.plain-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}
.plain-list li + li { margin-top: 8px; }
.steps {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}
.steps li + li { margin-top: 8px; }
.sheet-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}
.sheet-form textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.sync-panel { margin-bottom: 18px; }
.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.sync-actions form { margin: 0; }

.review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr);
  gap: 16px;
  align-items: start;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid.single { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.actions, .table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
.raw-panel { position: sticky; top: 88px; }
.doc-meta {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}
.doc-meta div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
}
.doc-meta dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.doc-meta dd { margin: 0; font-size: 13px; }
.ocr-candidates {
  border: 1px solid var(--line);
  border-radius: 7px;
  margin: 12px 0;
  padding: 12px;
  background: #fffdf7;
}
.ocr-candidates .panel-head { margin-bottom: 10px; }
.compact-table table { font-size: 12px; }
.compact-table th,
.compact-table td { padding: 8px 9px; }
.muted-text {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 0;
}
.raw-text {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfaf5;
  color: #343635;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.row-actions form { margin: 0; }
.inline-form { margin: 0 0 12px; }

@media (max-width: 1040px) {
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split, .review-layout { grid-template-columns: 1fr; }
  .raw-panel { position: static; }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }
  nav { justify-content: flex-start; }
  main { width: min(100% - 20px, 1240px); padding-top: 18px; }
  .page-head { flex-direction: column; }
  h1 { font-size: 26px; }
  .metrics-grid, .dashboard-grid, .filter-bar, .form-grid, .form-grid.single {
    grid-template-columns: 1fr;
  }
  .spec-grid { grid-template-columns: 1fr; }
  .spec-grid div { border-bottom: 1px solid #ece8de; }
  .spec-grid div:last-child { border-bottom: 0; }
  .metric-card { min-height: auto; }
  .month-chart { min-height: 210px; }
  .month-col { height: 210px; }
  footer { flex-direction: column; padding-inline: 16px; }
}
