/* KBSteel ERP - Design System Stylesheet
   Steel-blue anchor, warm neutrals, OKLCH palette
   For bright plant offices, 15" monitors, 8hr daily use
   ---------------------------------------------------- */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Roboto+Slab:wght@600;700&display=swap');

/* ========== 1. Custom Properties ========== */
:root {
  /* Brand palette */
  --primary: #0b4f86;
  --primary-hex: #0b4f86;
  --primary-dark: #083b63;
  --primary-light: #e8f2fb;
  --primary-light-hex: #e8f2fb;
  --accent-green: #14804a;
  --accent-green-hex: #14804a;
  --warning-amber: #8a5a00;
  --warning-amber-hex: #b7791f;
  --danger-red: #a21712;
  --danger-red-hex: #b42318;
  --surface: #f3f6fa;
  --surface-hex: #f3f6fa;
  --surface-muted: #edf1f6;
  --surface-raised: #ffffff;
  --surface-raised-hex: #ffffff;
  --text-primary: #1f2937;
  --text-primary-hex: #1f2937;
  --text-secondary: #596574;
  --text-secondary-hex: #596574;
  --border: #d8e0ea;
  --border-hex: #d8e0ea;

  /* Stage colors */
  --stage-fab-bg: oklch(92% 0.04 250);
  --stage-fab-fg: oklch(35% 0.12 250);
  --stage-paint-bg: oklch(92% 0.04 75);
  --stage-paint-fg: oklch(40% 0.12 75);
  --stage-dispatch-bg: #eef6ff;
  --stage-dispatch-fg: #0b4f86;
  --stage-complete-bg: oklch(92% 0.04 145);
  --stage-complete-fg: oklch(35% 0.12 145);

  /* Typography */
  --font-body: Aptos, "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-heading: "Roboto Slab", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Spacing scale */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;

  /* Layout */
  --max-width: 1400px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.06);
  --shadow: 0 8px 24px rgba(16,24,40,0.08);
  --shadow-lg: 0 16px 40px rgba(16,24,40,0.12);

  /* Bootstrap overrides */
  --bs-primary: var(--primary-hex);
  --bs-danger: var(--danger-red-hex);
  --bs-success: var(--accent-green-hex);
  --bs-warning: var(--warning-amber-hex);
}

/* ========== 2. Base Styles ========== */
html, body { height: 100%; overflow-x: hidden; }

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--surface);
  color: var(--text-primary);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0;
  line-height: 1.35;
}

h1, .h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.5rem; }
h4 { font-size: 1.15rem; }
h5 { font-size: 1.05rem; font-weight: 700; color: var(--primary); }
p, small, .text-muted { line-height: 1.5; }

a { color: var(--primary); }
a:hover { color: var(--primary); opacity: 0.85; }

::selection { background: var(--primary-light); }

*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Targeted micro-interactions (scoped, not blanket *) */
.btn, .nav-link, .form-control, .form-select, .card, .badge, .stat-card, .activity-item, .file-drop, a {
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

/* ========== 3. Layout ========== */
.container-fluid.main-container {
  padding: 0;
  max-width: var(--max-width);
  margin: 0;
}

.main-container > .d-flex.justify-content-between > div:last-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* ========== 4. Layout: Top Bar + Sidebar ========== */

/* Top bar - slim header */
.kb-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--primary);
  color: oklch(98% 0.003 250);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  z-index: 1030;
  border-bottom: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 1px 0 rgba(16,24,40,0.08);
}

.kb-topbar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: oklch(98% 0.003 250);
  text-decoration: none;
  letter-spacing: 0;
}

.kb-topbar .brand:hover {
  color: oklch(98% 0.003 250);
  opacity: 0.9;
}

.kb-topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

/* Sidebar */
.kb-sidebar {
  position: fixed;
  top: 60px;
  left: 0;
  bottom: 0;
  width: 240px;
  background: #f8fafc;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--sp-5) 0;
  z-index: 1020;
  transition: transform 0.2s ease;
}

.kb-sidebar .nav-group-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
}

