:root {
  --bg: #0b1220;
  --paper: #101b2d;
  --paper-2: #14233a;
  --grid: #31506f;
  --grid-soft: #243c57;
  --text: #e7f1ff;
  --muted: #9fb4cc;
  --head: #17375d;
  --head-2: #0f2d4f;
  --accent: #20d3e8;
  --accent-dark: #0891b2;
  --accent-2: #8b5cf6;
  --danger: #fb7185;
  --good: #34d399;
  --warn: #fbbf24;
  --shadow: rgba(0, 0, 0, 0.34);
  --row-h: 27px;
  --font: Roboto, Arial, Helvetica, sans-serif;
  --field-font: Roboto, Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top left, #142850 0, #0b1220 38%, #07101d 100%);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}

button,
input,
select,
textarea {
  font-family: var(--field-font);
  font-size: 13px;
}

button,
select,
input[type="date"],
input[type="number"],
input[type="text"],
textarea {
  line-height: 20px;
  border: 1px solid #3b6388;
  border-radius: 4px;
  background: #0f1b2d;
  color: var(--text);
}

button {
  min-height: 25px;
  padding: 3px 8px;
  cursor: pointer;
  background: linear-gradient(#1d4167, #102844);
  color: #f3f9ff;
  border-color: #4376a7;
}

button:hover {
  border-color: var(--accent);
  background: linear-gradient(#215078, #12365c);
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 9px 10px 7px;
  border-bottom: 1px solid #41698e;
  background: linear-gradient(90deg, #10294a, #172c5c 48%, #172047);
  box-shadow: 0 1px 12px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #f4fbff;
  text-shadow: 0 1px 4px rgba(32, 211, 232, 0.25);
}

.topbar-controls,
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.field-inline input { height: 25px; line-height: 19px; padding: 2px 5px; }
.small-field input { width: 58px; }

.toolbar {
  padding: 6px 10px;
  border-bottom: 1px solid #345778;
  background: linear-gradient(90deg, #0e2139, #102e4c);
  position: sticky;
  top: 43px;
  z-index: 18;
}

.toolbar button {
  height: 25px;
  min-height: 25px;
  padding: 2px 7px;
}

.toolbar-sep {
  width: 1px;
  height: 22px;
  background: #426b91;
  margin: 0 2px;
}

.toolbar-picker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.toolbar-picker input[type="color"] {
  width: 28px;
  height: 23px;
  padding: 1px;
  background: #0f1b2d;
}

.selected-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.sheet-wrap {
  flex: 1;
  overflow: auto;
  padding: 10px;
}

.treasury-sheet {
  font-family: var(--font);
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--paper);
  min-width: 1180px;
  width: 100%;
  box-shadow: 0 2px 14px var(--shadow);
}

.treasury-sheet th,
.treasury-sheet td {
  border: 1px solid var(--grid);
  height: var(--row-h);
  min-height: var(--row-h);
  padding: 2px 5px;
  vertical-align: middle;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.treasury-sheet th {
  background: linear-gradient(#1a4d7d, #12365f);
  color: #eef9ff;
  font-weight: 700;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 5;
}

.col-date { width: 112px; }
.col-color { width: 10px; padding: 0 !important; }
.col-item { width: 245px; }
.col-amount { width: 112px; }
.col-running { width: 122px; }
.col-gap { width: 18px; background: var(--bg) !important; border-top-color: transparent !important; border-bottom-color: transparent !important; }
.col-tracker { width: 205px; }
.col-note { width: 190px; }
.col-note2 { width: 190px; }

.cell-editable {
  cursor: text;
  font-family: var(--field-font);
  font-size: 13px;
  line-height: calc(var(--row-h) - 6px);
  min-height: calc(var(--row-h) - 2px);
  vertical-align: middle;
  padding-top: 2px !important;
  padding-bottom: 2px !important;
  caret-color: var(--accent);
}

.cell-editable:empty::before {
  content: "\00a0";
  pointer-events: none;
}

.cell-editable:focus {
  outline: 2px solid #38bdf8;
  outline-offset: -2px;
  background: #12243b;
}

.cell-selected {
  outline: 2px solid #22d3ee !important;
  outline-offset: -2px;
}

.row-weekly-pay td {
  font-weight: 700;
  background: #123f39;
}

.row-net-total td {
  font-weight: 700;
  background: #172d54;
  border-top: 2px solid #5cc8ff;
}

.row-empty td {
  background: #101b2d;
}

.row-recurring td.col-item-name::after,
.row-recurring td.col-item::after {
  content: "↻";
  float: right;
  color: var(--accent);
  font-weight: 700;
}

.week-spacer td {
  background: transparent;
  height: 16px;
  border-left-color: transparent;
  border-right-color: transparent;
}

.date-past {
  text-decoration: line-through;
  color: #7488a1;
}

.amount-cell,
.running-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.amount-negative { color: #fb7185; }
.amount-positive { color: #34d399; }

.color-cell {
  padding: 0 !important;
  cursor: pointer;
  position: relative;
}

.color-swatch {
  display: block;
  width: 100%;
  height: 100%;
  min-height: calc(var(--row-h) - 2px);
  border: 0;
}

.color-cell:hover .color-swatch {
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: -2px;
}

.gap-cell {
  background: transparent !important;
  border-top-color: transparent !important;
  border-bottom-color: transparent !important;
}

.tracker-pill {
  display: inline-flex;
  gap: 4px;
  align-items: baseline;
  max-width: 100%;
  color: #67e8f9;
  cursor: pointer;
}

.tracker-pill strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tracker-empty {
  color: #71869e;
  font-style: italic;
  cursor: pointer;
}

.net-label {
  color: #b7c7d8;
  text-align: right;
}

.loading-cell {
  height: 80px !important;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 12px;
  bottom: 12px;
  max-width: 360px;
  padding: 8px 10px;
  border: 1px solid #5795c5;
  background: #10233d;
  box-shadow: 0 2px 16px var(--shadow);
  border-radius: 6px;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .15s, transform .15s;
  z-index: 70;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.panel-dialog {
  width: min(1040px, calc(100vw - 28px));
  max-height: calc(100vh - 44px);
  padding: 0;
  border: 1px solid #5795c5;
  border-radius: 8px;
  background: #101b2d;
  color: var(--text);
  box-shadow: 0 16px 60px rgba(0,0,0,.5);
}

.recurring-dialog {
  width: min(900px, calc(100vw - 28px));
}

.panel-dialog::backdrop {
  background: rgba(4, 10, 22, 0.72);
}

.dialog-shell {
  margin: 0;
  max-height: calc(100vh - 44px);
  overflow: auto;
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: linear-gradient(90deg, #153d66, #1c2e68);
  border-bottom: 1px solid var(--grid);
}

.dialog-head button {
  width: 28px;
  height: 26px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.dialog-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 14px;
  padding: 12px;
}

.recurring-grid {
  grid-template-columns: minmax(410px, 1.35fr) minmax(240px, 0.65fr);
  gap: 10px;
  padding: 10px;
}

.dialog-grid h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.dialog-grid label {
  display: grid;
  gap: 3px;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
}

.dialog-grid input,
.dialog-grid select,
.dialog-grid textarea {
  font-family: var(--field-font);
  font-size: 13px;
  width: 100%;
  min-height: 28px;
  line-height: 18px;
  padding: 4px 6px;
  color: var(--text);
  background: #0e1a2b;
}

.compact-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 6px 8px;
}

.compact-form-grid label {
  margin: 0;
}

.compact-form-grid .wide {
  grid-column: span 2;
}

.compact-dialog-shell .dialog-grid input,
.compact-dialog-shell .dialog-grid select {
  min-height: 25px;
  padding: 2px 5px;
}

.compact-check {
  margin-top: 8px !important;
  margin-bottom: 4px !important;
}

.hint-line {
  display: block;
  margin-top: 5px;
  color: #8fa8c2;
  line-height: 1.35;
}

.compact-actions {
  margin-top: 7px;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 7px !important;
}

.check-row input { width: auto; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.simple-list {
  display: grid;
  gap: 6px;
  max-height: 360px;
  overflow: auto;
  padding-right: 3px;
}

.recurring-list {
  max-height: 456px;
}

.list-card {
  border: 1px solid var(--grid-soft);
  background: #0e1a2b;
  padding: 7px;
  border-radius: 5px;
  cursor: pointer;
}

.list-card:hover {
  border-color: var(--accent);
  background: #122640;
}

.list-card strong {
  display: block;
  margin-bottom: 3px;
}

.list-card small {
  color: var(--muted);
}

.link-box {
  margin-top: 12px;
  border: 1px solid var(--grid-soft);
  background: #0d1b2d;
  border-radius: 6px;
  padding: 9px;
}

.link-box p {
  margin: 5px 0;
  color: var(--muted);
}

.link-box select {
  width: 100%;
  margin: 5px 0;
}

.context-menu {
  position: fixed;
  z-index: 90;
  min-width: 210px;
  padding: 5px;
  border: 1px solid #5795c5;
  border-radius: 7px;
  background: #0d1b2d;
  box-shadow: 0 12px 34px rgba(0,0,0,.45);
}

.context-menu button {
  width: 100%;
  display: block;
  text-align: left;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  padding: 6px 8px;
  min-height: 27px;
}

.context-menu button:hover {
  background: #174368;
}

.color-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  background: rgba(4, 10, 22, 0.56);
}

.color-popup {
  width: 260px;
  border: 1px solid #5795c5;
  border-radius: 9px;
  background: #0f1b2d;
  color: var(--text);
  box-shadow: 0 16px 60px rgba(0,0,0,.5);
  padding: 12px;
}

.color-popup strong {
  display: block;
  margin-bottom: 9px;
}

.color-popup input[type="color"] {
  width: 100%;
  height: 54px;
  padding: 2px;
  background: #0b1220;
}

.color-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 10px;
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; }
  .brand-block { min-width: 100%; }
  .toolbar { top: 80px; }
  .dialog-grid,
  .recurring-grid { grid-template-columns: 1fr; }
  .compact-form-grid { grid-template-columns: 1fr 1fr; }
  .compact-form-grid .wide { grid-column: span 2; }
  .selected-hint { width: 100%; margin-left: 0; }
}
