/* Ownlivo design system. Tokens first; components and pages use only these variables.
   Light theme by design (warm off-white, forest green). Geist is self-hosted (OFL). */

@font-face { font-family: "Geist"; src: url("/static/fonts/Geist-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Geist"; src: url("/static/fonts/Geist-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Geist"; src: url("/static/fonts/Geist-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Geist"; src: url("/static/fonts/Geist-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  /* Color */
  --bg: #f7f6f2;            /* warm off-white canvas */
  --surface: #ffffff;
  --surface-2: #f2f0ea;     /* subtle fills, table headers */
  --surface-3: #e9e6de;
  --border: #e3e0d7;
  --border-strong: #cfcabd;
  --text: #191d1b;          /* deep charcoal */
  --text-2: #3f4743;
  --muted: #66706a;         /* 4.9:1 on white */
  --brand: #1f4d3d;         /* deep forest green */
  --brand-hover: #173b2f;
  --brand-600: #2c6a53;
  --brand-50: #edf4f0;
  --brand-100: #d7e7de;
  --brand-ink: #ffffff;
  --green: #2a7350; --green-bg: #e8f3ec;
  --blue: #2b5c8a;  --blue-bg: #e9f0f7;
  --amber: #8a5a00; --amber-bg: #fbf1db;
  --red: #b3261e;   --red-bg: #fbeae8;
  --violet: #5a4e9c; --violet-bg: #efedf8;   /* AI accents, used sparingly */
  --focus: #2c6a53;

  /* Type */
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-xs: 0.75rem; --fs-sm: 0.8125rem; --fs-base: 0.875rem; --fs-md: 0.9375rem;
  --fs-lg: 1.0625rem; --fs-xl: 1.25rem; --fs-2xl: 1.5rem; --fs-3xl: 1.875rem; --fs-4xl: 2.5rem; --fs-5xl: 3.25rem;
  --lh: 1.5; --tracking-tight: -0.015em; --tracking-tighter: -0.03em;

  /* Space (4px grid) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px; --s20: 80px;

  /* Shape and depth */
  --r-sm: 6px; --r: 8px; --r-lg: 12px; --r-xl: 16px; --r-full: 999px;
  --shadow-xs: 0 1px 0 rgba(25, 29, 27, 0.04);
  --shadow-sm: 0 1px 2px rgba(25, 29, 27, 0.06), 0 1px 1px rgba(25, 29, 27, 0.03);
  --shadow: 0 4px 12px -2px rgba(25, 29, 27, 0.08), 0 2px 4px rgba(25, 29, 27, 0.04);
  --shadow-lg: 0 18px 40px -12px rgba(25, 29, 27, 0.22), 0 4px 10px rgba(25, 29, 27, 0.06);

  /* Motion */
  --ease: cubic-bezier(0.2, 0, 0, 1); --fast: 120ms; --mid: 200ms;

  /* Layout */
  --sidebar: 248px; --sidebar-collapsed: 64px; --topbar: 56px; --content-max: 1200px;
  color-scheme: light;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-base); line-height: var(--lh); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: var(--tracking-tight); color: var(--text); }
h1 { font-size: var(--fs-2xl); line-height: 1.2; }
h2 { font-size: var(--fs-lg); line-height: 1.3; }
h3 { font-size: var(--fs-md); line-height: 1.35; }
p { margin: 0 0 var(--s3); }
a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; text-underline-offset: 2px; }
img { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s6) 0; }
.hidden, [hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s3); top: -48px; z-index: 100; background: var(--brand); color: #fff; padding: var(--s2) var(--s3); border-radius: var(--r); transition: top var(--fast) var(--ease); }
.skip-link:focus { top: var(--s3); color: #fff; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.pre { white-space: pre-wrap; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--red); }
.pos { color: var(--green); }
.icon { width: 18px; height: 18px; flex: none; stroke-width: 1.75; }
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 22px; height: 22px; }

/* ---------- Buttons ---------- */
button, .button {
  font: inherit; font-weight: 500; font-size: var(--fs-base); line-height: 1; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 36px; padding: 0 var(--s4); border-radius: var(--r); border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow-xs);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
button:hover, .button:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-ink); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button.ghost, .button.ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.ghost:hover, .button.ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
button.quiet, .button.quiet { background: transparent; color: var(--text-2); border-color: transparent; box-shadow: none; }
button.quiet:hover, .button.quiet:hover { background: var(--surface-2); color: var(--text); }
button.danger, .button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.danger:hover { background: #8f1e18; border-color: #8f1e18; }
button.small, .button.small { min-height: 30px; padding: 0 var(--s3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
button.lg, .button.lg { min-height: 44px; padding: 0 var(--s5); font-size: var(--fs-md); }
button.icon-only, .button.icon-only { padding: 0; width: 36px; }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.big-button { width: 100%; min-height: 52px; font-size: var(--fs-md); }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 500; font-size: var(--fs-sm); color: var(--text-2); margin: var(--s4) 0 var(--s1); }
.hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px prevents iOS zoom */ color: var(--text); width: 100%;
  min-height: 40px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
@media (min-width: 900px) { input, select, textarea { font-size: var(--fs-base); } }
input:hover, select:hover, textarea:hover { border-color: #b9b3a4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-600); box-shadow: 0 0 0 3px rgba(44, 106, 83, 0.18); }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--brand); flex: none; }
input[type="file"] { padding: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: var(--s2); }
.choices label { display: inline-flex; align-items: center; gap: var(--s2); margin: 0; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); cursor: pointer; font-weight: 500; color: var(--text); transition: border-color var(--fast), background var(--fast); }
.choices label:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }
.form-row { display: grid; gap: 0 var(--s4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.error-text { color: var(--red); font-size: var(--fs-sm); margin: var(--s2) 0 0; }
label.check { display: flex; gap: var(--s2); align-items: center; font-weight: 500; color: var(--text); }
details > summary { min-height: 24px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: var(--s2); }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: ""; width: 7px; height: 7px; border-right: 1.75px solid var(--muted); border-bottom: 1.75px solid var(--muted); transform: rotate(-45deg); transition: transform var(--fast) var(--ease); margin-right: 2px; }
details[open] > summary::before { transform: rotate(45deg); }
details[open] > summary { margin-bottom: var(--s3); }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); margin-bottom: var(--s4); box-shadow: var(--shadow-xs); }
.card.flush { padding: 0; overflow: hidden; }
.card > h2:first-child, .card > .section-head:first-child { margin-bottom: var(--s3); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.card-body { padding: var(--s4) var(--s5); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.split { display: grid; gap: var(--s4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .split { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); } .split.even { grid-template-columns: 1fr 1fr; } }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.row-link { display: block; padding: var(--s3) var(--s1); color: inherit; text-decoration: none; border-radius: var(--r-sm); transition: background var(--fast) var(--ease); }
a.row-link:hover { background: var(--surface-2); text-decoration: none; color: inherit; }
.row-top { display: flex; justify-content: space-between; gap: var(--s3); align-items: center; }
.row-title { font-weight: 600; color: var(--text); }
.row-sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 2px 6px; align-items: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s5); font-size: var(--fs-base); margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); }

