:root {
  --bg-dark: #0a0b10;
  --bg-card: #12151f;
  --bg-card-hover: #181d2a;
  --bg-card-active: #1e2435;
  --border: #23293a;
  --border-light: #2e364c;
  --border-focus: #6366f1;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --info: #06b6d4;
  --plan-color: #60a5fa;
  --plan-bg: rgba(96, 165, 250, 0.08);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.2);
  --header-height: 64px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header */
header {
  background: rgba(18, 21, 31, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.6rem 1.25rem;
}

.header-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  color: #fff;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.45);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-title span {
  color: var(--primary);
}

.doc-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Calendar Month Selector */
.calendar-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.calendar-controls label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.select-compact {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-xs);
  outline: none;
  cursor: pointer;
}

.select-compact:focus {
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: var(--shadow-glow);
}

.btn-success {
  background: #059669;
  border-color: #059669;
  color: #fff;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.25);
}

.btn-success:hover {
  background: #047857;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-outline.active, .btn-outline:hover {
  background: var(--border);
  color: var(--text-main);
  border-color: var(--primary);
}

/* Nav Tabs - Modern Scrollable Pill Strip */
.nav-tabs-wrapper {
  background: rgba(10, 11, 16, 0.95);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 57px;
  z-index: 90;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.nav-tabs {
  display: flex;
  gap: 0.5rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

/* Main Container */
main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem;
  width: 100%;
  flex: 1;
}

/* KPI Summary Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-light);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Problematic Alert */
.problem-section {
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.problem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
}

.problem-card {
  background: linear-gradient(145deg, rgba(239, 68, 68, 0.09), rgba(18, 21, 31, 0.98));
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.problem-badge {
  position: absolute;
  top: 0.85rem;
  right: 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--danger);
  background: var(--danger-bg);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.problem-supp {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.problem-metrics {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.5rem;
}

.problem-metric-item {
  display: flex;
  flex-direction: column;
}

.problem-metric-item .val {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* Card Section */
.content-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.search-input {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  width: 240px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

/* Tables & Sticky Headers */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 600px;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  text-align: left;
}

th, td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}

th {
  background: #151824;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  z-index: 5;
}

tr:hover td {
  background: var(--bg-card-hover);
}

.cell-num {
  font-family: var(--font-mono);
  text-align: right;
}

/* STICKY COLUMNS FOR SUMMARY TABLE */
#summaryTable th:nth-child(1),
#summaryTable td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--bg-card);
  min-width: 36px;
  text-align: center;
}
#summaryTable th:nth-child(2),
#summaryTable td:nth-child(2) {
  position: sticky;
  left: 36px;
  z-index: 4;
  background: var(--bg-card);
  border-right: 2px solid var(--border);
  min-width: 80px;
}
#summaryTable th:nth-child(1),
#summaryTable th:nth-child(2) {
  z-index: 10;
  background: #151824;
}

/* STICKY COLUMNS FOR MATRIX TABLE (PUR/FR/01-05) */
.matrix-table th:nth-child(1),
.matrix-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 6;
  background: var(--bg-card);
  width: 36px;
  min-width: 36px;
  text-align: center;
}

