/* ===================================================
   Fowler Order Tracker — Main Stylesheet
   =================================================== */

/* Reset & Base
   --------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Barlow Semi Condensed', system-ui, sans-serif;
  color: #0A0A0A;
  background: #FFFFFF;
  line-height: 1.6;
  min-height: 100vh;
}

.mono {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
}

/* Nav
   --------------------------------------------------- */
.nav {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  height: 56px;
  border-bottom: 1px solid #DCDCDC;
  background: #FFFFFF;
}

.nav-brand {
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-brand-bold {
  font-weight: 700;
}

.nav-brand-light {
  font-weight: 400;
  color: #555;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  flex: 1;
}

.nav-link {
  text-decoration: none;
  color: #0A0A0A;
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s;
}

.nav-link:hover,
.nav-link.active {
  border-bottom-color: #0A0A0A;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.nav-username {
  font-size: 0.9rem;
  color: #555;
}

.nav-account-btn {
  text-decoration: none;
  font-size: 0.75rem;
}

.nav-user-menu {
  position: relative;
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  background: #fff;
  border: 1px solid #DCDCDC;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 100;
  min-width: 140px;
}

.user-dropdown-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  font-family: 'Barlow Semi Condensed', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: #0A0A0A;
  text-decoration: none;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  box-sizing: border-box;
}

.user-dropdown-item:hover {
  background: #F0F0F0;
}

.user-dropdown-logout {
  color: #B91C1C;
  border-top: 1px solid #EBEBEB;
}

