/* FarmBill — B2B Success invoicing.
   Light and dark are both first-class; dark steps are chosen, not flipped. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --rule: #e3e6ea;
  --rule-strong: #c9cfd6;

  --ink: #14181d;
  --ink-2: #4a525c;
  --ink-3: #7b848f;

  --brand: #0087c4;
  --brand-ink: #005e8a;
  --brand-soft: #e6f4fb;

  /* Chart + status. Validated for CVD against the light surface. */
  --paid: #1a7f4b;
  --open: #3b82f6;
  --late: #c0392b;
  --paid-soft: #e6f4ec;
  --open-soft: #e8f0fe;
  --late-soft: #fdeceb;
  --draft-soft: #eef0f3;

  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101316;
    --surface: #191d21;
    --surface-2: #1f242a;
    --rule: #2b3238;
    --rule-strong: #3c454e;

    --ink: #e9edf1;
    --ink-2: #a8b2bc;
    --ink-3: #7e8892;

    --brand: #35a9e0;
    --brand-ink: #6cc4ee;
    --brand-soft: #12303f;

    --paid: #1fa871;
    --open: #4a90f2;
    --late: #e5645a;
    --paid-soft: #102b21;
    --open-soft: #142438;
    --late-soft: #33191a;
    --draft-soft: #232830;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

.boot { padding: 80px; text-align: center; color: var(--ink-3); }

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--rule);
  border-radius: 14px; padding: 36px 32px; box-shadow: var(--shadow); text-align: center;
}
.login-card img { width: 76px; margin-bottom: 20px; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card p { color: var(--ink-3); margin: 0 0 24px; font-size: 13px; }
.login-card .sub { line-height: 1.6; }

/* "or" divider between the passkey button and the email-code form */
.or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--ink-3); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

.code-input {
  text-align: center; font-size: 26px; letter-spacing: .38em;
  font-variant-numeric: tabular-nums; padding: 12px 8px; text-indent: .38em;
}

/* ------------------------------------------------------------------ shell */

.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--rule);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.sidebar .brand img { width: 30px; }
.sidebar .brand span { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px;
  color: var(--ink-2); font-weight: 500; font-size: 14px;
}
.sidebar a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.sidebar a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { padding: 0 10px; font-size: 12px; color: var(--ink-3); }
.sidebar .foot button {
  background: none; border: 0; color: var(--ink-3); padding: 0; cursor: pointer;
  font: inherit; text-decoration: underline;
}

main { padding: 28px 32px 80px; max-width: 1180px; width: 100%; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 24px;
}
.page-head h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.page-head .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px;
  border-radius: 8px; border: 1px solid var(--rule-strong); background: var(--surface);
  color: var(--ink); font: 500 14px/1 inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-danger { color: var(--late); border-color: var(--rule-strong); }
.btn-danger:hover { background: var(--late-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-link { border: 0; background: none; color: var(--brand-ink); padding: 4px 6px; }
.btn-link:hover { background: none; text-decoration: underline; }

input, select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--rule-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: 14px/1.4 inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand);
}
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-width: 150px; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }
.card + .card { margin-top: 20px; }

.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; }
.stat .label { font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: .02em; }
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .meta { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.stat.alert .value { color: var(--late); }

/* ----------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--rule);
  background: var(--surface-2); white-space: nowrap;
}
tbody td { padding: 14px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.empty { padding: 48px 24px; text-align: center; color: var(--ink-3); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
}
.pill-paid  { background: var(--paid-soft); color: var(--paid); }
.pill-sent  { background: var(--open-soft); color: var(--open); }
.pill-late  { background: var(--late-soft); color: var(--late); }
.pill-draft { background: var(--draft-soft); color: var(--ink-2); }
.pill-void  { background: var(--draft-soft); color: var(--ink-3); text-decoration: line-through; }

.late-text { color: var(--late); font-weight: 600; }

/* ------------------------------------------------------------------ chart */

.chart-card { padding: 22px 24px 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.chart-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.chart { width: 100%; height: 250px; margin-top: 14px; overflow: visible; }
.chart .grid-line { stroke: var(--rule); stroke-width: 1; }
.chart .axis-text { fill: var(--ink-3); font-size: 11px; }
.chart .bar-label { fill: var(--ink-2); font-size: 10.5px; font-weight: 600; }
.chart g:hover .bar-label { fill: var(--ink); }

/* ------------------------------------------------------- invoice detail */

.detail-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.doc { padding: 40px; background: var(--surface); }
.doc-top { display: flex; justify-content: space-between; gap: 32px; flex-wrap: wrap; }
.doc-top img { width: 92px; height: auto; }
.doc h2 { font-size: 20px; letter-spacing: .05em; margin: 0; }
.doc-grid { display: grid; gap: 32px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 34px 0 28px; }
.doc-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; margin-bottom: 8px; }
.doc dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0; }
.doc dt { color: var(--ink-3); } .doc dd { margin: 0; }
.doc-totals { width: min(300px, 100%); margin-left: auto; margin-top: 20px; }
.doc-totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.doc-totals .grand {
  font-size: 19px; font-weight: 700; border-top: 1px solid var(--rule);
  margin-top: 8px; padding-top: 12px;
}

/* ------------------------------------------------------------- line items */

.items-table td { padding: 8px 6px; }
.items-table input, .items-table select { padding: 7px 9px; }
.items-table .drag { color: var(--ink-3); cursor: grab; user-select: none; }
.item-remove { background: none; border: 0; color: var(--ink-3); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.item-remove:hover { color: var(--late); }

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed; inset: 0; background: rgba(12, 16, 20, .55);
  display: grid; place-items: start center; padding: 40px 20px; overflow-y: auto; z-index: 50;
}

/* An author `display` rule beats the UA stylesheet's `[hidden] { display: none }`,
   so without this the dismissed overlay stays on top of the page and eats every click. */
.modal[hidden], .toast[hidden] { display: none; }
.modal-card {
  width: min(620px, 100%); background: var(--surface); border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3); padding: 26px 28px;
}
.modal-card h2 { margin: 0 0 18px; font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 9px;
  font-size: 14px; font-weight: 500; z-index: 100; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  max-width: min(560px, calc(100vw - 40px));
}
.toast.err { background: var(--late); color: #fff; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--rule); padding: 12px;
  }
  .sidebar .brand { padding: 0 12px 0 4px; }
  .sidebar nav { flex-direction: row; }
  .sidebar .foot { display: none; }
  main { padding: 20px 16px 60px; }
  .doc { padding: 24px 20px; }
}

@media print {
  .sidebar, .actions, .page-head .actions, .toast { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
}