.kb-sidebar .nav-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0.5rem 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  margin: 0 var(--sp-2) var(--sp-1);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.kb-sidebar .nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #d4e7f7;
}

.kb-sidebar .nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);
}

.kb-sidebar .nav-divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-3) var(--sp-5);
}

.kb-sidebar .nav-item.nav-logout {
  color: var(--danger-red);
}

.kb-sidebar .nav-item.nav-logout:hover {
  background: oklch(95% 0.04 25);
}

/* Main content area */
.kb-main {
  margin-left: 240px;
  margin-top: 60px;
  padding: var(--sp-6);
  min-height: calc(100vh - 60px);
}

/* Hamburger toggle for mobile */
.kb-hamburger {
  display: none;
  background: none;
  border: none;
  color: oklch(98% 0.003 250);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

/* Sidebar overlay on mobile */
.kb-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: oklch(0% 0 0 / 0.4);
  z-index: 1019;
}

/* Mobile: sidebar slides in from left */
@media (max-width: 991px) {
  .kb-hamburger { display: block; }

  .kb-sidebar {
    transform: translateX(-100%);
  }

  .kb-sidebar.open {
    transform: translateX(0);
  }

  .kb-sidebar-overlay.open {
    display: block;
  }

  .kb-main {
    margin-left: 0;
  }
}

/* Old navbar - hidden (kept for backward compat until all pages migrate) */
.kb-navbar { display: none; }

/* Role badge (used in topbar) */
.role-badge {
  background: rgba(255, 255, 255, 0.16);
  color: oklch(98% 0.003 250);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-weight: 600;
  font-size: 0.8rem;
  border: 1px solid rgba(255,255,255,0.18);
}

/* ========== 5. Cards ========== */
.card, .card.kb-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-2);
}

.card.shadow-sm,
.card.border-0 {
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-sm) !important;
}

.card-body {
  padding: var(--sp-5);
}

.card > .card-header {
  margin: calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)) 0;
}

.card.p-0,
.card-body.p-0 {
  overflow: hidden;
}

.card:not(:has(> .card-body)):not(:has(> .table-responsive)):not(.p-0) {
  padding: var(--sp-5);
}

.modal-content {
  padding: var(--sp-3);
}

.modal-content .modal-header,
.modal-content .modal-body,
.modal-content .modal-footer {
  padding-left: var(--sp-5);
  padding-right: var(--sp-5);
}

.alert {
  padding: var(--sp-4) var(--sp-5);
}

.card > .table-responsive:first-child:last-child {
  border-radius: var(--radius);
}

.kb-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
}

/* ========== 6. Tables ========== */
.table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin-bottom: 0;
}

.table thead th {
  background: var(--surface-muted);
  color: #4d5968;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.82rem 0.9rem;
  border-bottom: 1px solid #c8d2df;
  position: sticky;
  top: 0;
  z-index: 2;
}

.table tbody tr {
  background: var(--surface-raised);
}

.table tbody tr:nth-child(even) {
  background: #fbfcfe;
}

.table tbody tr:hover > * {
  background: #f1f7fd;
}

.table th, .table td {
  vertical-align: middle;
  padding: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.table td { font-size: 0.9rem; color: var(--text-primary); }
.table tbody tr:last-child > * { border-bottom: 0; }

/* Right-align numeric columns (apply .text-end or use this) */
.table .col-number,
.table td[data-type="number"] {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}

/* ========== 7. Numbers & Mono ========== */
.kb-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: 0;
}

/* ========== 8. Stage Indicators (background tint, no side-stripe) ========== */
.stage-fabrication { background: var(--stage-fab-bg); color: var(--stage-fab-fg); }
.stage-painting    { background: var(--stage-paint-bg); color: var(--stage-paint-fg); }
.stage-dispatch    { background: var(--stage-dispatch-bg); color: var(--stage-dispatch-fg); }
.stage-completed   { background: var(--stage-complete-bg); color: var(--stage-complete-fg); }

/* ========== 9. Status Badges ========== */
.badge {
  padding: 0.35em 0.65em;
  font-weight: 600;
  font-size: 0.75rem;
  border-radius: 999px;
}

