/* TrackOps Design System — Industrial Utilitarian */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

:root {
  --bg-base:      #0f1117;
  --bg-surface:   #171b26;
  --bg-raised:    #1e2333;
  --bg-border:    #2a3045;
  --bg-hover:     #252c3d;

  --text-primary:   #e8eaf0;
  --text-secondary: #8b93a8;
  --text-muted:     #545d73;
  --text-inverse:   #0f1117;

  --accent:       #4d9fff;
  --accent-dim:   #1a3a5c;
  --accent-glow:  rgba(77,159,255,0.15);

  --success:      #3ecf8e;
  --success-dim:  #0d3323;
  --warning:      #f5c842;
  --warning-dim:  #3d2f00;
  --danger:       #f56565;
  --danger-dim:   #3d1515;
  --critical:     #ff4444;

  --priority-low:    #545d73;
  --priority-normal: #4d9fff;
  --priority-high:   #f5c842;
  --priority-urgent: #ff4444;

  --status-draft:            #545d73;
  --status-pending_approval: #9b7fd4;
  --status-approved:         #4d9fff;
  --status-in_production:    #f5c842;
  --status-quality_check:    #fb923c;
  --status-ready_to_ship:    #3ecf8e;
  --status-shipped:          #22c55e;
  --status-completed:        #16a34a;
  --status-cancelled:        #545d73;
  --status-on_hold:          #f59e0b;

  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --radius-sm: 3px;
  --radius-md: 5px;
  --radius-lg: 8px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);

  --transition: 150ms ease;
  --nav-width: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Layout ── */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--nav-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--bg-border);
}

.sidebar-logo .wordmark {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text-primary);
}

.sidebar-logo .wordmark span {
  color: var(--accent);
}

.sidebar-logo .tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 400;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all var(--transition);
  user-select: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { color: var(--accent); background: var(--accent-glow); border-left-color: var(--accent); }