/* Stats (legacy) and metrics */
.stats { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: var(--s4); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow-xs); }
.stat .n { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; }
.stat.alert .n { color: var(--red); }

/* Badges / chips */
.chip, .badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 500; line-height: 1.5; background: var(--surface-2); color: var(--text-2); white-space: nowrap; border: 1px solid transparent; }
.chip::before, .badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.chip.open, .chip.in_review, .badge.blue { background: var(--blue-bg); color: var(--blue); }
.chip.scheduled, .chip.in_progress, .badge.amber { background: var(--amber-bg); color: var(--amber); }
.chip.completed, .chip.ok, .badge.green { background: var(--green-bg); color: var(--green); }
.chip.closed, .chip.cancelled { background: var(--surface-2); color: var(--muted); }
.chip.danger, .badge.red { background: var(--red-bg); color: var(--red); }
.chip.private { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border-strong); }
.chip.private::before { display: none; }
.badge.violet { background: var(--violet-bg); color: var(--violet); }

/* Alerts */
.alert { border-radius: var(--r-lg); padding: var(--s3) var(--s4); margin-bottom: var(--s4); border: 1px solid; font-size: var(--fs-base); }
.alert h3 { font-size: var(--fs-base); margin-bottom: var(--s1); }
.alert.danger { background: var(--red-bg); border-color: #f0c9c5; color: #5c140f; }
.alert.danger h3 { color: var(--red); }
.alert.warn { background: var(--amber-bg); border-color: #efdcae; color: #4d3300; }
.alert.ok { background: var(--green-bg); border-color: #c4e0cf; color: #12402b; }
.alert.info { background: var(--blue-bg); border-color: #cddcec; color: #173b5d; }
.alert .list > li { border-color: rgba(0, 0, 0, 0.06); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: var(--s6); transform: translateX(-50%); z-index: 90; background: var(--text); color: #fff; padding: 10px var(--s4); border-radius: var(--r); box-shadow: var(--shadow-lg); font-size: var(--fs-base); max-width: calc(100vw - 32px); animation: toast-in var(--mid) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite; border-radius: var(--r-sm); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Misc legacy pieces */
.photos { display: flex; flex-wrap: wrap; gap: var(--s2); }
.photos img, .photo-strip img { max-height: 200px; border-radius: var(--r); border: 1px solid var(--border); object-fit: cover; }
.photo-strip { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s1); }
.photo-strip img { width: 120px; height: 90px; }
.file-chip { display: inline-flex; gap: var(--s1); align-items: center; padding: 6px 10px; border-radius: var(--r); background: var(--surface-2); font-size: var(--fs-sm); }
.due-overdue { color: var(--red); font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--s4); border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 var(--s4) var(--s3); }
.timeline li::before { content: ""; position: absolute; left: calc(-1 * var(--s4) - 6px); top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand-600); }
.receipt .kv { font-size: var(--fs-md); }
.bars li { padding: var(--s2) 0; }
.bar { height: 8px; border-radius: var(--r-full); margin-top: 4px; min-width: 2px; }
.bar.in, .key.in { background: var(--brand-600); }
.bar.out, .key.out { background: #d4a43a; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; }
.env-banner { background: var(--amber-bg); color: var(--amber); font-size: var(--fs-xs); font-weight: 500; text-align: center; padding: 6px var(--s4); border-bottom: 1px solid #efdcae; }

@media print {
  .sidebar, .topbar, .footer, .env-banner, .no-print, #toast, .mobile-tabs { display: none !important; }
  body { background: #fff; }
  .main { margin: 0 !important; }
  .card { box-shadow: none; border: 1px solid #999; }
}

/* Links inside running text are underlined so they don't rely on color alone (WCAG 1.4.1). */
p a, .pre a, li > p a { text-decoration: underline; text-underline-offset: 2px; }
