/* ============================================
   BUILD AI | OPERATIONS — Design System
   Matching BuildAI Dashboard (Chassis Admirer)
   ============================================ */

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

:root {
  /* Border radius — zero for technical/engineering aesthetic */
  --radius: 0px;

  /* Backgrounds — warm white */
  --background: oklch(0.99 0 0);
  --foreground: oklch(0.15 0 0);

  /* Cards */
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.15 0 0);

  /* Primary — black */
  --primary: oklch(0.15 0 0);
  --primary-foreground: oklch(0.98 0 0);

  /* Secondary */
  --secondary: oklch(0.95 0 0);
  --secondary-foreground: oklch(0.15 0 0);

  /* Muted */
  --muted: oklch(0.95 0 0);
  --muted-foreground: oklch(0.45 0 0);

  /* Accent — neutral */
  --accent: oklch(0.95 0 0);
  --accent-foreground: oklch(0.15 0 0);

  /* Destructive */
  --destructive: oklch(0.58 0.22 27);

  /* Border */
  --border: oklch(0.90 0 0);
  --input: oklch(0.90 0 0);
  --ring: oklch(0.15 0 0);

  /* Semantic status colors */
  --success: oklch(0.60 0.18 145);
  --success-foreground: oklch(0.25 0.05 145);
  --success-muted: oklch(0.96 0.03 145);

  --warning: oklch(0.70 0.15 75);
  --warning-foreground: oklch(0.35 0.08 75);
  --warning-muted: oklch(0.96 0.03 75);

  --error: oklch(0.62 0.18 25);
  --error-foreground: oklch(0.30 0.08 25);
  --error-muted: oklch(0.96 0.03 25);

  /* Font — JetBrains Mono throughout for technical aesthetic */
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font-ui: var(--font-mono);

  /* Legacy tokens mapped to new system */
  --bg: var(--background);
  --surface: var(--card);
  --surface-soft: var(--muted);
  --ink: var(--foreground);
  --ink-soft: var(--muted-foreground);
  --line: var(--border);
  --line-strong: oklch(0.80 0 0);
  --ok-bg: var(--success-muted);
  --ok-ink: var(--success-foreground);
  --bad-bg: var(--error-muted);
  --bad-ink: var(--error-foreground);
  --pending-bg: var(--muted);
  --pending-ink: var(--muted-foreground);
  --touch-target: 44px;
}

/* ============================================
   BASE
   ============================================ */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--foreground);
  background: var(--background);
  font-family: var(--font-mono);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.4;
}

/* ============================================
   NAVBAR — matches BuildAI Dashboard
   ============================================ */

.site-navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid oklch(0.90 0 0 / 0.4);
  background: oklch(0.99 0 0 / 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.navbar-inner {
  width: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
}

@media (min-width: 640px) {
  .navbar-inner {
    padding: 0 24px;
    height: 56px;
  }
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0;
  text-decoration: none;
}

.navbar-brand-main {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--foreground);
}

@media (min-width: 640px) {
  .navbar-brand-main {
    font-size: 0.875rem;
  }
}

.navbar-brand-sep {
  color: var(--muted-foreground);
  opacity: 0.3;
  margin: 0 6px;
  font-size: 0.625rem;
}

@media (min-width: 640px) {
  .navbar-brand-sep {
    margin: 0 8px;
  }
}

.navbar-brand-sub {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--foreground);
}

@media (min-width: 640px) {
  .navbar-brand-sub {
    font-size: 0.875rem;
  }
}

.navbar-nav {
  display: none;
  align-items: center;
  gap: 4px;
}

@media (min-width: 768px) {
  .navbar-nav {
    display: flex;
  }
}

.navbar-link {
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted-foreground);
  text-decoration: none;
  transition: color 0.15s, background-color 0.15s;
}

.navbar-link:hover {
  color: var(--foreground);
  background: var(--secondary);
}

.navbar-link-active {
  color: var(--primary);
  background: oklch(0.15 0 0 / 0.05);
}

/* ============================================
   TOGGLE TABS
   ============================================ */

.tabs {
  display: inline-flex;
  align-items: center;
  gap: 0;
  width: fit-content;
  border: 1px solid var(--border);
  background: var(--muted);
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-foreground);
  padding: 6px 12px;
  min-height: 32px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: -0.01em;
  touch-action: manipulation;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--foreground);
  background: var(--secondary);
}

.tab-active {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-foreground);
}

/* ============================================
   PAGE LAYOUT
   ============================================ */

.page {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 18px;
}

/* ============================================
   VIEWS
   ============================================ */

.view {
  display: none;
}

.view-active {
  display: grid;
  gap: 20px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}

/* ============================================
   CARDS
   ============================================ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 16px;
  min-width: 0;
}

.card h2 {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 1.5vw, 1.35rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--foreground);
}

.card h3 {
  margin: 16px 0 8px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ============================================
   FORMS
   ============================================ */

.form {
  display: grid;
  gap: 10px;
}

