/*
  Standard Kit — "Paper & Moss"
  Shared visual identity for all ops-console apps (car-workshop, job-order-system,
  mfg-costing, etc). Base tokens + components below are kept in sync with
  standard-kit/kit.css — the job-order-system-specific extensions (notifications,
  sortable columns, stage bars, permission matrix, LPR/SMC grids) live in their
  own section at the bottom, ported onto the same tokens.
*/

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,500;0,600;0,700;1,500&family=Nunito+Sans:wght@400;600;700;800&family=Spline+Sans+Mono:wght@500;600&display=swap');

:root {
  /* Neutrals */
  --bg: #F0F1EB;
  --surface: #FFFFFF;
  --ink: #262E22;
  --muted: #5E6B57;
  --border: #DBDED2;

  /* Sidebar */
  --sidebar-bg: #FFFFFF;
  --sidebar-text: #4B5443;
  --sidebar-active-bg: #E7EEDF;
  --sidebar-border: #DBDED2;

  /* Brand */
  --accent: #4B7A3E;
  --accent-dark: #3B6231;
  --accent-soft: #E7EEDF;
  --accent-ink: #FFFFFF;

  /* Semantic (distinct from brand accent) */
  --success: #1F7A5C;
  --success-soft: #E4F3ED;
  --danger: #A8412E;
  --danger-soft: #FBEAE6;
  --warn: #B08A2E;
  --warn-soft: #FAF1DE;
  --info: #2C6E8E;
  --info-soft: #E7F1F5;

  /* Shape */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 2px 10px rgba(38, 46, 34, 0.08);
  --shadow-lg: 0 8px 28px rgba(38, 46, 34, 0.14);

  /* Type */
  --font-head: 'Lora', Georgia, 'Times New Roman', serif;
  --font-body: 'Nunito Sans', system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: 'Spline Sans Mono', 'SFMono-Regular', Consolas, monospace;

  /* Back-compat aliases — the pre-kit theme's token names, used inline
     (style="color: var(--color-text-muted)") throughout views/. Keeping
     these means every view re-themes automatically without hunting down
     each inline var() usage. New CSS should use the tokens above instead. */
  --color-navy: var(--ink);
  --color-slate: var(--muted);
  --color-bg: var(--bg);
  --color-amber: var(--accent);
  --color-amber-dark: var(--accent-dark);
  --color-border: var(--border);
  --color-text: var(--ink);
  --color-text-muted: var(--muted);
  --color-white: var(--surface);
  --color-success: var(--success);
  --color-danger: var(--danger);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; line-height: 1.25; margin: 0 0 6px; color: var(--ink); }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

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

.text-muted { color: var(--muted); }
.tabular { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: -22px -22px 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-sm { padding: 7px 14px; font-size: 12.5px; }
.btn-sm svg { width: 13px; height: 13px; }
.btn-icon-only { padding: 9px; }
.btn-icon-only svg { width: 16px; height: 16px; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-dark); text-decoration: none; }

.btn-outline { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-outline:hover { background: var(--bg); text-decoration: none; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); text-decoration: none; }

.btn-danger { background: var(--danger); color: #FFFFFF; }
.btn-danger:hover { background: #8E3624; text-decoration: none; }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 13px; color: var(--ink); }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13.5px;
  background: var(--surface);
  color: var(--ink);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.input-icon-wrap { position: relative; }
.input-icon-wrap svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted); }
.input-icon-wrap .form-control { padding-left: 38px; }

