/* Greig ERP — single stylesheet, no build step. */
:root {
  --green: #218D49; --green-dark: #186b37; --green-soft: #e6f3eb;
  --slate: #535F61; --ink: #1f2628; --muted: #6b7678; --line: #dfe5e6;
  --bg: #f3f5f6; --card: #ffffff; --sidebar: #1c2a2e; --sidebar-ink: #c9d4d6;
  --amber: #b7791f; --amber-soft: #fdf3e1; --red: #b42318; --red-soft: #fdecea;
  --blue: #2a6fb0; --blue-soft: #e6f0fa; --grey-soft: #eef1f2;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; font-weight: 650; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.muted { font-size: .9rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
code { background: var(--grey-soft); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* ---- layout ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: 0 0 236px; background: var(--sidebar); color: var(--sidebar-ink); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; color: #fff; font-weight: 700; letter-spacing: .01em; }
.brand .logo { width: 30px; height: 30px; border-radius: 50%; background: var(--green); display: grid; place-items: center; font-size: .8rem; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-ink); font-size: .72rem; }
.nav-group { margin-top: .9rem; }
.nav-group > span { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #8a9a9d; padding: 0 .5rem .3rem; }
.nav-group a { display: flex; align-items: center; gap: .55rem; padding: .42rem .6rem; border-radius: 7px; color: var(--sidebar-ink); font-size: .92rem; }
.nav-group a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav-group a.active { background: var(--green); color: #fff; }
.nav-group a .count { margin-left: auto; background: rgba(255,255,255,.14); border-radius: 999px; font-size: .7rem; padding: .05rem .45rem; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .user { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.topbar .user .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head .crumbs { font-size: .82rem; color: var(--muted); margin-bottom: .25rem; }
.page-head .crumbs a { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.menu-toggle { display: none; }

/* ---- cards & grid ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.card.tight { padding: 0; overflow: hidden; }
.card.tight > table { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.card.tight .card-head { padding: .9rem 1.25rem; border-bottom: 1px solid var(--line); margin: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; box-shadow: var(--shadow); }
.stat .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .15rem; }
.stat .sub { font-size: .8rem; color: var(--muted); }
.stat.warn .value { color: var(--amber); } .stat.danger .value { color: var(--red); } .stat.ok .value { color: var(--green-dark); }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: #fafbfb; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions-cell { white-space: nowrap; text-align: right; }
.table-wrap { overflow-x: auto; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* ---- badges ---- */
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--grey-soft); color: var(--slate); white-space: nowrap; text-transform: capitalize; }
.badge.green, .badge.active, .badge.approved, .badge.completed, .badge.done, .badge.issued, .badge.retired, .badge.reimbursed, .badge.valid, .badge.closed, .badge.ok, .badge.mobilised, .badge.in_stock, .badge.installed { background: var(--green-soft); color: var(--green-dark); }
.badge.amber, .badge.submitted, .badge.in_progress, .badge.awaiting_report, .badge.partially_issued, .badge.partially_retired, .badge.expiring, .badge.mobilising, .badge.scheduled, .badge.on_hold, .badge.planned, .badge.standby, .badge.high { background: var(--amber-soft); color: var(--amber); }
.badge.red, .badge.rejected, .badge.expired, .badge.cancelled, .badge.fault, .badge.faulty, .badge.blocked, .badge.urgent, .badge.overdue { background: var(--red-soft); color: var(--red); }
.badge.blue, .badge.open, .badge.planning, .badge.approved-blue, .badge.invoiced, .badge.todo, .badge.draft, .badge.returned, .badge.demobilised { background: var(--blue-soft); color: var(--blue); }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .48rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: .9rem; font-weight: 500; cursor: pointer; line-height: 1.2; text-decoration: none; }
.btn:hover { background: #f7f9f9; text-decoration: none; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); border-color: #f1c2bd; }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: .3rem .6rem; font-size: .8rem; }
.btn.link { border: 0; background: transparent; color: var(--green-dark); padding: .2rem .3rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.25rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--slate); margin-bottom: .25rem; }
.field label .req { color: var(--red); }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=number], .field input[type=date], .field input[type=datetime-local], .field input[type=file], .field select, .field textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid #cfd6d8; border-radius: 8px; background: #fff; font: inherit; color: var(--ink); }
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid rgba(33,141,73,.25); border-color: var(--green); }
.field .help { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.field .error { font-size: .78rem; color: var(--red); margin-top: .2rem; }
.field.check { display: flex; align-items: center; gap: .5rem; padding-top: 1.4rem; }
.field.check label { margin: 0; font-weight: 500; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 160px; }
.filters .field label { font-size: .72rem; }
.filters input, .filters select { padding: .4rem .55rem !important; }

/* ---- alerts ---- */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .92rem; border: 1px solid transparent; }
.alert.success { background: var(--green-soft); color: var(--green-dark); border-color: #bfe3cb; }
.alert.error { background: var(--red-soft); color: var(--red); border-color: #f1c2bd; }
.alert.warning { background: var(--amber-soft); color: var(--amber); border-color: #f2dcb0; }
.alert.info { background: var(--blue-soft); color: var(--blue); border-color: #c5dcf2; }
.alert ul { margin: .25rem 0 0 1rem; padding: 0; }

/* ---- detail lists ---- */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; font-size: .92rem; margin: 0; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; }
.kv { display: flex; gap: 2rem; flex-wrap: wrap; }
.progress { height: 8px; background: var(--grey-soft); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--green); }
.pill-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; }
.tabs a.active { color: var(--green-dark); border-color: var(--green); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ---- status board (kanban-ish) ---- */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.board .col { background: var(--grey-soft); border-radius: var(--radius); padding: .75rem; }
.board .col h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .6rem; }
.board .item { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .5rem; font-size: .88rem; }
.board .item .ref { font-size: .74rem; color: var(--muted); }

/* ---- pagination ---- */
.pagination { display: flex; gap: .3rem; justify-content: flex-end; padding: .75rem 1rem; font-size: .85rem; align-items: center; }
.pagination a, .pagination span { padding: .3rem .6rem; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }
.pagination span.current { background: var(--green); color: #fff; border-color: var(--green); }
.pagination span.disabled { color: var(--muted); }
.pagination .info { border: 0; background: transparent; margin-right: auto; color: var(--muted); }

/* ---- line-item editors ---- */
table.lines td { padding: .35rem .4rem; }
table.lines input, table.lines select { width: 100%; padding: .4rem .5rem; border: 1px solid #cfd6d8; border-radius: 6px; font: inherit; }
table.lines td.rm { width: 36px; text-align: center; }

/* ---- signature pad ---- */
.sigpad { border: 1px dashed #b7c1c3; border-radius: 8px; background: #fff; width: 100%; height: 160px; touch-action: none; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); }
.login-card .brand { color: var(--ink); padding: 0 0 1.25rem; }
.login-card .brand small { color: var(--muted); }
.login-card .field { margin-bottom: 1rem; }

/* ---- print ---- */
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .actions, .no-print, .pagination { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; break-inside: avoid; }
  .print-only { display: block; }
  body { background: #fff; font-size: 12px; }
  .doc-head { display: flex; justify-content: space-between; border-bottom: 2px solid var(--green); padding-bottom: .5rem; margin-bottom: 1rem; }
}
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--green); padding-bottom: .75rem; margin-bottom: 1rem; }
.doc-head .co { font-weight: 700; font-size: 1.2rem; color: var(--green-dark); }
.doc-head .meta { text-align: right; font-size: .85rem; color: var(--muted); }
.sig-box { border-top: 1px solid var(--ink); margin-top: 2.5rem; padding-top: .3rem; font-size: .8rem; }

/* ---- responsive ---- */
@media (max-width: 960px) {
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .sidebar { position: fixed; left: -260px; transition: left .2s; z-index: 50; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 1rem; }
  .dl { grid-template-columns: 1fr; gap: .1rem .5rem; }
  .dl dt { margin-top: .4rem; }
}