.form label {
  display: grid;
  gap: 5px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

input,
select,
textarea,
button {
  font: inherit;
  font-family: var(--font-mono);
}

input:not([type='checkbox']):not([type='radio']),
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  padding: 8px 10px;
  min-height: 38px;
  color: var(--foreground);
  background: var(--card);
}

input:not([type='checkbox']):not([type='radio']):focus,
select:focus,
textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px oklch(0.15 0 0 / 0.15);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 78px;
}

input[type='file'] {
  padding: 7px;
  border-style: dashed;
}

input[type='file']::file-selector-button {
  border: 1px solid var(--border);
  padding: 4px 8px;
  background: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

input[type='checkbox'],
input[type='radio'] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

.checkbox-row {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 0 10px;
  color: var(--foreground);
  font-weight: 500;
  line-height: 1.35;
}

.checkbox-row input {
  margin-top: 1px;
}

.choice-group {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.choice-title {
  padding: 0;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.radio-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 0 10px;
  color: var(--foreground);
  font-weight: 500;
  line-height: 1.35;
}

.radio-row input {
  margin-top: 1px;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  padding: 8px 11px;
  min-height: 38px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: -0.01em;
  touch-action: manipulation;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.btn:hover {
  border-color: var(--line-strong);
  background: var(--secondary);
}

.btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-primary:hover {
  background: oklch(0.25 0 0);
  border-color: oklch(0.25 0 0);
}

.btn[disabled] {
  opacity: 0.72;
  cursor: not-allowed;
}

/* ============================================
   TYPE TOGGLE (submission type pills)
   ============================================ */

.type-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: transparent;
  border: 1px solid var(--border);
  padding: 0;
  width: fit-content;
}

.type-btn {
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--card);
  color: var(--muted-foreground);
  padding: 5px 12px;
  min-height: 36px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: -0.01em;
  touch-action: manipulation;
  transition: color 0.15s, background-color 0.15s;
}

.type-btn:last-child {
  border-right: 0;
}

.type-btn:hover {
  color: var(--foreground);
  background: var(--secondary);
}

.type-btn-active {
  background: var(--primary);
  color: var(--primary-foreground);
}

/* ============================================
   MISC FORM BITS
   ============================================ */

.sub-fields {
  display: grid;
  gap: 9px;
  margin-top: 2px;
}

.hidden {
  display: none;
}

.submission-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted-foreground);
}

.submission-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

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

.status {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inline-label {
  display: inline-grid;
  gap: 5px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.inline-label input {
  min-width: 150px;
}

#refresh-dashboard {
  align-self: flex-end;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  flex-wrap: wrap;
}

.row-between > strong {
  line-height: 1.2;
  font-weight: 600;
}

/* ============================================
   DASHBOARD LAYOUT
   ============================================ */

.dashboard-board {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.dashboard-main-panel,
.dashboard-side-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  gap: 10px;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
}

.dashboard-main-panel > h3,
.dashboard-side-panel > h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(1.05rem, 1.3vw, 1.3rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  text-align: left;
  color: var(--foreground);
}

.dashboard-main-panel .matrix-wrap {
  min-height: 520px;
}

.dashboard-side-panels {
  display: grid;
  gap: 12px;
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.dashboard-side-panel .status-grid-wrap {
  min-height: 250px;
}

.dashboard-header {
  align-items: flex-end;
}

/* ============================================
   SUMMARY CARDS
   ============================================ */

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
}

.summary {
  background: transparent;
  border: 0;
  padding: 0;
}

.summary .label {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.summary .value {
  margin-top: 4px;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--foreground);
}

/* ============================================
   TABLES
   ============================================ */

.table-wrap,
.matrix-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  background: var(--card);
}

table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

#sd-grid-1pm,
#sd-grid-eod {
  min-width: 440px;
  table-layout: auto;
}

#leaderboard-table {
  min-width: 980px;
  table-layout: auto;
}

#sd-1pm-table,
#sd-eod-table {
  min-width: 430px;
  table-layout: fixed;
}

#matrix-table {
  min-width: 780px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 7px;
  text-align: left;
  font-size: 0.73rem;
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: middle;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

tbody tr:last-child td {
  border-bottom: 0;
}

/* ============================================
   STATUS GRID TABLES
   ============================================ */

.status-grid-table thead th {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.7rem;
}

.status-grid-table th,
.status-grid-table td {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 0.72rem;
}

.status-grid-table th:first-child,
.status-grid-table td:first-child {
  text-align: left;
  width: 38%;
  white-space: nowrap;
}

.status-grid-table th:nth-child(2),
.status-grid-table td:nth-child(2) {
  width: 10%;
}

.status-grid-table th:nth-child(3),
.status-grid-table td:nth-child(3),
.status-grid-table th:nth-child(4),
.status-grid-table td:nth-child(4),
.status-grid-table th:nth-child(5),
.status-grid-table td:nth-child(5) {
  width: 17.333%;
}

.status-grid-table tbody tr.clickable-row {
  cursor: pointer;
  transition: background-color 0.15s;
}

.status-grid-table tbody tr.clickable-row:hover td {
  background: var(--secondary);
}

.status-grid-table tbody tr.clickable-row:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: -2px;
}