/* ---------- Alerts ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #F0CFC6; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: #C6E4D8; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: #EEDDB0; }
.alert-info { background: var(--info-soft); color: var(--info); border-color: #C6DEE7; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.badge-outline { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  padding: 11px 14px;
  text-align: left;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table td { padding: 11px 14px; border-top: 1px solid var(--border); white-space: nowrap; }
table.data-table td.wrap { white-space: normal; }
table.data-table tbody tr:hover { background: var(--bg); }
table.data-table td.actions-cell, table.data-table th.actions-cell { white-space: nowrap; text-align: right; }
table.data-table .row-actions { display: inline-flex; gap: 6px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 12.5px;
}
.pagination a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pagination a:hover { background: var(--bg); text-decoration: none; }

/* ---------- Stat tiles ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat-card .stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.stat-card .stat-value { font-family: var(--font-mono); font-weight: 600; font-size: 24px; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat-card.stat-alert { border-left-color: var(--danger); }
.stat-card.stat-warn { border-left-color: var(--warn); }

/* ---------- Guest layout (login / signup) ---------- */
.guest-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.guest-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px;
}
.guest-logo { text-align: center; margin-bottom: 22px; }
.guest-logo .guest-mark { font-size: 30px; line-height: 1; margin-bottom: 4px; }
.guest-logo h1 { font-size: 20px; margin: 0; }
.guest-logo p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.guest-logo img { max-width: 260px; width: 100%; height: auto; }
.guest-subtitle { margin: 10px 0 0; color: var(--muted); font-weight: 700; font-size: 13.5px; letter-spacing: 0.02em; }
.guest-footnote { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

/* ---------- App shell (authenticated layout) ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 18px 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 20px 18px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
}
.sidebar-brand svg { width: 20px; height: 20px; color: var(--accent); }
.sidebar-brand img { display: block; max-width: 176px; width: 100%; height: auto; }
.sidebar-nav { list-style: none; margin: 0; padding: 0; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 600;
  border-left: 3px solid transparent;
}
.sidebar-nav a svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--accent-dark);
  border-left-color: var(--accent);
  text-decoration: none;
}
.sidebar-section-label {
  padding: 14px 20px 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 13px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.topbar-title { font-family: var(--font-head); font-weight: 600; font-size: 16px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.topbar-user strong { color: var(--ink); }
.content { padding: 24px; }

.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 4px; }
.sidebar-toggle svg { width: 22px; height: 22px; color: var(--ink); }
.sidebar-overlay { display: none; }

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .sidebar-toggle { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 260px;
    max-width: 82vw;
    z-index: 50;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(38, 46, 34, 0.45);
    z-index: 40;
  }
  .app-shell.sidebar-open .sidebar-overlay { display: block; }
}

/* =====================================================================
   job-order-system extensions — notifications, sortable columns, stage
   bars, permission matrix, LPR/SMC grids. Same tokens as the base kit
   above; these components aren't generic enough (yet) to live in the
   shared standard-kit/kit.css, so they're kept local to this app.
   ===================================================================== */

/* Topbar here has no title, just [toggle] [notif bell] ... [user] [logout],
   pushed apart with auto-margins instead of space-between groups. */
.topbar { justify-content: flex-end; }
.sidebar-toggle { margin-right: auto; }
.sidebar-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
  margin: 5px 0;
}

/* Notification bell + dropdown */
.notif-bell-wrap { position: relative; margin-right: auto; }
.notif-bell-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--muted);
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
}
.notif-bell-btn:hover { background: var(--bg); }
.notif-bell-btn svg { width: 20px; height: 20px; }
.notif-bell-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--danger);
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 999px;
  min-width: 16px;
  text-align: center;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 340px;
  max-width: 90vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  overflow: hidden;
}
.notif-dropdown-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
}
.notif-mark-all {
  background: none;
  border: none;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}