.matrix-table th:nth-child(2),
.matrix-table td:nth-child(2) {
  position: sticky;
  left: 36px;
  z-index: 6;
  background: var(--bg-card);
  width: 140px;
  min-width: 140px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-table th:nth-child(3),
.matrix-table td:nth-child(3) {
  position: sticky;
  left: 176px;
  z-index: 6;
  background: var(--bg-card);
  width: 110px;
  min-width: 110px;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-table th:nth-child(4),
.matrix-table td:nth-child(4) {
  position: sticky;
  left: 286px;
  z-index: 6;
  background: var(--bg-card);
  width: 60px;
  min-width: 60px;
  text-align: center;
  border-right: 2px solid var(--border-light) !important;
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.35);
}

.matrix-table th:nth-child(1),
.matrix-table th:nth-child(2),
.matrix-table th:nth-child(3),
.matrix-table th:nth-child(4) {
  z-index: 15;
  background: #151824;
}

.matrix-table tr:hover td:nth-child(1),
.matrix-table tr:hover td:nth-child(2),
.matrix-table tr:hover td:nth-child(3),
.matrix-table tr:hover td:nth-child(4) {
  background: var(--bg-card-hover);
}

.matrix-table th, .matrix-table td {
  padding: 0.4rem 0.45rem;
  font-size: 0.78rem;
  min-width: 44px;
  text-align: center;
}

.matrix-table input {
  width: 54px;
  height: 32px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-align: right;
  padding: 2px 4px;
  transition: all 0.15s;
}

.matrix-plan-input {
  color: var(--plan-color) !important;
}

.matrix-plan-input:focus {
  background: #131d33;
  border-color: #3b82f6 !important;
  outline: none;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.matrix-act-input {
  color: var(--success) !important;
}

.matrix-act-input:focus {
  background: #0f2720;
  border-color: var(--success) !important;
  outline: none;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

/* Quick Jump Week Bar */
.matrix-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.quick-jump-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-jump-group::-webkit-scrollbar {
  display: none;
}

.jump-chip {
  padding: 0.25rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.jump-chip:hover {
  background: var(--border);
  color: var(--text-main);
  border-color: var(--primary);
}

/* Quick Increment Chips for Entry Form */
.quick-qty-chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.qty-chip {
  padding: 2px 7px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.15s;
}

.qty-chip:hover {
  background: var(--primary-glow);
  border-color: var(--primary);
  color: #fff;
}

/* Entry Form */
.entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  align-items: end;
  background: #141724;
  padding: 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.form-control {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  outline: none;
  min-height: 40px;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

/* Progress bar & badges */
.progress-bar-bg {
  width: 70px;
  height: 6px;
  background: #23293a;
  border-radius: var(--radius-full);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
}

.status-success {
  background: var(--success-bg);
  color: var(--success);
}

.status-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.status-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-card {
  transform: translateY(0);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #1a1f30;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
  border-radius: var(--radius-md);
  padding: 0.8rem 1.25rem;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  z-index: 2000;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Mobile Quick Nav (Floating Bottom Action Bar) */
.mobile-bottom-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(18, 21, 31, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom));
  z-index: 95;
  justify-content: space-around;
  align-items: center;
}

.bottom-bar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}

.bottom-bar-btn.active {
  color: var(--primary);
}

.bottom-bar-btn .icon {
  font-size: 1.15rem;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: auto;
}

/* RESPONSIVE MEDIA QUERIES */
@media (max-width: 992px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  header {
    padding: 0.5rem 1rem;
  }
  .header-container {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }
  .brand {
    justify-content: space-between;
  }
  .header-actions {
    justify-content: space-between;
    width: 100%;
  }
  .calendar-controls {
    flex: 1;
    justify-content: space-between;
  }
  .select-compact {
    flex: 1;
  }
  .nav-tabs-wrapper {
    top: auto;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }
  .stat-card {
    padding: 0.75rem 0.85rem;
  }
  .stat-value {
    font-size: 1.25rem;
  }
  .search-input {
    width: 100%;
  }
  .entry-form {
    grid-template-columns: 1fr;
  }
  .mobile-bottom-bar {
    display: flex;
  }
  main {
    padding: 0.85rem 0.85rem 5rem 0.85rem; /* extra space for bottom bar */
  }
  .toast {
    bottom: 5rem;
    left: 1rem;
    right: 1rem;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .brand-title {
    font-size: 1.05rem;
  }
  .btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.75rem;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  .stat-value {
    font-size: 1.15rem;
  }
  .matrix-table input {
    width: 46px;
    height: 34px;
    font-size: 0.75rem;
  }
}