/* ============================================
   MATRIX
   ============================================ */

.matrix {
  table-layout: fixed;
}

.matrix th:first-child,
.matrix td:first-child {
  width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix thead th {
  text-align: center;
  padding: 4px 2px;
  font-size: 0.56rem;
  text-transform: none;
  letter-spacing: 0;
}

.matrix thead .matrix-operator {
  text-align: left;
  padding-left: 8px;
}

.matrix thead .matrix-hour {
  background: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  white-space: nowrap;
}

.matrix thead .matrix-quarter {
  width: 18px;
  min-width: 18px;
  font-weight: 600;
  color: var(--muted-foreground);
}

.matrix th,
.matrix td {
  padding: 2px;
  font-size: 0.66rem;
  line-height: 1.15;
  vertical-align: middle;
}

.matrix .slot-cell {
  text-align: center;
  font-weight: 700;
}

/* ============================================
   STATUS CELLS / CHIPS
   ============================================ */

.hit {
  background: var(--success-muted);
  color: var(--success-foreground);
}

.miss {
  background: var(--error-muted);
  color: var(--error-foreground);
}

.pending {
  background: var(--muted);
  color: var(--muted-foreground);
}

.flag-bad,
.flag-good,
.state-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 7px;
  font-size: 0.68rem;
  font-weight: 700;
  border: 0;
  font-family: var(--font-mono);
}

.flag-bad,
.state-miss {
  background: var(--error-muted);
  color: var(--error-foreground);
}

.flag-good,
.state-ok {
  background: var(--success-muted);
  color: var(--success-foreground);
}

/* ============================================
   MOBILE LEADERBOARD
   ============================================ */

.leaderboard-mobile {
  display: none;
  gap: 10px;
}

.mobile-row {
  border: 1px solid var(--border);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.mobile-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.mobile-row-head h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
}

.mobile-team {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted-foreground);
}

.mobile-row-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 8px;
}

.mobile-kv {
  display: grid;
  gap: 2px;
}

.mobile-kv .k {
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.mobile-kv .v {
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

/* ============================================
   REPORT PAGES
   ============================================ */

.eod-report-page {
  width: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
}

.report-fit-canvas {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.report-shell {
  width: min(1180px, 100%);
  display: grid;
  gap: 8px;
  padding: 10px;
}

.report-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.report-top h1 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 1.4vw, 1.3rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.report-content {
  display: grid;
  gap: 8px;
}

.report-section {
  border: 1px solid var(--border);
  padding: 7px;
}

.report-section h2 {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.report-kv-table {
  table-layout: auto;
  font-family: var(--font-mono);
}

.report-kv-table th,
.report-kv-table td {
  padding: 5px 7px;
  font-size: 0.74rem;
  vertical-align: top;
  line-height: 1.2;
}

.report-kv-table th {
  width: 30%;
  min-width: 150px;
  color: var(--muted-foreground);
  font-weight: 600;
  background: var(--muted);
}

.report-sd-summary-table {
  margin-bottom: 6px;
}

.report-card-table {
  table-layout: auto;
}

.report-card-table th,
.report-card-table td {
  text-align: left;
  font-size: 0.72rem;
  padding: 4px 6px;
  line-height: 1.15;
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease-out backwards;
}

.animate-slide-up {
  animation: slideUp 0.4s ease-out backwards;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .dashboard-board {
    grid-template-columns: 1fr;
  }

  .dashboard-main-panel .matrix-wrap {
    min-height: 420px;
  }

  .dashboard-side-panels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .dashboard-side-panel .status-grid-wrap {
    min-height: 220px;
  }

  .summary-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .page {
    padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .btn,
  .type-btn,
  input:not([type='checkbox']):not([type='radio']),
  select,
  textarea {
    min-height: var(--touch-target);
  }

  .type-toggle {
    width: 100%;
  }

  .type-btn {
    flex: 1;
    text-align: center;
  }

  .card {
    padding: 12px;
  }

  .eod-report-page {
    padding-top: 0;
    padding-bottom: 0;
  }

  .report-shell {
    width: 100%;
  }

  .summary-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-header {
    align-items: flex-start;
  }

  .inline-form {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .inline-label {
    width: 100%;
  }

  #refresh-dashboard {
    width: 100%;
  }

  .dashboard-side-panels {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .status-grid-table th,
  .status-grid-table td {
    font-size: 0.68rem;
    padding: 6px;
  }

  .status-grid-table thead th {
    font-size: 0.66rem;
  }

  .leaderboard-table-wrap {
    display: none;
  }

  .leaderboard-mobile {
    display: grid;
  }

  .mobile-row-grid {
    grid-template-columns: 1fr;
  }

  .matrix th:first-child,
  .matrix td:first-child {
    width: 96px;
  }

  .matrix thead .matrix-quarter {
    width: 16px;
    min-width: 16px;
    font-size: 0.54rem;
  }

  .report-kv-table th {
    width: 40%;
    min-width: 140px;
  }
}

@media (max-width: 480px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .mobile-row {
    padding: 9px;
  }
}
