/* ============================================================================
   Design system — PO / Billing / Payment tracker
   Plain CSS, no framework (see /docs/ENVIRONMENT_NOTES.md for why). Built as
   a small token system so the look stays consistent across every screen and
   dark mode is a single attribute flip.
   ============================================================================ */

:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-surface-alt: #f9fafb;
  --color-border: #cad1db;
  --color-text: #1a2233;
  --color-text-muted: #475569;
  --color-primary: #2452c8;
  --color-primary-dark: #1a3a99;
  --color-primary-bg: #eaf0fe;

  --color-green: #15803d;
  --color-green-bg: #dcfce7;
  --color-orange: #b45309;
  --color-orange-bg: #fef3c7;
  --color-red: #b91c1c;
  --color-red-bg: #fee2e2;
  --color-grey: #475569;
  --color-grey-bg: #e2e8f0;
  --color-blue: #1d4ed8;
  --color-blue-bg: #dbeafe;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
/* Some mobile browsers auto-shrink or auto-inflate text based on their own
   density heuristics rather than the page's actual CSS — this can make an
   otherwise-normal 13-14px design read as uncomfortably tiny (or need a
   pinch-zoom) on certain phones. Locking it off means the sizes below are
   what actually renders. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

.boot-loading { padding: 40px; text-align: center; color: var(--color-text-muted); }

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

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 8px 14px;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: var(--color-surface-alt); }
button.primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
button.primary:hover { background: var(--color-primary-dark); }
button.danger { background: var(--color-red-bg); border-color: var(--color-red); color: var(--color-red); }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
/* a.small mirrors button.small's look for plain links styled as buttons
   (e.g. the DC-Link link in the topbar, which navigates out to a separate
   app rather than triggering an in-page action). */
a.small {
  display: inline-block;
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 4px 10px;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
a.small:hover { background: var(--color-surface-alt); text-decoration: none; }
button.small { padding: 4px 10px; font-size: 12px; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-primary-bg); border-color: var(--color-primary); }
/* Marks a field that a document scan filled in but wasn't confident about —
   prompts a closer look before saving, without blocking anything. */
input.scan-flag, select.scan-flag { border-color: var(--color-orange); background: var(--color-orange-bg); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--color-text-muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

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

.shell { display: flex; min-height: 100vh; width: 100%; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand { padding: 18px 16px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--color-border); }
.sidebar-brand small { display: block; font-weight: 400; color: var(--color-text-muted); font-size: 11px; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 10px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: var(--radius-sm); color: var(--color-text);
  font-size: 13px; margin-bottom: 2px; text-decoration: none;
}
.sidebar-nav a:hover { background: var(--color-surface-alt); }
.sidebar-nav a.active { background: var(--color-primary-bg); color: var(--color-primary-dark); font-weight: 600; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--color-border); font-size: 12px; color: var(--color-text-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* #company-select sits in a flex row with no defined flex-basis, so the
   generic `select { width: 100% }` rule above resolves against an
   indeterminate container width and collapses to a sliver instead of a
   normal-sized control. Give it its own explicit sizing so it always
   renders (and is tappable) at a normal select width, regardless of how
   long the surrounding company names are. */
#company-select {
  width: auto;
  min-width: 160px;
  max-width: 260px;
  flex: 0 1 auto;
}
@media (max-width: 860px) {
  #company-select { min-width: 0; max-width: 100%; flex: 1 1 160px; }
}

.content { padding: 20px; flex: 1; }

.menu-toggle { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .content { padding: 12px; }
  .topbar { padding: 10px 12px; }
}

/* On a genuinely narrow phone screen, bump the smallest text back up a
   notch — the desktop design leans on 11-13px labels/table text that reads
   fine on a laptop but is uncomfortably small on a phone; this doesn't
   touch layout, just legibility. */
@media (max-width: 480px) {
  html, body { font-size: 15px; }
  label { font-size: 13px; }
  .modal-backdrop { padding: 16px 10px; }
  /* Ad-hoc button/field rows use .flex without wrapping — fine on desktop,
     but on a phone several elements side by side don't fit and would force
     sideways scrolling inside the modal. Wrapping them onto multiple lines
     here keeps every field reachable without horizontal scrolling. */
  .flex { flex-wrap: wrap; }
  .hint, .kv-grid .kv-label, .error-text, .stat-card .label, .stat-card .sub { font-size: 12.5px; }
  .kv-grid .kv-value { font-size: 15px; }
  table { font-size: 13.5px; }
  thead th { font-size: 11.5px; }
  .sidebar-nav a, .sidebar-nav.grouped a { font-size: 14.5px; }
  .stat-card .value { font-size: 23px; }
  .badge { font-size: 12px; }
  button { font-size: 14px; }
  button.small { font-size: 13px; }
  input, select, textarea { font-size: 14.5px; }
  .section-title { font-size: 13.5px; }
}

/* --- Cards / dashboard --- */

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: 16px; cursor: pointer; transition: box-shadow 0.15s, transform 0.1s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card .label { font-size: 12px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat-card .sub { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

.panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px; }
.panel-title { font-weight: 700; font-size: 14px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }

/* --- Tables --- */

.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 600px; }
thead th {
  position: sticky; top: 0; background: var(--color-surface-alt); text-align: left; font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--color-border); color: var(--color-text-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; cursor: pointer;
}
thead th:hover { color: var(--color-text); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-alt); }
tbody tr.clickable { cursor: pointer; }
.table-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
.table-toolbar .search { max-width: 280px; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--color-text-muted); }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 10px 12px; }

