:root {
  --bg: #F8F6F1;
  --card: #ffffff;
  --card-shadow: 0 4px 16px rgba(76,31,40,0.06);
  --text: #1A1A1A;
  --muted: #7A7C86;
  --line: #E2D9CC;
  --accent: #4C1F28;
  --accent-secondary: #0E1A40;
  --accent-gold: #C2A25F;
  --danger: #8A2B38;
  --input-bg: #ffffff;
  --subcard-bg: #FDFBF7;
  --topbar-bg: rgba(248,246,241,0.92);
  --font-sans: "Source Sans 3", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --card: #12161c;
    --card-shadow: 0 4px 16px rgba(0,0,0,0.25);
    --text: #e9eef5;
    --muted: #a7b3c4;
    --line: #273244;
    --accent: #C2A25F;
    --accent-secondary: #F8F6F1;
    --accent-gold: #C2A25F;
    --danger: #ff5d5d;
    --input-bg: #0f1319;
    --subcard-bg: rgba(255,255,255,0.04);
    --topbar-bg: rgba(10,12,16,0.85);
  }
}

/* ─── Base ─── */
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

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

.wrap { max-width: 1100px; margin: 0 auto; padding: 18px; }

/* ─── Skip link (accessibility) ─── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--bg);
  padding: 8px 16px;
  z-index: 100;
  font-weight: 600;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus {
  top: 0;
}

/* ─── Topbar ─── */
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.brand { font-weight: 700; letter-spacing: 0.2px; font-size: 1.05rem; }
.brandlink { color: var(--accent); }
.brandlink:hover { color: var(--accent-secondary); text-decoration: none; }

/* ─── Navigation ─── */
.nav { font-size: 0.9rem; display: flex; align-items: center; gap: 4px; }
.nav a {
  padding: 6px 10px;
  color: var(--text);
  opacity: 0.78;
  border-radius: var(--radius);
  transition: opacity 0.15s, background 0.15s;
}
.nav a:hover { opacity: 1; background: rgba(194,162,95,0.1); text-decoration: none; }
.nav a.active {
  color: var(--accent);
  opacity: 1;
  background: rgba(194,162,95,0.12);
  font-weight: 600;
}

/* Admin dropdown */
.nav-group { position: relative; }
.nav-group__toggle {
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 10px;
  color: var(--text);
  opacity: 0.78;
  border-radius: var(--radius);
  border: none;
  background: none;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
.nav-group__toggle:hover { opacity: 1; background: rgba(194,162,95,0.1); }
.nav-group__toggle.active { color: var(--accent); opacity: 1; font-weight: 600; }
.nav-group__menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  min-width: 160px;
  z-index: 60;
  padding: 4px;
}
.nav-group__menu--open { display: block; }
.nav-group__menu a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text);
  opacity: 1;
}
.nav-group__menu a:hover { background: rgba(194,162,95,0.1); text-decoration: none; }
.nav-group__menu a.active { color: var(--accent); font-weight: 600; }

/* Mobile hamburger */
.nav-toggle { display: none; }

.topbar-user { flex-shrink: 0; }
.topbar-user__info { font-size: 0.82rem; }

@media (max-width: 900px) {
  .topbar .wrap { flex-wrap: wrap; }
  .nav-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    order: 2;
  }
  .nav-toggle__bar {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s;
  }
  .nav {
    display: none;
    flex-direction: column;
    width: 100%;
    order: 10;
    gap: 2px;
    padding: 8px 0;
  }
  .nav--open { display: flex; }
  .nav a { padding: 10px 12px; }
  .topbar-user { order: 3; }
  .topbar-user__info { display: none; }

  .nav-group { width: 100%; }
  .nav-group__menu {
    position: static;
    box-shadow: none;
    border: none;
    padding-left: 16px;
  }
  .nav-group__menu--open { display: block; }
}

