:root {
  --navy: #1f3a5f;
  --navy-2: #2c5282;
  --navy-soft: #e8eef6;
  --ink: #1a2230;
  --muted: #5d6b7e;
  --line: #d5dde8;
  --bg: #f3f5f9;
  --card: #ffffff;
  --good: #1e7a4c;
  --good-bg: #e3f4ea;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --focus: #3b82f6;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.4; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #aab7c9; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.icon { padding: 4px 10px; font-size: 18px; line-height: 1; }
.link { border: 0; background: none; padding: 0; color: var(--navy-2); cursor: pointer; text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.brand-mark {
  display: inline-block; width: 26px; height: 26px; border-radius: 7px; background: var(--navy);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 22V14M14 22V9M20 22V17M26 22V12' stroke='white' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover; flex: none;
}

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px;
  width: min(380px, 100%); display: grid; gap: 14px; box-shadow: 0 10px 30px rgba(20, 40, 70, .08);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
.login-card input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-weight: 400; }
.login-card .btn { padding: 10px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.field select, .date-nav input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.date-nav { display: flex; gap: 4px; align-items: center; }
.user { color: var(--muted); }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(20, 40, 70, .14); padding: 4px; min-width: 240px; z-index: 20;
}
.menu-list button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px;
  border-radius: 7px; cursor: pointer;
}
.menu-list button:hover { background: var(--navy-soft); }

.statusbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 0; max-width: 1240px; margin: 0 auto; }
.pill { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; background: var(--navy-soft); color: var(--navy); }
.pill.ok { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.subtle { background: transparent; color: var(--muted); }
.pill:empty { display: none; }

/* ---------- report ---------- */
.page { padding: 12px 16px 40px; }
.report {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  max-width: 1240px; margin: 0 auto; padding: 24px;
}
.report h1 { margin: 0 0 2px; font-size: 21px; }
.report .subtitle { margin: 0 0 18px; color: var(--muted); }
.report h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--navy);
  margin: 26px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--navy-soft);
}
.report section:first-of-type h2 { margin-top: 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

.table-wrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td { border: 1px solid var(--line); padding: 6px 9px; text-align: center; }
.grid td { white-space: nowrap; }
.grid td.outcome { white-space: normal; }
.grid thead th { background: var(--navy); color: #fff; font-weight: 600; font-size: 12.5px; border-color: #35557e; }
.grid thead tr.sub th { background: var(--navy-2); font-weight: 500; font-size: 11.5px; }
.grid thead th.title { background: #16304f; font-size: 13px; }
.grid tbody th { text-align: left; font-weight: 600; background: #f7f9fc; white-space: nowrap; }
.grid tfoot td, .grid tfoot th { background: var(--navy-soft); font-weight: 700; }
.grid tfoot th { text-align: left; }
.grid td.num { text-align: right; }
.grid td.empty { color: #a7b2c1; }
.grid td.input-cell { padding: 0; background: #fffdf3; }
.grid .outcome { text-align: left; }
.grid.compact th, .grid.compact td { padding: 5px 6px; font-size: 12.5px; }
.grid.compact tbody th { font-size: 12px; }
.grid.compact thead th { white-space: nowrap; }
.ahead { color: var(--good); font-weight: 600; }
.behind { color: var(--bad); font-weight: 600; }

.cell-input {
  width: 100%; min-width: 64px; border: 0; background: transparent; padding: 6px 9px; text-align: center;
  -moz-appearance: textfield;
}
.cell-input::-webkit-outer-spin-button, .cell-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell-input:hover { background: #fff6cc; }
.cell-input:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: #fff; }
.cell-input.carried { color: var(--muted); font-style: italic; }
.cell-print { display: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }

.commentary textarea {
  width: 100%; min-height: 110px; resize: vertical; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; line-height: 1.5; background: #fffdf3;
}
.commentary textarea:focus { background: #fff; }
.commentary .print-text { display: none; white-space: pre-wrap; line-height: 1.5; margin: 0; }

.empty-state { text-align: center; padding: 30px 10px; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; }

/* Export / print mode: inputs become plain text, fixed width for a consistent image */
.report.exporting { width: 1240px; max-width: none; border: 0; border-radius: 0; }
.report.exporting .cell-input, .report.exporting .hint, .report.exporting textarea, .report.exporting .no-export { display: none; }
.report.exporting .cell-print { display: inline; }
.report.exporting .print-text { display: block; }
.report.exporting td.input-cell { background: transparent; padding: 6px 9px; }
.report.exporting .cards { grid-template-columns: repeat(3, 1fr); }
.report.exporting.summary-only .full-only { display: none; }

/* ---------- campaign dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(860px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(15, 25, 40, .4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
dialog h2 { margin: 0; font-size: 18px; }
dialog h3 { font-size: 14px; margin: 18px 0 8px; }
table.settings { border-collapse: collapse; width: 100%; }
.settings th, .settings td { padding: 5px; text-align: left; border-bottom: 1px solid var(--line); }
.settings th { font-size: 12px; color: var(--muted); font-weight: 600; }
.settings input[type=text], .settings input[type=number], .add-row input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px;
}
.settings input[type=number] { width: 70px; }
.add-row { display: grid; grid-template-columns: 1fr 1.6fr 1.6fr 80px auto; gap: 6px; }

@media (max-width: 720px) {
  .report { padding: 16px 12px; }
  .topbar { padding: 10px 12px; }
  .controls { width: 100%; }
  .user { margin-left: auto; }
  .add-row { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; }
  .topbar, .statusbar, dialog { display: none !important; }
  .page { padding: 0; }
  .report { border: 0; padding: 0; max-width: none; }
  .cell-input, .hint, textarea, .no-export { display: none !important; }
  .cell-print { display: inline !important; }
  .print-text { display: block !important; }
  .grid td.input-cell { background: transparent; padding: 6px 9px; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  section { break-inside: avoid; }
  .grid thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .grid tfoot td, .grid tfoot th, .grid tbody th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
