/* Jobwork Management System - UI stylesheet (no external framework) */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

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

/* ------------------------------------------------------------------ layout */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 18px 20px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #1e293b;
  letter-spacing: .3px;
}
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; color: #64748b; margin-top: 2px; }
.sidebar nav { padding: 8px 0 24px; flex: 1; }
.sidebar .group-label {
  padding: 14px 20px 6px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #475569;
}
.sidebar a.nav-link {
  display: block;
  padding: 8px 20px;
  color: var(--sidebar-text);
  font-size: 13px;
}
.sidebar a.nav-link:hover { background: #172033; color: #fff; text-decoration: none; }
.sidebar a.nav-link.active { background: var(--sidebar-active); color: #fff; border-left: 3px solid var(--primary); padding-left: 17px; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.topbar .user-chip { font-size: 12.5px; color: var(--text-muted); }
.topbar .user-chip strong { color: var(--text); }

.content { padding: 22px 24px 60px; }

/* ------------------------------------------------------------------ utilities */

.row { display: flex; flex-wrap: wrap; gap: 16px; }
.col { flex: 1; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 100; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex !important; }
}

.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.hidden { display: none !important; }
.flex { display: flex; } .flex.between { justify-content: space-between; } .flex.center { align-items: center; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }

/* ------------------------------------------------------------------ card */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card > .card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card > .card-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.card > .card-body { padding: 18px; }
.card > .card-body.tight { padding: 0; }

/* KPI cards */
.kpi { padding: 16px 18px; }
.kpi .kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.kpi .kpi-value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi.accent-blue { border-top: 3px solid var(--primary); }
.kpi.accent-green { border-top: 3px solid var(--success); }
.kpi.accent-amber { border-top: 3px solid var(--warning); }
.kpi.accent-red { border-top: 3px solid var(--danger); }

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }

/* ------------------------------------------------------------------ forms */

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 550; }
label.field.req > span::after { content: " *"; color: var(--danger); }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=search], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input.err, select.err { border-color: var(--danger); }
textarea { min-height: 66px; resize: vertical; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 720px) { .form-grid, .form-grid.cols-2 { grid-template-columns: 1fr; } }

.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form label.field { margin-bottom: 0; }
.inline-form label.field > span { margin-bottom: 2px; }

/* --------------------------------------------------------------- quick add */
/* A master-data field (searchable dropdown or plain select) plus its inline
   "+" add-new button, injected by quick-add.js. */
.qa-row { display: flex; gap: 6px; align-items: stretch; }
.qa-row > .dd { flex: 1; min-width: 0; }
.qa-row > select { flex: 1; min-width: 0; }
.qa-row > .qa-add {
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
.qa-hint { font-size: 12px; color: var(--text-muted); margin: -4px 0 12px; }

/* ------------------------------------------------------------------ table */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data thead th {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  position: sticky; top: 0;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
table.data tr.variation { background: var(--warning-soft); }
table.data tr.variation:hover { background: #fef3c7; }
table.data.compact th, table.data.compact td { padding: 6px 9px; }

/* ------------------------------------------------------------------ badges */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.5;
}
.badge.gray { background: #f1f5f9; color: #475569; }
.badge.blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.amber { background: var(--warning-soft); color: var(--warning); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------------------ alerts */

.alert { padding: 11px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; }
.alert.info { background: var(--primary-soft); border-color: #bfdbfe; color: #1e40af; }
.alert.success { background: var(--success-soft); border-color: #bbf7d0; color: #166534; }
.alert.warning { background: var(--warning-soft); border-color: #fde68a; color: #92400e; }
.alert.error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

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

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  z-index: 200;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 960px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .3);
}
.modal.sm { max-width: 460px; }
.modal.lg { max-width: 1160px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head .close { margin-left: auto; background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* wizard steps */
.steps { display: flex; gap: 8px; margin-bottom: 18px; }
.steps .step { flex: 1; text-align: center; font-size: 12px; padding: 6px 4px; border-radius: 6px; background: var(--surface-2); color: var(--text-muted); }
.steps .step.active { background: var(--primary); color: #fff; }
.steps .step.done { background: var(--success-soft); color: var(--success); }

/* ------------------------------------------------------------------ entry grid */

.entry-grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.entry-grid th { background: var(--surface-2); padding: 7px 8px; font-size: 11px; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border); text-align: left; }
.entry-grid td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.entry-grid input, .entry-grid select { padding: 6px 7px; font-size: 13px; }
.entry-grid td.num input { text-align: right; }
.entry-grid .calc { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.entry-grid .calc.warn { color: var(--warning); font-weight: 650; }
.entry-grid tfoot td { font-weight: 700; background: var(--surface-2); }
.entry-grid .row-tools { display: flex; gap: 4px; }
/* Lot pcs/weight quietly mirror pcs/net wt until edited - de-emphasise them so the
   two fields that matter every day (pcs, net wt) read as the primary ones. */
.entry-grid input.c-lot { color: var(--text-muted); background: var(--surface-2); }
.entry-grid input.c-lot:focus { color: var(--text); background: var(--surface); }

.hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}
.hint.warn { color: var(--warning); font-weight: 600; }

/* ------------------------------------------------------------------ searchable dropdown */

.dd { position: relative; }
.dd-input { width: 100%; }
.dd-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .16);
  max-height: 260px; overflow-y: auto;
  z-index: 50;
}
.dd-menu .dd-opt { padding: 8px 10px; cursor: pointer; font-size: 13px; }
.dd-menu .dd-opt:hover, .dd-menu .dd-opt.active { background: var(--primary-soft); }
.dd-menu .dd-opt .sub { display: block; font-size: 11px; color: var(--text-muted); }
.dd-menu .dd-empty { padding: 10px; color: var(--text-muted); font-size: 12px; }

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

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 500; }
.toast {
  min-width: 260px; max-width: 380px;
  padding: 12px 14px;
  border-radius: 9px;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .28);
  animation: toast-in .18s ease-out;
}
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.info { background: #1d4ed8; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ sparkline / flow */

.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 26px; }
.spark i { width: 4px; background: var(--primary); border-radius: 1px; display: block; }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.flow .node { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; text-align: center; min-width: 96px; }
.flow .node .p { font-size: 11px; text-transform: uppercase; color: var(--text-muted); }
.flow .node .w { font-weight: 700; font-variant-numeric: tabular-nums; }
.flow .arrow { color: var(--border-strong); font-size: 18px; }

/* ------------------------------------------------------------------ misc */

.menu-toggle { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }
.loading { padding: 30px; text-align: center; color: var(--text-muted); }

hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

@media print {
  .sidebar, .topbar, .page-actions, .no-print { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: none; }
}