html.theme-dark .user-dropdown {
  background: #1A1A1A;
  border-color: #2D2D2D;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
html.theme-dark .user-dropdown-item { color: #E0E0E0; }
html.theme-dark .user-dropdown-item:hover { background: #2D2D2D; }
html.theme-dark .user-dropdown-logout { color: #D94A4A; border-color: #2D2D2D; }

.lights-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #888;
  margin-right: 0.25rem;
}

/* Buttons
   --------------------------------------------------- */
.btn-primary,
.btn-secondary {
  display: inline-block;
  padding: 0.65rem 1.25rem;
  font-family: 'Barlow Semi Condensed', system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  border-radius: 0;
  border: none;
  transition: background 0.15s, color 0.15s;
}

.btn-primary {
  background: #0A0A0A;
  color: #FFFFFF;
  border: 2px solid #0A0A0A;
}

.btn-primary:hover {
  background: #2A2A2A;
  border-color: #2A2A2A;
}

.btn-secondary {
  background: transparent;
  color: #0A0A0A;
  border: 2px solid #0A0A0A;
}

.btn-secondary:hover {
  background: #0A0A0A;
  color: #FFFFFF;
}

.btn-full {
  width: 100%;
  text-align: center;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Forms
   --------------------------------------------------- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #555;
  margin-bottom: 0.4rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  display: block;
  width: 100%;
  padding: 0.75rem;
  font-family: 'Barlow Semi Condensed', system-ui, sans-serif;
  font-size: 1rem;
  color: #0A0A0A;
  background: #FFFFFF;
  border: 1px solid #DCDCDC;
  border-radius: 0;
  transition: border-color 0.15s;
  appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #0A0A0A;
}

/* Flash Messages
   --------------------------------------------------- */
.flash {
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  border-left: 4px solid;
  margin: 0;
}

.flash-success {
  background: #F0FFF4;
  border-color: #22C55E;
  color: #15803D;
}

.flash-error {
  background: #FFF1F2;
  border-color: #EF4444;
  color: #B91C1C;
}

/* Login Page
   --------------------------------------------------- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F5F5F5;
  padding: 2rem;
}

.login-card {
  background: #FFFFFF;
  border: 1px solid #DCDCDC;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #0A0A0A;
  line-height: 1.2;
}

.login-subtitle {
  font-size: 0.85rem;
  color: #888;
  margin-top: 0.4rem;
  letter-spacing: 0.04em;
}

.login-card .flash {
  margin-bottom: 1.25rem;
}

.login-form {
  margin-top: 0;
}

/* Tables
   --------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

table th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #555;
  background: #F8F8F8;
  border-bottom: 2px solid #DCDCDC;
}

table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #EBEBEB;
  vertical-align: middle;
}

table tr:nth-child(even) td {
  background: #F0F0F0;
}

table tr:hover td {
  background: #E8E8E8;
}

/* Stage Badges
   --------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 2px;
}

.badge-order_created  { background: #EEF2FF; color: #3730A3; }
.badge-machining      { background: #FFF7ED; color: #9A3412; }
.badge-fitting        { background: #FEFCE8; color: #854D0E; }
.badge-serializing    { background: #F0FFF4; color: #166534; }
.badge-coating        { background: #EFF6FF; color: #1D4ED8; }
.badge-test_firing    { background: #FFF1F2; color: #9F1239; }
.badge-shipping       { background: #F0FDF4; color: #15803D; }

/* Layout / Page
   --------------------------------------------------- */
main {
  /* padding added per-page to allow full-bleed sections */
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid #EBEBEB;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 50;
}

html.theme-dark .page-header {
  background: #0A0A0A;
  border-bottom-color: #2D2D2D;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.page-content {
  padding: 1.5rem 2rem;
}

/* Color Swatches (finish/coating)
   --------------------------------------------------- */
.color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  vertical-align: middle;
  flex-shrink: 0;
}
.finish-label { color: #555; }
.order-num-cell { color: #555; }

.tux-swatch {
  background: linear-gradient(to right, #1a1a1a 50%, #c0c0c0 50%);
}

/* Filter bar (order list)
   --------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

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

.filter-group-search {
  flex: 1;
  min-width: 200px;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #888;
}

.filter-select,
.filter-input {
  padding: 0.5rem 0.75rem;
  font-family: 'Barlow Semi Condensed', system-ui, sans-serif;
  font-size: 0.9rem;
  color: #0A0A0A;
  background: #FFFFFF;
  border: 1px solid #DCDCDC;
  border-radius: 0;
  appearance: none;
  transition: border-color 0.15s;
  height: 36px;
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: #0A0A0A;
}

.filter-select {
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23555'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}

/* Responsive
   --------------------------------------------------- */
@media (max-width: 768px) {
  .nav {
    flex-wrap: wrap;
    height: auto;
    padding: 0.5rem 0.75rem;
    gap: 0;
  }

  /* Row 1: brand left, user menu right */
  .nav-brand {
    flex: 1;
    font-size: 0.9rem;
  }

  .nav-brand-light {
    display: none;
  }

  .nav-user {
    order: 2;
    gap: 0.35rem;
  }

  /* Row 2: nav links spanning full width */
  .nav-links {
    order: 3;
    width: 100%;
    display: flex;
    gap: 0;
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid #EBEBEB;
  }

  .nav-links a {
    flex: 1;
    text-align: center;
    font-size: 0.78rem;
    padding: 0.3rem 0;
  }

  .nav-links .btn-primary.btn-sm {
    margin-left: 0;
  }

  .lights-label {
    display: none;
  }

  .nav-account-btn {
    font-size: 0.68rem;
    padding: 0.2rem 0.4rem;
  }

  .user-dropdown {
    right: 0;
  }

  html.theme-dark .nav-links { border-top-color: #2D2D2D; }

  .page-header {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
  }

  .page-content {
    padding: 1rem;
  }

  .login-card {
    padding: 1.75rem 1.25rem;
  }
}

/* ===================================================
   Toggle Switch
   =================================================== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  vertical-align: middle;
  cursor: pointer;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #2D2D2D;
  border-radius: 18px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: #9A9A9A; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(14px); }

/* ===================================================
   Dark Mode (toggled via .theme-dark on <html>)
   =================================================== */
html.theme-dark body {
  background: #0A0A0A;
  color: #E0E0E0;
}
html.theme-dark .nav {
  background: #111;
  border-bottom-color: #2D2D2D;
}
html.theme-dark .nav-brand-light,
html.theme-dark .nav-link,
html.theme-dark .nav-username { color: #9A9A9A; }
html.theme-dark .nav-brand-bold { color: #F0F0F0; }
html.theme-dark .nav-link:hover { color: #F0F0F0; }

html.theme-dark .page-title { color: #F0F0F0; }

html.theme-dark .filter-select,
html.theme-dark .filter-input {
  background: #1A1A1A; color: #E0E0E0;
  border-color: #2D2D2D;
}
html.theme-dark .filter-label { color: #6B6B6B; }

html.theme-dark table { border-color: #2D2D2D; }
html.theme-dark thead th { background: #111; color: #9A9A9A; border-color: #2D2D2D; }
html.theme-dark tbody tr { border-color: #2D2D2D; }
html.theme-dark table tr:nth-child(even) td { background: #151515; }
html.theme-dark table tr:nth-child(odd) td { background: #0A0A0A; }
html.theme-dark table tr:hover td { background: #1A1A1A; }
html.theme-dark td { color: #E0E0E0; border-color: #2D2D2D; }
html.theme-dark td a { color: #F0F0F0; }
html.theme-dark .finish-label { color: #CCCCCC !important; }
html.theme-dark .order-num-cell, html.theme-dark .order-num-cell a { color: #F0F0F0 !important; }

html.theme-dark .btn-primary { background: #F0F0F0; color: #0A0A0A; }
html.theme-dark .btn-primary:hover { background: #DCDCDC; }
html.theme-dark .btn-secondary { border-color: #6B6B6B; color: #9A9A9A; }
html.theme-dark .btn-secondary:hover { background: #2D2D2D; color: #F0F0F0; }

html.theme-dark .badge { border-color: #2D2D2D; }

html.theme-dark .flash-success { background: #1a3d1a; border-color: #166534; color: #4AD94A; }
html.theme-dark .flash-error { background: #3d1a1a; border-color: #8B2500; color: #D94A4A; }

/* Order detail dark mode */
html.theme-dark .order-detail { color: #E0E0E0; }
html.theme-dark .order-hero-title { color: #F0F0F0; }
html.theme-dark .order-hero-meta { color: #6B6B6B; }
html.theme-dark .section-heading { color: #6B6B6B; border-color: #2D2D2D; }
html.theme-dark .specs-grid { border-color: #2D2D2D; }
html.theme-dark .spec-item { border-color: #2D2D2D; }
html.theme-dark .spec-label { color: #6B6B6B; }
html.theme-dark .spec-value { color: #E0E0E0; }
html.theme-dark .payment-row { border-color: #2D2D2D; }
html.theme-dark .payment-label { color: #9A9A9A; }
html.theme-dark .payment-amount { color: #E0E0E0; }
html.theme-dark .notes-block { background: #1A1A1A; border-color: #2D2D2D; color: #CCCCCC; }
html.theme-dark .timeline::before { background: #2D2D2D; }
html.theme-dark .timeline-date { color: #6B6B6B; }
html.theme-dark .timeline-by { color: #6B6B6B; }
html.theme-dark .meta-strip { background: #1A1A1A; border-color: #2D2D2D; color: #9A9A9A; }
html.theme-dark .meta-strip strong { color: #E0E0E0; }

html.theme-dark .edit-specs-form { border-color: #2D2D2D; }
html.theme-dark .edit-field label { color: #6B6B6B; }
html.theme-dark .edit-field input,
html.theme-dark .edit-field textarea,
html.theme-dark .edit-field select {
  background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D;
}
html.theme-dark .set-stage-select { background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D; }
html.theme-dark .btn-set-stage { background: #1A1A1A; color: #9A9A9A; border-color: #2D2D2D; }
html.theme-dark .btn-save-specs { background: #F0F0F0; color: #0A0A0A; }

html.theme-dark .fitting-section { background: #1A1A0A; border-color: #3d3d1a; }
html.theme-dark .fitting-task { border-color: #3d3d1a; }
html.theme-dark .fitting-title { color: #E0E0E0; }

html.theme-dark .login-card { background: #111; border-color: #2D2D2D; }
html.theme-dark .login-title { color: #F0F0F0; }
html.theme-dark .login-subtitle { color: #6B6B6B; }
html.theme-dark .login-input { background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D; }

/* Account page dark mode */
html.theme-dark .account-section-title { color: #6B6B6B; border-color: #2D2D2D; }
html.theme-dark .info-row { border-color: #2D2D2D; }
html.theme-dark .info-label { color: #6B6B6B; }
html.theme-dark .info-value { color: #E0E0E0; }
html.theme-dark .password-form .form-field label { color: #6B6B6B; }
html.theme-dark .password-form .form-field input { background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D; }
html.theme-dark .btn-save-password { background: #F0F0F0; color: #0A0A0A; }
html.theme-dark .btn-save-password:hover { background: #DCDCDC; }

/* Admin users page dark mode */
html.theme-dark .section-heading { color: #6B6B6B; border-color: #2D2D2D; }
html.theme-dark .add-user-form { border-color: #2D2D2D; }
html.theme-dark .add-user-grid .form-field label { color: #6B6B6B; }
html.theme-dark .add-user-grid .form-field input,
html.theme-dark .add-user-grid .form-field select { background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D; }
html.theme-dark .btn-add-user { background: #F0F0F0; color: #0A0A0A; }
html.theme-dark .btn-add-user:hover { background: #DCDCDC; }
html.theme-dark .users-table th { color: #6B6B6B; border-color: #2D2D2D; }
html.theme-dark .users-table td { border-color: #2D2D2D; color: #E0E0E0; }
html.theme-dark .users-table tr.current-user td { background: #1A1A1A; }
html.theme-dark .role-form select { background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D; }
html.theme-dark .btn-role { background: #1A1A1A; color: #9A9A9A; border-color: #2D2D2D; }
html.theme-dark .btn-role:hover { background: #2D2D2D; color: #E0E0E0; }
html.theme-dark .reset-pwd-toggle { background: #1A1A1A; color: #9A9A9A; border-color: #2D2D2D; }
html.theme-dark .reset-pwd-toggle:hover { background: #2D2D2D; }
html.theme-dark .reset-pwd-form input { background: #1A1A1A; color: #E0E0E0; border-color: #2D2D2D; }
html.theme-dark .you-badge { background: #1A1A1A; color: #6B6B6B; border-color: #2D2D2D; }