.badge-status { padding: 0.35em 0.75em; border-radius: 999px; font-weight: 600; }
.badge-success, .status-completed { background: var(--stage-complete-bg); color: var(--stage-complete-fg); }
.badge-warning, .status-inprogress { background: var(--stage-paint-bg); color: var(--stage-paint-fg); }
.badge-danger { background: oklch(92% 0.04 25); color: oklch(40% 0.15 25); }

/* ========== 10. Stat Cards (no hero-metric) ========== */
.stat-card, .kpi-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-top-width: 1px !important;
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
}

.stat-card .stat-label,
.kpi-card small {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
  display: block;
}

.stat-card .stat-value,
.kpi-card h3 {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.75rem;
  font-weight: 700;
  margin: var(--sp-1) 0;
  color: var(--text-primary);
}

.kpi-card .badge { font-size: 0.75rem; padding: 0.3em 0.55em; }

/* ========== 11. Buttons ========== */
.btn {
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 40px;
  padding: 0.5rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  line-height: 1.35;
  border-width: 1px;
}

.btn-primary, .btn-kb {
  background: var(--primary);
  color: oklch(98% 0.003 250);
  border-color: var(--primary);
}

.btn-primary:hover, .btn-kb:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: oklch(98% 0.003 250);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(7,90,159,0.16);
}

.btn-outline-primary, .btn-kb-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  border-radius: var(--radius);
}

.btn-outline-primary:hover, .btn-kb-outline:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger-red);
  color: oklch(98% 0.003 250);
  border: none;
}

.btn-danger:hover {
  background: oklch(48% 0.2 25);
  color: oklch(98% 0.003 250);
}

.btn-success {
  background: var(--accent-green);
  color: oklch(98% 0.003 250);
  border-color: var(--accent-green);
}

.btn-success:hover {
  background: #0f6b3e;
  border-color: #0f6b3e;
  color: #fff;
  transform: translateY(-1px);
}

.btn-warning {
  background: #f6c343;
  border-color: #f0b429;
  color: #342400;
}

.btn-warning:hover {
  background: #e8ad19;
  border-color: #d99b0b;
  color: #1f1600;
}

.btn-secondary,
.btn-outline-secondary {
  color: #495464;
  border-color: #b8c3d1;
}

.btn-outline-secondary:hover {
  background: #eef2f7;
  border-color: #94a3b8;
  color: var(--text-primary);
}

.btn-sm {
  min-height: 36px;
  padding: 0.42rem 0.72rem;
  font-size: 0.82rem;
}

.btn-group-sm > .btn,
.table .btn-sm {
  min-height: 34px;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

/* Touch target sizing */
.btn, .btn-kb, .btn-kb-outline { min-height: 44px; padding-top: 0.55rem; padding-bottom: 0.55rem; }

/* ========== 12. Forms ========== */
.form-control, .form-select {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.62rem 0.78rem;
  font-size: 0.9rem;
  background: var(--surface-raised);
  color: var(--text-primary);
  min-height: 42px;
}

.form-label {
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  line-height: 1.25;
}

.form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 4px rgba(7,90,159,0.13);
  border-color: var(--primary);
  outline: none;
  background: #fff;
}

.file-drop {
  border: 2px dashed var(--border);
  padding: var(--sp-4);
  border-radius: var(--radius);
  text-align: center;
  background: var(--surface);
}

.file-drop:hover { border-color: var(--primary); background: var(--primary-light); }

/* ========== 13. Alerts (tinted backgrounds, no side-stripe) ========== */
.instruction-box {
  background: oklch(95% 0.03 250);
  border: 1px solid oklch(85% 0.05 250);
  padding: var(--sp-4);
  border-radius: var(--radius);
}

.instruction-meta { font-size: 0.875rem; color: var(--text-secondary); }

.alert-warning, .low-stock {
  background: oklch(95% 0.04 75);
  color: oklch(35% 0.1 75);
  border: 1px solid oklch(88% 0.06 75);
  border-radius: var(--radius);
}

