/* Finance Tracker */

:root {
  --ink:      #0f172a;
  --ink-soft: #475569;
  --muted:    #64748b;
  --line:     #e2e8f0;
  --line-soft:#f1f5f9;
  --paper:    #ffffff;
  --bg:       #f6f8fa;
  --brand:    #0f766e;
  --brand-dk: #115e59;
  --brand-lt: #ccfbf1;
  --in:       #15803d;
  --out:      #b91c1c;
  --warn:     #b45309;
  --radius:   14px;
  --shadow:   0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand-dk); }

h1 { font-size: 1.35rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; letter-spacing: -.01em; }
h3 { font-size: .95rem; margin: 0 0 .6rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny  { font-size: .78rem; }
.right { text-align: right; }
.center{ text-align: center; }
.nowrap{ white-space: nowrap; }
.pos { color: var(--in); }
.neg { color: var(--out); }
.warnnum { color: var(--warn); }
.hide { display: none !important; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  padding: .6rem .8rem;
  padding-top: calc(.6rem + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--brand) 0%, #0e7490 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; }
.brand .mark { display: block; border-radius: 8px; }
.brand-text { font-size: 1rem; letter-spacing: -.01em; }

.tabs {
  display: flex;
  gap: .25rem;
  order: 3;
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: .35rem .7rem;
  border-radius: 999px;
  font-size: .88rem;
  white-space: nowrap;
  background: rgba(255,255,255,.12);
}
.tabs a.on { background: #fff; color: var(--brand-dk); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

/* ---------------------------------------------------------------- layout */
.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem .8rem 3rem;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card.tight { padding: .7rem; }
details.fold summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .4rem;
}
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary::before {
  content: "\25B8";
  color: var(--muted);
  font-size: .9rem;
  transition: transform .15s;
}
details.fold[open] summary::before { transform: rotate(90deg); }

.page-head {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .9rem;
}
.page-head .spacer { flex: 1 1 auto; }

/* month stepper */
.monthnav {
  display: flex;
  align-items: center;
  gap: .35rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .2rem;
  box-shadow: var(--shadow);
}
.monthnav button {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--brand-dk);
}
.monthnav button:hover { background: var(--brand-lt); }
.monthnav .label {
  min-width: 9.5rem;
  text-align: center;
  font-weight: 650;
  font-size: .95rem;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: .5rem .85rem;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #fbfdfe; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dk); border-color: var(--brand-dk); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-dk); }
.btn.danger { color: var(--out); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.topbar .btn { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); color: #fff; }

/* ---------------------------------------------------------------- forms */
label { display: block; font-size: .82rem; color: var(--ink-soft); font-weight: 600; margin-bottom: .75rem; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: .22rem;
  padding: .5rem .6rem;
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-lt);
  border-color: var(--brand);
}
input[type="checkbox"] { width: auto; display: inline-block; margin: 0 .4rem 0 0; }

.formrow {
  display: grid;
  gap: .6rem;
  grid-template-columns: 1fr;
}
.formrow label { margin-bottom: 0; }
.formrow .actions { display: flex; gap: .5rem; align-items: flex-end; }

.seg { display: flex; width: fit-content; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: .22rem; }
.seg button {
  border: 0;
  background: #fff;
  padding: .5rem .8rem;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  color: var(--ink-soft);
}
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }

/* ---------------------------------------------------------------- tables */
.scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .5rem .55rem; text-align: left; border-bottom: 1px solid var(--line-soft); }
thead th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody tr:hover { background: #fbfdfe; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table input { margin: 0; padding: .35rem .45rem; font-size: .88rem; }

.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; vertical-align: baseline; }

.pill {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  background: var(--line-soft);
  color: var(--ink-soft);
}
.pill.open   { background: #dcfce7; color: #166534; }
.pill.closed { background: #fee2e2; color: #991b1b; }

/* summary tiles */
.tiles { display: grid; gap: .7rem; grid-template-columns: repeat(2, 1fr); margin-bottom: 1rem; }
.tile {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .75rem .85rem;
}
.tile .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile .v { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; margin-top: .15rem; font-variant-numeric: tabular-nums; }

/* time sheet grid */
.weekgrid { min-width: 720px; }
.weekgrid th.day { text-align: center; font-weight: 600; }
.weekgrid th.day span { display: block; font-size: .68rem; color: var(--muted); }
.weekgrid td.cell { text-align: center; padding: .25rem; }
.weekgrid td.cell input {
  width: 100%;
  min-width: 3.4rem;
  text-align: center;
  padding: .4rem .2rem;
  border-radius: 8px;
}
.weekgrid td.cell input.has { background: var(--brand-lt); border-color: #99f6e4; font-weight: 650; }
.weekgrid .out-month { background: #fafafa; }
.weekgrid td.client { font-weight: 600; white-space: nowrap; }
.weekgrid .wk-total { font-weight: 700; background: var(--line-soft); }

.bar { height: .5rem; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }

.notice {
  padding: .6rem .8rem;
  border-radius: 10px;
  font-size: .88rem;
  margin-bottom: .8rem;
  border: 1px solid;
}
.notice.err  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.notice.ok   { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.notice.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.error { color: var(--out); font-size: .88rem; }
.ok    { color: var(--in);  font-size: .88rem; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
  padding: 1rem .8rem calc(1.5rem + env(safe-area-inset-bottom));
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%) translateY(1rem);
  background: var(--ink);
  color: #fff;
  padding: .55rem 1rem;
  border-radius: 999px;
  font-size: .88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 90;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: #991b1b; }

/* ---------------------------------------------------------------- sign in */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.2rem;
  background: linear-gradient(160deg, #0f766e 0%, #0e7490 55%, #164e63 100%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 18px;
  padding: 1.6rem 1.4rem;
  box-shadow: 0 20px 60px rgba(2,44,34,.35);
}
.auth-card h1 { font-size: 1.2rem; margin-bottom: .2rem; }
.auth-card .lead { color: var(--muted); font-size: .88rem; margin: 0 0 1.1rem; }
.auth-card .logo, .auth-card .auth-mark { display: block; margin: 0 auto .8rem; border-radius: 14px; }
.auth-card .btn { width: 100%; margin-top: .5rem; }
.codes { list-style: none; padding: 0; margin: .6rem 0 0; }
.codes li { padding: .35rem 0; border-bottom: 1px solid var(--line-soft); }
.codes code { font-size: 1rem; letter-spacing: .06em; }

.code-input {
  letter-spacing: .5em;
  text-align: center;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- wider screens */
@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .formrow.cols-4 { grid-template-columns: repeat(4, 1fr); }
  .formrow.cols-5 { grid-template-columns: repeat(5, 1fr); }
  .formrow.cols-6 { grid-template-columns: repeat(6, 1fr); }
  .formrow.cols-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .topbar { padding: .55rem 1.2rem; flex-wrap: nowrap; }
  .tabs { order: 0; width: auto; margin-left: 1rem; }
  .wrap { padding: 1.4rem 1.2rem 3rem; }
  .two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1rem; align-items: start; }
}

/* ---------------------------------------------------------------- print */
@media print {
  .topbar, .foot, .no-print, .btn, .monthnav { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; margin-bottom: .6rem; }
  .scroller { overflow: visible; }
  table { font-size: 10.5pt; }
  .print-head { display: block !important; }
  @page { margin: 12mm; size: A4; }
}
.print-head { display: none; margin-bottom: .8rem; }
.print-head h1 { font-size: 1.2rem; }