.nav-item .nav-icon { width: 16px; height: 16px; opacity: 0.8; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--bg-border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 26px; height: 26px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .user-name { color: var(--text-secondary); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .user-role { color: var(--text-muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; }

.logout-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px;
  display: flex; align-items: center;
  transition: color var(--transition);
}
.logout-btn:hover { color: var(--danger); }

/* ── Main content ── */
.main-content {
  margin-left: var(--nav-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.page-content {
  padding: 24px;
  flex: 1;
}

/* ── Cards ── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--bg-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.card-body { padding: 18px; }

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}

.stat-card.accent::before { background: var(--accent); }
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }

.stat-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1;
}

.stat-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.845rem;
}

thead th {
  background: var(--bg-raised);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--bg-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text-secondary); }

tbody tr {
  border-bottom: 1px solid var(--bg-border);
  transition: background var(--transition);
  cursor: pointer;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

td {
  padding: 10px 14px;
  color: var(--text-secondary);
  vertical-align: middle;
}

td.primary { color: var(--text-primary); font-weight: 500; }
td.mono { font-family: var(--font-mono); font-size: 0.8rem; }

/* ── Badges / Pills ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.badge-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Status badges */
.badge-draft            { background: #1a1d25; color: var(--status-draft); border: 1px solid var(--status-draft); }
.badge-pending_approval { background: #241d35; color: var(--status-pending_approval); border: 1px solid var(--status-pending_approval); }
.badge-approved         { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); }
.badge-in_production    { background: var(--warning-dim); color: var(--warning); border: 1px solid var(--warning); }
.badge-quality_check    { background: #2d1f0d; color: #fb923c; border: 1px solid #fb923c; }
.badge-ready_to_ship    { background: var(--success-dim); color: var(--success); border: 1px solid var(--success); }
.badge-shipped          { background: #0d2d1a; color: #22c55e; border: 1px solid #22c55e; }
.badge-completed        { background: #0a1f12; color: #16a34a; border: 1px solid #16a34a; }
.badge-cancelled        { background: #1a1d25; color: var(--text-muted); border: 1px solid var(--bg-border); }
.badge-on_hold          { background: #2d2000; color: #f59e0b; border: 1px solid #f59e0b; }

/* Priority badges */
.badge-low    { background: #1a1d25; color: var(--priority-low); border: 1px solid var(--priority-low); }
.badge-normal { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); }
.badge-high   { background: var(--warning-dim); color: var(--warning); border: 1px solid var(--warning); }
.badge-urgent { background: var(--danger-dim); color: var(--danger); border: 1px solid var(--danger); }

/* Alert severity */
.badge-info     { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); }
.badge-warning  { background: var(--warning-dim); color: var(--warning); border: 1px solid var(--warning); }
.badge-high     { background: var(--danger-dim); color: var(--danger); border: 1px solid var(--danger); }
.badge-critical { background: #2d0000; color: var(--critical); border: 1px solid var(--critical); animation: pulse-border 1.5s ease infinite; }

@keyframes pulse-border {
  0%, 100% { border-color: var(--critical); }
  50% { border-color: transparent; }
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: #6aafff; border-color: #6aafff; }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--bg-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-dim); }

.btn-success {
  background: var(--success);
  color: var(--text-inverse);
  border-color: var(--success);
}
.btn-success:hover:not(:disabled) { background: #5de0a8; }

.btn-sm { padding: 4px 10px; font-size: 0.775rem; }
.btn-icon { padding: 6px; width: 30px; height: 30px; justify-content: center; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition);
}

.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }

select.form-control { cursor: pointer; }
select.form-control option { background: var(--bg-raised); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Search / Filter bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding-left: 34px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

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

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: translateY(0); }
.modal-lg { max-width: 800px; }

.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--bg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--bg-border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Alert banner ── */
.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid;
  font-size: 0.825rem;
  margin-bottom: 16px;
}

.alert-banner.warning { background: var(--warning-dim); border-color: var(--warning); color: var(--warning); }
.alert-banner.danger  { background: var(--danger-dim);  border-color: var(--danger);  color: var(--danger); }
.alert-banner.success { background: var(--success-dim); border-color: var(--success); color: var(--success); }
.alert-banner.info    { background: var(--accent-dim);  border-color: var(--accent);  color: var(--accent); }

/* ── Timeline ── */
.timeline { padding-left: 24px; position: relative; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 8px; bottom: 8px; width: 1px; background: var(--bg-border); }

.timeline-event {
  position: relative;
  padding: 0 0 20px 20px;
}

.timeline-event::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 5px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--bg-border);
  border: 2px solid var(--bg-surface);
}

.timeline-event.completed::before { background: var(--success); }
.timeline-event.current::before   { background: var(--accent); }

.timeline-event-title { font-size: 0.845rem; font-weight: 500; color: var(--text-primary); }
.timeline-event-desc  { font-size: 0.775rem; color: var(--text-secondary); margin-top: 2px; }
.timeline-event-time  { font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); margin-top: 4px; }

/* ── Stock bar ── */
.stock-bar {
  height: 4px;
  background: var(--bg-raised);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.stock-bar-fill.ok      { background: var(--success); }
.stock-bar-fill.low     { background: var(--warning); }
.stock-bar-fill.critical { background: var(--danger); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 0.875rem; }

/* ── Loading ── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--bg-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(15,17,23,0.6);
  display: flex; align-items: center; justify-content: center;
  border-radius: inherit;
  z-index: 10;
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.825rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  max-width: 380px;
  animation: toast-in 0.2s ease;
  border-left: 3px solid var(--accent);
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Overdue indicator ── */
.overdue-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--danger);
  display: inline-block;
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(77,159,255,0.04) 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .wordmark {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--text-primary);
}

.login-logo .wordmark span { color: var(--accent); }
.login-logo .sub { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.1em; text-transform: uppercase; margin-top: 4px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  :root { --nav-width: 0px; }
  .sidebar { transform: translateX(-220px); }
  .sidebar.open { transform: translateX(0); width: 220px; }
  .main-content { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Utility ── */
.text-mono  { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-accent  { color: var(--accent); }
.text-sm { font-size: 0.775rem; }
.text-xs { font-size: 0.7rem; }

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }
