:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --border-strong: #cdd3da;
  --text: #161f2b;
  --muted: #61707f;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --up: #137333;
  --down: #c5221f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 4px 12px rgba(20, 30, 45, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre.code {
  font-family: Consolas, 'SF Mono', Menlo, monospace;
  font-size: 12.5px;
}

pre.code {
  background: #f1f3f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 10px;
}

/* Header */

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 600; font-size: 16px; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 13px; }

.topnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }

.topnav a {
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 500;
}

.topnav a:hover { background: var(--bg); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1480px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }

.login-wrap { max-width: 420px; margin: 48px auto; }

/* Panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 20px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-head h2 { margin: 0; }
.panel-note { color: var(--muted); font-size: 12px; }

/* Controls */

.controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end; }
.period-extra { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.date-hint { flex-basis: 100%; margin: 0; }
.trend-note { margin: 0 0 10px; }
.control { display: flex; flex-direction: column; gap: 6px; }

.control-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.inline-form { display: flex; align-items: center; gap: 8px; }

select,
input[type='text'],
input[type='password'],
input[type='number'],
input[type='date'] {
  font: inherit;
  color: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  min-width: 160px;
}

select:focus, input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

button, .button {
  font: inherit;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-block;
  text-align: center;
}

button:hover, .button:hover { filter: brightness(1.05); text-decoration: none; }

button.secondary, .button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}

button.danger { color: var(--down); border-color: #f5c4c1; background: #fff; }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
}

.segmented a {
  padding: 7px 14px;
  color: var(--muted);
  background: #fff;
  font-weight: 500;
  border-right: 1px solid var(--border);
}

.segmented a:last-child { border-right: none; }
.segmented a:hover { text-decoration: none; background: var(--bg); }
.segmented a.active { background: var(--accent-soft); color: var(--accent); }

.year-checks { display: flex; flex-wrap: wrap; gap: 10px; }

.year-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-weight: 500;
}

.year-check:hover { text-decoration: none; background: var(--bg); }
.year-check.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Year colours — match the chart lines */

.swatch, .cmp-bar, .legend-swatch { background: var(--y0, #1a73e8); }
.y0 { --sw: #1a73e8; }
.y1 { --sw: #e8710a; }
.y2 { --sw: #12805c; }
.y3 { --sw: #a142f4; }
.y4 { --sw: #d93025; }
.y5 { --sw: #5f6368; }
.swatch.y0, .cmp-bar.y0, .legend-swatch.y0 { background: #1a73e8; }
.swatch.y1, .cmp-bar.y1, .legend-swatch.y1 { background: #e8710a; }
.swatch.y2, .cmp-bar.y2, .legend-swatch.y2 { background: #12805c; }
.swatch.y3, .cmp-bar.y3, .legend-swatch.y3 { background: #a142f4; }
.swatch.y4, .cmp-bar.y4, .legend-swatch.y4 { background: #d93025; }
.swatch.y5, .cmp-bar.y5, .legend-swatch.y5 { background: #5f6368; }

.year-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 650;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.cmp-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 8px;
}

.cmp-bar {
  display: block;
  height: 6px;
  border-radius: 99px;
  min-width: 0;
  opacity: 0.92;
}

/* Tables */

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: top;
}

thead th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border-strong);
  background: #fafbfc;
}

.th-period {
  display: block;
  margin-top: 3px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

tbody tr:hover { background: #f7f8fa; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-value { font-size: 14px; font-weight: 550; font-variant-numeric: tabular-nums; }

th.year-current, td.year-current { background: #f3f8ff; }
td.year-current .cell-value { font-weight: 650; }
tbody tr:hover td.year-current { background: #e8f0fe; }

.table-months th,
.table-months td { padding: 8px 7px; }
.table-months tr.year-now td { background: #f3f8ff; }
.table-months tr.year-now .sticky-name { background: #f3f8ff; }
.table-months tbody tr.year-now:hover td,
.table-months tbody tr.year-now:hover .sticky-name { background: #e8f0fe; }
.table-months .cell-value { font-size: 13px; }
.table-months .sticky-name { min-width: 88px; max-width: 120px; }
.table-days th, .table-days td { padding: 8px 6px; }
.th-month a { color: inherit; text-decoration: none; }
.th-month a:hover { color: var(--accent); text-decoration: underline; }
.th-month.is-on a { color: var(--accent); font-weight: 700; }

tfoot td {
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
  border-bottom: none;
  background: #fafbfc;
}

.row-head { font-weight: 600; }
.row-sub { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.table-scroll { overflow: auto; margin: 0 -18px -18px; padding: 0 18px 4px; }
.month-scroll { margin: 16px -18px -18px; }

.sticky-name {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  box-shadow: 1px 0 0 var(--border);
  min-width: 168px;
  max-width: 260px;
  white-space: normal;
}

thead .sticky-name,
tfoot .sticky-name { background: #fafbfc; z-index: 2; }
tbody tr:hover .sticky-name { background: #f7f8fa; }
tr.year-now .sticky-name { background: #f3f8ff; }
tbody tr.year-now:hover .sticky-name { background: #e8f0fe; }

.table-years tr.group-start td { border-top: 1px solid var(--border-strong); }
.table-years tbody tr.group-start:first-child td { border-top: none; }
.table-years tr.year-now td { background: #f3f8ff; }
.table-years tr.year-now .sticky-name { background: #f3f8ff; }
.table-years tbody tr.year-now:hover td,
.table-years tbody tr.year-now:hover .sticky-name { background: #e8f0fe; }
.table-years tr.cmp-change td { padding-bottom: 16px; border-bottom: none; }
.table-years tfoot tr.year-now td { background: #eef4ff; }
.table-years tfoot .sticky-name { background: #fafbfc; }

.delta {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.35;
}
.delta.up { color: var(--up); background: #e6f4ea; }
.delta.down { color: var(--down); background: #fce8e6; }
.delta.flat { color: var(--muted); background: #f1f3f5; }

.year-group { border-left: 1px solid var(--border-strong); }

/* Cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-years {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.card-year-label { margin-bottom: 2px; }
.card-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.card-value.prev { font-size: 18px; font-weight: 550; color: #3c4a59; }
.card .cmp-bars { margin-top: 12px; }
.card .cmp-bar { height: 7px; }

/* Chart */

.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.legend-swatch { width: 18px; height: 3px; border-radius: 2px; }

/* Messages */

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; border: 1px solid; }
.banner.info { background: var(--accent-soft); border-color: #c6dafc; color: #174ea6; }
.banner.warn { background: #fef7e0; border-color: #fde293; color: #7c5b00; }
.banner.error { background: #fce8e6; border-color: #f5c4c1; color: #a50e0e; }
.banner.ok { background: #e6f4ea; border-color: #b7e1c1; color: #0d652d; }
.banner strong { display: block; margin-bottom: 4px; }
.banner a { color: inherit; text-decoration: underline; }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* Forms */

.settings-form { display: grid; gap: 18px; max-width: 620px; }
.field { display: grid; gap: 6px; }
.field-label { font-weight: 600; }
.field-hint { color: var(--muted); font-size: 12px; }
.field input { min-width: 0; width: 100%; }

.fx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.fx-row { display: flex; gap: 6px; }
.fx-row input:first-child { width: 72px; min-width: 0; }
.fx-row input:last-child { flex: 1; min-width: 0; }

.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Sync progress */

.progress { margin-top: 16px; }
.progress.hidden { display: none; }

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}
