/* RR Budget — compact office tool. Warm white, navy accents, fine gray rules. */

:root {
  --bg: #faf9f7;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #66707a;
  --line: #d9d6d0;
  --line-soft: #e8e6e1;
  --navy: #1f3a5f;
  --navy-soft: #eef2f7;
  --accent: #2b5d8c;
  --danger: #a03232;
  --danger-soft: #f7ecec;
  --free: #3d6b4f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

.num, .grid td, .mini-table td {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; }

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

h1 { font-size: 18px; margin: 0 0 4px; }
h2 { font-size: 14px; margin: 0 0 8px; }
h3 { font-size: 13px; margin: 0 0 6px; }

.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.strong { font-weight: 600; }

/* Top bar */
.topbar {
  background: var(--navy);
  color: #fff;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 42px;
}
.brand {
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: 4px; }
.tab {
  color: #cfd9e4;
  padding: 4px 10px;
  border-radius: 4px;
}
.tab:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,0.08); }
.tab.is-active { color: #fff; background: rgba(255,255,255,0.16); font-weight: 600; }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Menus (native details/summary, no JS) */
.menu { position: relative; }
.menu > summary {
  cursor: pointer;
  list-style: none;
  color: #e6ecf3;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.25);
  user-select: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: rgba(255,255,255,0.14); }
.menu-body {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(28, 39, 51, 0.12);
  min-width: 160px;
  padding: 8px;
  z-index: 30;
}
.menu-note {
  color: var(--muted);
  font-size: 12px;
  padding: 2px 4px 8px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 8px;
}
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li { padding: 3px 4px; }

/* Buttons and forms */
.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { padding: 2px 8px; font-size: 12px; }

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  max-width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus, summary:focus {
  outline: 2px solid rgba(43, 93, 140, 0.45);
  outline-offset: 1px;
}
label { display: block; margin: 6px 0 2px; }

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.inline-form label { margin: 0; }
.stack-form label { margin: 8px 0 2px; }
.hint {
  color: var(--muted);
  font-size: 11.5px;
  margin: 6px 0 0;
  max-width: 60ch;
}

/* Page scaffolding */
.page { padding: 14px 16px 40px; max-width: 1500px; margin: 0 auto; }
.page-head { margin-bottom: 10px; }
.badge {
  display: inline-block;
  font-size: 11px;
  border-radius: 10px;
  padding: 1px 8px;
  background: var(--navy-soft);
  color: var(--navy);
  vertical-align: 2px;
}
.badge-muted { background: var(--line-soft); color: var(--muted); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.messages { padding: 8px 16px 0; }
.message {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--panel);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 6px;
}
.message-error { border-left-color: var(--danger); color: var(--danger); }
.message-warn { border-left-color: #b97f24; color: #7a5417; }
.message-success { border-left-color: var(--free); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.list { list-style: none; padding: 0; }
.list li { margin-bottom: 8px; }

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
}
.table th, .table td {
  border: 1px solid var(--line-soft);
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}
.table thead th {
  background: var(--navy-soft);
  color: var(--navy);
  font-weight: 600;
}
.years-table td .btn { margin-left: 6px; }

/* Budget grid */
.grid-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.subtabs { display: flex; gap: 2px; margin-top: 6px; }
.subtab {
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-bottom: none;
  background: var(--line-soft);
  color: var(--muted);
  border-radius: 5px 5px 0 0;
  font-size: 12.5px;
}
.subtab.is-active { background: var(--panel); color: var(--navy); font-weight: 600; }
.subtab.is-disabled { opacity: 0.55; cursor: not-allowed; }

.grid-stats { display: flex; align-items: center; gap: 14px; }
.stat { display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-size: 11px; }
.stat-value { font-weight: 700; font-size: 15px; color: var(--navy); }
.stat-value.warn { color: var(--danger); }

.grid-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  align-items: start;
}

.grid-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  max-height: calc(100vh - 160px);
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1180px;
  width: 100%;
}
.grid th, .grid td {
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  padding: 3px 7px;
  text-align: right;
  white-space: nowrap;
}
.grid thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--navy-soft);
  color: var(--navy);
  font-weight: 600;
  text-align: right;
}
.grid thead th.head-article, .grid thead th.head-annual { text-align: left; }
.sticky-col {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--panel);
  text-align: left !important;
  min-width: 230px;
  max-width: 320px;
  white-space: normal;
}
.grid thead th.sticky-col { z-index: 15; }
.grid tfoot th, .grid tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--navy-soft);
  font-weight: 700;
  z-index: 10;
}
.grid tfoot .sticky-col { z-index: 20; }

