/* ===== Design tokens ===== */
:root {
  --primary: #1B3A5C;
  --primary-hover: #16314D;
  --sidebar: #122539;
  --accent: #2E7DD1;
  --accent-2: #35B6C9;
  --positive: #1D9E75;
  --warning: #EF9F27;
  --negative: #D64545;
  --app-bg-1: #D6EAF7;
  --app-bg-2: #E0EFF9;
  --app-bg-3: #EAF4FB;
  --surface: #FFFFFF;
  --surface-2: #F3F7FC;
  --border: #E3E8F0;
  --text: #1F2733;
  --text-muted: #6B7787;
  --text-on-dark: var(--primary);
  --text-on-dark-muted: var(--text-muted);
  --radius-card: 16px;
  --radius-input: 8px;
  --shadow-card: 0 14px 30px -16px rgba(27, 58, 92, .28), 0 3px 10px rgba(27, 58, 92, .10);
  --accent-strip: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 52%, var(--positive) 100%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background-color: var(--app-bg-1);
  background-image: linear-gradient(158deg, var(--app-bg-1) 0%, var(--app-bg-2) 55%, var(--app-bg-3) 100%);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; color: var(--primary); font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ===== Reusable components ===== */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 28px;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent-strip);
}
.card__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 18px;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.input {
  height: 38px;
  padding: 0 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(46, 125, 209, .25);
}
.input--number { text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  height: 38px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-input);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 140ms ease, transform 120ms ease;
}
.btn--primary {
  background-image: linear-gradient(135deg, var(--primary) 0%, #24507A 100%);
  color: #fff;
  box-shadow: 0 8px 18px -8px rgba(27, 58, 92, .7);
}
.btn--primary:hover { box-shadow: 0 10px 22px -8px rgba(27, 58, 92, .85); transform: translateY(-1px); }
.btn--primary:active { transform: translateY(0); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { background: var(--surface-2); border-color: #CBD5E4; }

.error-text { color: var(--negative); font-size: 13px; min-height: 18px; }

/* ===== Login screen ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--app-bg-1);
  background-image:
    radial-gradient(1200px 600px at 15% -10%, rgba(46, 125, 209, .34), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(53, 182, 201, .26), transparent 55%),
    linear-gradient(158deg, var(--app-bg-1) 0%, #274a72 60%, #325786 100%);
  padding: 20px;
}
.login-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 30px 70px -25px rgba(4, 10, 20, .7);
  padding: 32px;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--accent-strip);
}
.login-card__brand { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.login-card__subtitle { color: var(--text-muted); margin-bottom: 24px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form .btn { width: 100%; }

/* ===== Dashboard layout ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background-color: var(--sidebar);
  background-image: linear-gradient(180deg, rgba(46, 125, 209, .10) 0%, transparent 40%);
  color: #C7D2DE;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  border-right: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 1px 0 24px rgba(4, 10, 20, .35);
}
.sidebar__brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  padding: 0 24px 24px;
}
.sidebar__brand::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 9px;
  border-radius: 3px;
  background: var(--accent-strip);
  vertical-align: baseline;
}
.sidebar__nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar__item {
  display: block;
  width: 100%;
  padding: 10px 24px;
  color: #C7D2DE;
  font: inherit;
  font-weight: 500;
  text-align: left;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.sidebar__item:hover { color: #fff; text-decoration: none; }
.sidebar__item--active { background: var(--primary); color: #fff; border-left-color: var(--accent); }
.sidebar__spacer { flex: 1; }

.main { flex: 1; min-width: 0; padding: 28px 36px 40px; }
.main__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.main__title { font-size: 20px; color: var(--text-on-dark); letter-spacing: .01em; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--text-on-dark-muted); font-weight: 600; }
.user-chip__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-image: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 4px 12px -3px rgba(46, 125, 209, .6);
}
.stack { display: flex; flex-direction: column; gap: 24px; }

/* ===== Entry form ===== */
.entry-form { display: block; }
.entry-form__inputs {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.entry-form__inputs .field { flex: 1 1 150px; min-width: 140px; }
.entry-form__inputs .field--market { flex: 1 1 190px; }

.entry-form__result {
  display: flex;
  justify-content: center;
  margin-top: 22px;
}
.result-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 40px;
  min-width: 240px;
  text-align: center;
  border-radius: 14px;
  background-image: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  box-shadow: 0 14px 30px -12px rgba(46, 125, 209, .55);
}
.result-pill__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: rgba(255, 255, 255, .78);
  font-weight: 700;
}
.result-pill__value {
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.form-error { margin-top: 14px; text-align: center; }

.entry-form__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 6px;
}
.entry-form__actions .btn { min-width: 120px; }

/* ===== Records table ===== */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  padding: 12px;
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  border-bottom: 2px solid var(--border);
}
.table th.col-actions { cursor: default; }
.table th.is-numeric, .table td.is-numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table th .caret { color: var(--accent); margin-left: 4px; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); height: 46px; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color 120ms ease; }
.table tbody tr:nth-child(even) { background: #FAFCFE; }
.table tbody tr:hover { background: #EEF4FB; }

.amount {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 7px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.amount--up { color: var(--positive); background: rgba(29, 158, 117, .12); }
.amount--down { color: var(--negative); background: rgba(214, 69, 69, .12); }

.chip {
  display: inline-block;
  padding: 3px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}
.empty-state {
  padding: 44px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

/* ===== Row actions / inline edit ===== */
.col-actions { width: 1%; white-space: nowrap; }
.row-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.row-btn:hover { background: var(--surface-2); border-color: #CBD5E4; }
.row-btn--edit { color: var(--accent); border-color: rgba(46, 125, 209, .35); }
.row-btn--edit:hover { background: rgba(46, 125, 209, .08); }
.row-btn--save {
  color: #fff;
  background: var(--positive);
  border-color: transparent;
}
.row-btn--save:hover { background: #17855F; }
.row-btn--delete { color: var(--negative); border-color: rgba(214, 69, 69, .35); }
.row-btn--delete:hover { background: rgba(214, 69, 69, .08); }

.table tbody tr.row-editing { background: #EAF2FB; }
.table tbody tr.row-editing:hover { background: #EAF2FB; }
.cell-input {
  width: 100%;
  min-width: 70px;
  height: 32px;
  padding: 0 8px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #C6D3E4;
  border-radius: 6px;
}
.cell-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(46, 125, 209, .22);
}
.cell-input.input--number { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; }
.cell-error {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--negative);
}

/* ===== Filter bar ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px;
  margin-bottom: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.filter-bar .field { flex: 0 0 auto; }
.filter-bar .input { height: 34px; background: var(--surface); }
.filter-bar .input--search { min-width: 200px; }
.filter-bar .input--range { width: 110px; }
.filter-bar__count {
  margin-left: auto;
  align-self: center;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}