.alert-danger {
  background: oklch(95% 0.04 25);
  color: oklch(35% 0.12 25);
  border: 1px solid oklch(88% 0.06 25);
  border-radius: var(--radius);
}

.alert-success {
  background: var(--stage-complete-bg);
  color: var(--stage-complete-fg);
  border: 1px solid oklch(85% 0.05 145);
  border-radius: var(--radius);
}

.alert-info {
  background: var(--primary-light);
  color: oklch(35% 0.1 250);
  border: 1px solid oklch(85% 0.04 250);
  border-radius: var(--radius);
}

/* Activity items (used in index.html) - tinted, no side-stripe */
.activity-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  margin-bottom: var(--sp-2);
}

.kb-empty-state {
  border: 1px dashed #c5d0de;
  border-radius: var(--radius);
  background: #f8fbfe;
  color: var(--text-secondary);
  padding: var(--sp-6);
  text-align: center;
}

.kb-empty-state i {
  display: block;
  color: #8a99ab;
  font-size: 1.6rem;
  margin-bottom: var(--sp-2);
}

.kb-loading-surface {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  color: var(--text-secondary);
  background: #f8fbfe;
  border: 1px dashed #c5d0de;
  border-radius: var(--radius);
}

#globalLoader {
  backdrop-filter: blur(2px);
}

#globalLoader .spinner-border {
  width: 2.25rem;
  height: 2.25rem;
}

.modal-content,
.dropdown-menu {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.dropdown-menu {
  padding: var(--sp-2);
}

.dropdown-item {
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
}

.nav-tabs {
  border-color: var(--border);
  gap: var(--sp-1);
}

.nav-tabs .nav-link {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-secondary);
  font-weight: 600;
}

.nav-tabs .nav-link.active {
  color: var(--primary);
}

/* ========== 14. Utilities ========== */
.mb-10 { margin-bottom: 10px; }
.mt-10 { margin-top: 10px; }
.p-12  { padding: 12px; }
.small-muted { color: var(--text-secondary); font-size: 0.875rem; }

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

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }

/* ========== 15. Responsive ========== */
@media (max-width: 768px) {
  .main-container > .d-flex.justify-content-between,
  .main-container > .d-flex.justify-content-between.align-items-center,
  .main-container > .d-flex.justify-content-between.align-items-start {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: var(--sp-2);
  }

  h1, .h1 { font-size: 1.65rem; }
  h2 { font-size: 1.3rem; }
  .kb-main { padding: var(--sp-4); }
  .btn { width: auto; }
  .main-container > .d-flex.justify-content-between > .d-flex,
  .main-container > .d-flex.justify-content-between > div:last-child {
    width: 100%;
    flex-wrap: wrap;
  }
  .main-container > .d-flex.justify-content-between > .d-flex .btn,
  .main-container > .d-flex.justify-content-between > div:last-child .btn {
    flex: 1 1 150px;
  }
  .form-control, .form-select { width: 100% !important; }
  .kpi-card { text-align: left; }
  table { font-size: 0.85rem; }
  .grid-3 { grid-template-columns: 1fr; }
  .container-fluid.main-container { padding-left: 12px; padding-right: 12px; }
  .card-body { padding: var(--sp-4); }
  .table th, .table td { padding: 0.75rem; }
  .role-badge { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kb-topbar .brand { font-size: 0.95rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ========== 16. Print Styles ========== */
@media print {
  body { background: var(--surface-raised); color: var(--text-primary); font-size: 11pt; }
  .kb-navbar, .kb-topbar, .kb-sidebar, .kb-sidebar-overlay, .kb-hamburger,
  .btn, .btn-kb, .btn-kb-outline, .file-drop, nav { display: none !important; }
  .kb-main { margin-left: 0; margin-top: 0; }
  .card, .card.kb-card, .stat-card, .kpi-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
  .table thead th { background: #eee; }
  .table tbody tr { background: var(--surface-raised); }
  a { color: var(--text-primary); text-decoration: none; }
  .container-fluid.main-container { max-width: 100%; padding: 0; }
}