/* ─── Flash messages ─── */
.flash-container { border-bottom: 1px solid var(--line); }
.flash-container .wrap { padding-top: 0; padding-bottom: 0; }
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin: 8px 0;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.3s;
}
.flash--success {
  background: rgba(43, 122, 46, 0.1);
  border: 1px solid rgba(43, 122, 46, 0.3);
  color: #2b7a2e;
}
.flash--error {
  background: rgba(138, 43, 56, 0.1);
  border: 1px solid rgba(138, 43, 56, 0.3);
  color: var(--danger);
}
.flash--info {
  background: rgba(194, 162, 95, 0.1);
  border: 1px solid rgba(194, 162, 95, 0.3);
  color: #8a6d1f;
}
.flash__close {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.6;
  line-height: 1;
}
.flash__close:hover { opacity: 1; }

@media (prefers-color-scheme: dark) {
  .flash--success { color: #6ecf72; }
  .flash--error { color: #ff7a7a; }
  .flash--info { color: #d4b76a; }
}

/* ─── Clock banner ─── */
.clock-banner {
  border-bottom: 1px solid var(--line);
  background: rgba(194,162,95,0.1);
}
.clock-banner .wrap {
  padding-top: 10px;
  padding-bottom: 10px;
}
.clock-banner__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
  flex-wrap: wrap;
}
.clock-banner__row:first-child { border-top: none; }
.clock-banner__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
}
.clock-banner__title { font-weight: 700; }
.clock-banner__detail { font-size: 0.9rem; }
.clock-banner__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.clock-banner__timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.35);
  font-size: 0.9rem;
}

/* ─── Cards ─── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin: 16px 0;
  box-shadow: var(--card-shadow);
}

h1, h2 { margin: 0 0 8px 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
.lead { font-size: 1.05rem; }

.muted { color: var(--muted); }
.row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.right { text-align: right; }

/* ─── Grid ─── */
.grid { display: grid; grid-template-columns: 1.4fr 1.2fr auto; gap: 10px; align-items: end; }
.grid > * { min-width: 0; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: 1.2fr 1.6fr 1fr auto; }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid .full { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .grid, .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
}

/* ─── Filters ─── */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}
.filters .full { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 500px) {
  .filters { grid-template-columns: 1fr; }
}

/* ─── Forms ─── */
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.small-label { font-size: 0.82rem; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.stacked-form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.stacked-form .btn { width: 100%; }

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  font: inherit;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  min-height: 42px;
  line-height: 1.2;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { resize: vertical; }

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

select[multiple] {
  background-image: none;
  padding-right: 12px;
  min-height: 100px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(194,162,95,0.2);
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

/* ─── Buttons ─── */
.btn {
  font: inherit;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--accent-gold); border-color: var(--accent-gold); color: var(--text); text-decoration: none; }
.btn.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.btn.danger:hover { background: #6E1F2A; border-color: #6E1F2A; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); opacity: 0.9; }
.btn.ghost:hover { opacity: 1; background: rgba(194,162,95,0.1); }
.btn.ghost.danger { color: var(--danger); border-color: rgba(138,43,56,0.4); }
.btn.ghost.danger:hover { background: rgba(138,43,56,0.08); }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 0.82rem; }

/* ─── Pills & tags ─── */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.running { border-color: var(--accent-gold); color: var(--accent); background: rgba(194,162,95,0.12); }
.pill.idle { color: var(--muted); }

.pill.positive {
  color: #2b7a2e;
  border-color: rgba(43, 122, 46, 0.4);
  background: rgba(43, 122, 46, 0.1);
}
.pill.negative {
  color: #a03737;
  border-color: rgba(160, 55, 55, 0.4);
  background: rgba(160, 55, 55, 0.1);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  background: rgba(194,162,95,0.08);
}

/* ─── Tables ─── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -18px;
  padding: 0 18px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}
.table th, .table td {
  border-top: 1px solid var(--line);
  padding: 9px 8px;
  vertical-align: top;
}
.table th {
  text-align: left;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ─── Inline edit (details/summary pattern) ─── */
.inline-edit { position: relative; }
.inline-edit__body {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 16px;
  min-width: 320px;
  max-width: 520px;
  width: max-content;
}

@media (max-width: 900px) {
  .inline-edit__body {
    position: fixed;
    right: 8px;
    left: 8px;
    top: auto;
    bottom: 8px;
    max-width: none;
    width: auto;
    max-height: 80vh;
    overflow-y: auto;
  }
}

details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

/* ─── Actions & layout ─── */
.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.footer { padding-bottom: 28px; }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.subcard {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--subcard-bg);
}