.notif-dropdown-list { max-height: 360px; overflow-y: auto; }
.notif-empty { padding: 20px 14px; text-align: center; color: var(--muted); font-size: 13px; }
.notif-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--ink);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg); text-decoration: none; }
.notif-item-unread { background: var(--warn-soft); }
.notif-item-title { font-size: 13px; font-weight: 700; }
.notif-item-msg { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.notif-item-time { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Sortable column headers — server-side (a.sort-link, on paginated tables)
   and client-side (th.sortable-col, on flat tables + the LPR/SMC grids). */
a.sort-link { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
a.sort-link:hover { text-decoration: underline; }
.sort-arrow { font-size: 10px; color: var(--accent-dark); }
th.sortable-col { cursor: pointer; user-select: none; }
th.sortable-col:hover { color: var(--accent-dark); }
th.sortable-col .sort-indicator { display: inline-block; width: 12px; font-size: 10px; color: var(--accent-dark); }

/* Dashboard job-stage distribution bars */
.stage-bar-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.stage-bar-label { width: 220px; flex-shrink: 0; font-size: 13px; }
.stage-bar-track { flex: 1; background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden; }
.stage-bar-fill { height: 100%; border-radius: 999px; }
.stage-bar-count { width: 32px; text-align: right; font-size: 13px; font-weight: 700; color: var(--ink); }

table.data-table td.actions-cell, table.data-table th.actions-cell { white-space: nowrap; }

/* Roles screen permission matrix */
.perm-matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.perm-matrix th, .perm-matrix td { padding: 8px 12px; border-top: 1px solid var(--border); text-align: center; }
.perm-matrix th { text-align: left; background: var(--bg); border-top: none; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }

/* LPR Rental grid — Customer/Start/Coverage/Email/Actions stay pinned to
   the left via position:sticky while the month-checkbox area scrolls. */
.lpr-grid-wrap { overflow-x: auto; max-width: 100%; }
table.lpr-grid { border-collapse: collapse; font-size: 13px; }
table.lpr-grid th, table.lpr-grid td {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}
table.lpr-grid thead th {
  background: var(--bg);
  color: var(--muted);
  text-align: left;
  border-bottom: 2px solid var(--border);
}
table.lpr-grid .sticky-col { position: sticky; z-index: 2; background: var(--surface); }
table.lpr-grid thead .sticky-col { z-index: 3; background: var(--bg); }
table.lpr-grid .col-actions { left: 0; width: 110px; min-width: 110px; }
/* Customer names here are often long strata-management body names
   ("Perbadanan Pengurusan Bersama Vistaria Kondominium") — wrap instead
   of the single-line nowrap other columns use, same as col-email below,
   so long names read in full instead of overlapping the next sticky
   column. */
table.lpr-grid .col-customer { left: 110px; width: 240px; min-width: 240px; white-space: normal; }
table.lpr-grid .col-start { left: 350px; width: 110px; min-width: 110px; }
table.lpr-grid .col-coverage { left: 460px; width: 90px; min-width: 90px; text-align: center; }
table.lpr-grid .col-email { left: 550px; width: 200px; min-width: 200px; white-space: normal; }
/* Extra columns some rows opt into after Email — LPR Rental adds
   Quotation No + Rental Amount; SMC adds Quotation No + Assign To +
   Contract Status. Quotation No's position is shared since it's always
   first regardless of which table renders it; each table's actual last
   column gets the box-shadow via its own class below. */
table.lpr-grid .col-quotation-no { left: 750px; width: 150px; min-width: 150px; }
table.lpr-grid .col-rental-amount { left: 900px; width: 110px; min-width: 110px; text-align: right; box-shadow: 2px 0 4px rgba(38,46,34,0.08); }
table.lpr-grid .col-assigned-to { left: 900px; width: 150px; min-width: 150px; }
table.lpr-grid .col-contract-status { left: 1050px; width: 110px; min-width: 110px; box-shadow: 2px 0 4px rgba(38,46,34,0.08); }
table.lpr-grid .month-col { width: 90px; min-width: 90px; text-align: center; }
table.lpr-grid .month-col.current-month, table.lpr-grid th.current-month { background: var(--warn-soft); }
table.lpr-grid .group-header-row td.sticky-col {
  font-weight: 700;
  color: var(--ink);
  background: var(--bg);
}
table.lpr-grid .group-header-row td { background: var(--bg); border-top: 2px solid var(--border); }
table.lpr-grid .lpr-check { width: 16px; height: 16px; cursor: pointer; }
table.lpr-grid .lpr-check:disabled { cursor: not-allowed; opacity: 0.6; }

/* SMC status dropdown (Blank/SCH/DONE) — reuses the .lpr-grid layout
   above (SMC has no partner grouping, so no .group-header-row here). */
.smc-status-select {
  width: 80px;
  padding: 3px 4px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.smc-status-select:disabled { cursor: not-allowed; opacity: 0.6; }
.smc-status-select.status-blank { background: var(--surface); color: var(--ink); }
.smc-status-select.status-sch { background: var(--warn-soft); color: var(--warn); border-color: #EEDDB0; }
.smc-status-select.status-done { background: var(--success-soft); color: var(--success); border-color: #C6E4D8; }

/* SMC row alert: current month still SCH (not DONE) — flags the whole
   contract row red so it stands out among the rest of the grid. Selector
   specificity is bumped above .sticky-col/.month-col/.current-month so it
   wins regardless of stylesheet order. */
table.lpr-grid tr.row-alert td.sticky-col,
table.lpr-grid tr.row-alert td.month-col { background: var(--danger-soft); }
table.lpr-grid tr.row-alert td.sticky-col { color: var(--danger); }