.cat-row th, .cat-row td { background: var(--navy-soft); }
.cat-row .sticky-col { background: var(--navy-soft); }
.cat-row td, .cat-row th { border-bottom: 1px solid var(--line); }
.cat-name { font-weight: 600; }
.cat-code {
  display: inline-block;
  color: var(--muted);
  font-weight: 500;
  margin-right: 4px;
}
.cat-planned { font-weight: 700; color: var(--navy); }
.cat-sub { font-size: 11px; color: var(--muted); }
.cat-sub.free { color: var(--free); }
.cat-sub.over { color: var(--danger); font-weight: 600; }

.line-row .cell { cursor: default; }
.line-name { font-weight: 400; }
.line-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.line-btn:hover { color: var(--accent); }
.cell.is-canceled .amt {
  color: var(--danger);
  text-decoration: line-through;
}
.cell.is-empty { color: #b6bcc2; }
.cell .amt { display: inline-block; min-width: 64px; }
.cell-editor {
  width: 88px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding: 1px 4px;
}
tbody.cat-group.collapsed tr.line-row { display: none; }

.collapse-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px 0 0;
  font-size: 10px;
}
.collapse-btn[aria-expanded="false"] { transform: rotate(-90deg); }

.add-line { display: block; margin-top: 4px; }
.add-line > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 11.5px;
  user-select: none;
}
.add-line form {
  margin-top: 6px;
  display: grid;
  gap: 4px;
  min-width: 220px;
}
.add-line input { width: 100%; }

/* Side panel */
.side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  position: sticky;
  top: 8px;
  max-height: calc(100vh - 60px);
  overflow: auto;
}
.side-placeholder .muted { margin-top: 4px; }
.panel-head h2 { margin-bottom: 2px; }
#panel-close { float: right; }

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.mini-table th, .mini-table td {
  border-bottom: 1px solid var(--line-soft);
  padding: 4px 6px;
  text-align: left;
}
.mini-table form { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.mini-table input[type="text"] { width: 130px; }

.history { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.history li { padding: 3px 0; border-bottom: 1px dashed var(--line-soft); }

.app-error {
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 8px;
}

/* Documents */
.doc-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.mail-state { border-top: 1px dashed var(--line); padding-top: 6px; }
.docs-table { margin-top: 6px; }

.doc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 1fr);
  gap: 12px;
  align-items: start;
}
.pdf-preview {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  margin-top: 8px;
}
.meta-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.meta-list li { padding: 3px 0; border-bottom: 1px dashed var(--line-soft); }
.next-stage { border-style: dashed; }

/* Login */
.login-card {
  max-width: 380px;
  margin: 8vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px 24px 26px;
}
.login-card h1 { color: var(--navy); margin-bottom: 4px; }
.login-card button { margin-top: 14px; width: 100%; }

/* Narrow screens: keep the table usable by horizontal scroll */
@media (max-width: 980px) {
  .grid-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .doc-layout { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 6px 12px; }
  .topbar-right { margin-left: 0; }
}

.category-settings { font-weight: normal; font-size: 12px; margin-top: 6px; }
.category-settings summary { color: var(--navy); cursor: pointer; }
.category-settings form { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.category-settings label { display: grid; gap: 3px; }
td.cell:focus { outline: 2px solid var(--navy); outline-offset: -2px; }

.topbar-right > .btn-ghost { color: #fff; border-color: #899bb4; }