/* ─── Stat grid ─── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--subcard-bg);
}
.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; margin: 4px 0; }
.stat-meta { color: var(--muted); font-size: 0.85rem; }

/* ─── Trends ─── */
.trend-list { display: grid; gap: 14px; }
.trend-item { display: grid; gap: 4px; }

.trend-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}
.trend-row:first-of-type { border-top: none; }

.trend-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(194,162,95,0.2);
  overflow: hidden;
  position: relative;
}
.trend-bar > span {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-gold));
  border-radius: inherit;
}

/* ─── Empty states ─── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}
.empty-state p {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

/* ─── Pagination ─── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0 4px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}

/* ─── Project cards ─── */
.project-grid { display: grid; gap: 12px; }

.project-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--subcard-bg);
  display: grid;
  gap: 10px;
}
.project-card.overdue {
  border-color: rgba(138, 43, 56, 0.5);
  box-shadow: 0 0 0 1px rgba(138, 43, 56, 0.15);
}
.project-card.due_soon {
  border-color: rgba(194, 162, 95, 0.5);
}
.project-card__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.project-card__title { font-weight: 700; }
.project-card__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

/* ─── Status pills ─── */
.pill.status.open {
  color: #2b7a2e;
  border-color: rgba(43, 122, 46, 0.4);
  background: rgba(43, 122, 46, 0.1);
}
.pill.status.closed, .pill.status.done {
  color: #a03737;
  border-color: rgba(160, 55, 55, 0.4);
  background: rgba(160, 55, 55, 0.1);
}
.pill.status.on_hold {
  color: #7A7C86;
  border-color: rgba(122, 124, 134, 0.4);
  background: rgba(122, 124, 134, 0.1);
}

/* ─── Due dates ─── */
.due {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
}
.due.overdue {
  color: var(--danger);
  border-color: rgba(138, 43, 56, 0.5);
  background: rgba(138, 43, 56, 0.1);
}
.due.due_soon {
  color: #8a6d1f;
  border-color: rgba(194, 162, 95, 0.5);
  background: rgba(194, 162, 95, 0.12);
}

/* ─── Task cards ─── */
.task-list { display: grid; gap: 10px; }
.task-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  align-items: center;
}
.task-card .btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ─── Statements ─── */
.statement-card { display: grid; gap: 14px; }
.statement-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.statement-contact { display: flex; gap: 6px; flex-wrap: wrap; }
.statement-period { text-align: right; min-width: 200px; }
.statement-period__range { font-size: 1.1rem; font-weight: 600; margin-top: 6px; }
.statement-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--subcard-bg);
}

/* ─── Aging ─── */
.aging-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}
.aging-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--bg);
}

/* ─── Ledger ─── */
.ledger-table td .ledger-title { font-weight: 600; }
.ledger-table tfoot th { border-top: 2px solid var(--line); font-weight: 700; }

/* ─── Utilities ─── */
.padtop { margin-top: 10px; }

.editform {
  display: grid;
  gap: 10px;
  max-width: 520px;
}

/* ─── Login page ─── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-wrapper {
  width: 100%;
  max-width: 420px;
  padding: 18px;
}
.login-card {
  padding: 32px 28px;
}
.login-header {
  text-align: center;
  margin-bottom: 24px;
}
.login-logo {
  border-radius: 12px;
  margin-bottom: 12px;
}
.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.login-btn {
  width: 100%;
  margin-top: 4px;
}