/* --- Status badges (spec section 19 colour coding) --- */

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; }
.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-orange { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-grey { background: var(--color-grey-bg); color: var(--color-grey); }
.badge-blue { background: var(--color-blue-bg); color: var(--color-blue); }

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

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: flex; align-items: flex-start; justify-content: center; z-index: 100; overflow-y: auto; padding: 40px 16px; }
.modal { background: var(--color-surface); border-radius: var(--radius-lg); width: 100%; max-width: 640px; box-shadow: var(--shadow-md); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 15px; margin: 0; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 14px; }
.tab { padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--color-text-muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: var(--color-primary); border-color: var(--color-primary); }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; }
.kv-grid .kv-label { font-size: 11px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kv-grid .kv-value { font-size: 14px; font-weight: 600; margin-top: 2px; }

.progress-bar { height: 8px; border-radius: 999px; background: var(--color-grey-bg); overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--color-primary); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow-md); }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.sub { color: var(--color-text-muted); font-size: 13px; margin: 0 0 20px; }

.toast-root { position: fixed; bottom: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--color-text); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow-md); max-width: 320px; }
.toast.error { background: var(--color-red); }
.toast.success { background: var(--color-green); }

.hint { font-size: 12px; color: var(--color-text-muted); }
.error-text { font-size: 12px; color: var(--color-red); margin-top: 4px; }
.muted { color: var(--color-text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.text-right { text-align: right; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.section-title { font-size: 13px; font-weight: 700; margin: 18px 0 8px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.divider { border: none; border-top: 1px solid var(--color-border); margin: 16px 0; }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar-chart .bar { width: 100%; border-radius: 3px 3px 0 0; background: var(--color-primary); min-height: 2px; }
.bar-chart .bar-label { font-size: 10px; color: var(--color-text-muted); white-space: nowrap; }

.donut-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; }
.donut-legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* --- HRMS additions: workflow steppers, sub-nav tabs, permission grid --- */

.stepper { display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 16px; }
.stepper .step {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  color: var(--color-text-muted); background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-right: none;
}
.stepper .step:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.stepper .step:last-child { border-right: 1px solid var(--color-border); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.stepper .step.done { background: var(--color-green-bg); color: var(--color-green); }
.stepper .step.current { background: var(--color-primary-bg); color: var(--color-primary-dark); }

.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; }
.subnav a {
  padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text-muted);
}
.subnav a.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

.perm-grid-wrap { overflow-x: auto; }
.perm-grid { border-collapse: collapse; font-size: 12px; min-width: 900px; }
.perm-grid th, .perm-grid td { border: 1px solid var(--color-border); padding: 6px 8px; text-align: center; white-space: nowrap; }
.perm-grid th { background: var(--color-surface-alt); position: sticky; top: 0; }
.perm-grid td:first-child, .perm-grid th:first-child { text-align: left; position: sticky; left: 0; background: var(--color-surface); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.doc-list { display: flex; flex-direction: column; gap: 6px; }
.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 13px; }
.doc-row.expiring { border-color: var(--color-orange); background: var(--color-orange-bg); }

.payslip-print { background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 24px; max-width: 720px; margin: 0 auto; }
.payslip-print table { width: 100%; font-size: 12.5px; }
.payslip-print .totals-row td { font-weight: 700; border-top: 2px solid var(--color-text); }

textarea { min-height: 70px; resize: vertical; }
