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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.nav-left { flex-shrink: 0; }

.user-dropdown {
  font-size: 13px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 5px 10px;
  background: #f9fafb;
  cursor: pointer;
  color: #374151;
  min-width: 160px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.nav-links a {
  color: #4b5563;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.nav-links a:hover { background: #f3f4f6; color: #111827; text-decoration: none; }
.nav-links a.active { background: #eff6ff; color: #2563eb; }
.nav-divider { color: #d1d5db; font-size: 16px; padding: 0 4px; }

/* ── Container ────────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* ── Page Header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.page-header h1 { font-size: 22px; font-weight: 700; color: #111827; }
.subtitle { color: #6b7280; margin-top: 2px; font-size: 13px; }

/* ── Flash Messages ───────────────────────────────────────────────────────── */
.flash-messages { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
}
.flash-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.flash-danger  { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.flash-warning { background: #fef9c3; color: #92400e; border: 1px solid #fde68a; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { text-decoration: none; }

.btn-primary  { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }

.btn-success  { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-success:hover { background: #15803d; }

.btn-bernie   { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.btn-bernie:hover { background: #6d28d9; }

.btn-secondary { background: #f3f4f6; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover { background: #e5e7eb; }

.btn-ghost    { background: transparent; color: #374151; border-color: #d1d5db; }
.btn-ghost:hover { background: #f3f4f6; }

.btn-danger   { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-active   { background: #dbeafe; color: #1e40af; }
.badge-complete { background: #dcfce7; color: #15803d; }
.badge-bernie   { background: #ede9fe; color: #6d28d9; }
.badge-entry    { background: #d1fae5; color: #065f46; }
.badge-terminal { background: #f3f4f6; color: #6b7280; }
.badge-inactive { background: #f3f4f6; color: #9ca3af; }

/* ── Queue Page ───────────────────────────────────────────────────────────── */
.queue-section { margin-bottom: 28px; }
.queue-section h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: #374151; }

.sku-card { margin-bottom: 10px; }

.sku-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 12px;
}
.sku-link { font-size: 15px; font-weight: 600; color: #111827; }
.sku-meta { font-size: 12px; color: #6b7280; margin-top: 2px; }

.time-badge {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
  flex-shrink: 0;
}
.time-overdue { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }

.advance-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.transition-picker {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  width: 100%;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
}
.radio-label:has(input:checked) { border-color: #2563eb; background: #eff6ff; }

.comment-input {
  flex: 1;
  min-width: 180px;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  color: #374151;
  background: #f9fafb;
}
.comment-input:focus { outline: none; border-color: #2563eb; background: #fff; }

.bernie-section h2 { color: #6d28d9; }
.bernie-card { border-color: #ede9fe; }
.section-note { font-size: 12px; color: #6b7280; margin-bottom: 12px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-card { max-width: 560px; }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 5px; }

.form-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  color: #111827;
  background: #fff;
}
.form-control:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

textarea.form-control { resize: vertical; font-family: inherit; }
select.form-control { cursor: pointer; }

.checkbox-label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-weight: 400; }
.checkbox-label input { margin-top: 2px; flex-shrink: 0; }
.form-hint { font-size: 12px; color: #6b7280; margin-top: 4px; display: block; }
.required { color: #b91c1c; }
.form-actions { display: flex; gap: 8px; padding-top: 8px; }

/* ── Filter Bar ───────────────────────────────────────────────────────────── */
.filter-bar { padding: 14px 16px; }
.filter-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-search { flex: 1; min-width: 160px; max-width: 260px; }
.filter-select { min-width: 130px; width: auto; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  color: #4b5563;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 10px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f9fafb; }
.clickable-row { cursor: pointer; }
.row-overdue { background: #fff7f7 !important; }
.row-overdue:hover { background: #fee2e2 !important; }
.row-inactive { opacity: 0.6; }

.sort-link { color: #4b5563; font-size: 12px; font-weight: 600; text-decoration: none; }
.sort-link:hover { color: #111827; }

.actions-cell { white-space: nowrap; display: flex; gap: 4px; }
.table-count { font-size: 12px; color: #9ca3af; margin-top: 12px; text-align: right; }

.nowrap { white-space: nowrap; }
.text-muted { color: #9ca3af; }
.text-danger { color: #b91c1c; font-weight: 600; }
.overdue-flag { margin-left: 4px; }

/* ── Section Header ───────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h2 { font-size: 16px; font-weight: 600; }

/* ── Detail Page ──────────────────────────────────────────────────────────── */
.detail-header-card { margin-bottom: 16px; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.detail-item { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #9ca3af; }
.detail-value { font-size: 14px; color: #111827; font-weight: 500; }

.advance-card { border-color: #bfdbfe; background: #f0f7ff; }
.advance-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: #1e40af; }

/* ── Warnings Card ────────────────────────────────────────────────────────── */
.warnings-card { border-color: #fde68a; background: #fefce8; }
.warnings-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: #92400e; }
.warnings-card ul { padding-left: 18px; }
.warnings-card li { font-size: 13px; color: #78350f; margin-bottom: 4px; }

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: #9ca3af;
  padding: 32px 16px;
  font-size: 14px;
}

/* ── Truncatable Names ────────────────────────────────────────────────────── */
.sku-name.truncatable {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  cursor: pointer;
  border-bottom: 1px dashed #d1d5db;
}
.sku-name.truncatable:hover { border-bottom-color: #6b7280; }
.sku-name.truncatable.expanded {
  max-width: none;
  white-space: normal;
  overflow: visible;
}
/* In table cells, allow more width */
td .sku-name.truncatable { max-width: 180px; }

/* ── Time Toggle Button ───────────────────────────────────────────────────── */
.time-col-header { white-space: nowrap; }
.toggle-time-btn {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 500;
  color: #6b7280;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
}
.toggle-time-btn:hover { background: #e5e7eb; color: #111827; }
.time-badge-inline { cursor: pointer; border-bottom: 1px dashed #d1d5db; }
.time-badge-inline:hover { border-bottom-color: #6b7280; }

/* ── Undo Banner ──────────────────────────────────────────────────────────── */
.undo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #eff6ff;
  border-color: #bfdbfe;
  font-size: 13px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.undo-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Comments Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #6b7280;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: #111827; }
.modal-body { overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.comment-entry { border-left: 3px solid #bfdbfe; padding-left: 12px; }
.comment-meta { font-size: 11px; color: #9ca3af; margin-bottom: 3px; }
.comment-text { font-size: 13px; color: #374151; }

/* ── Reorder Buttons (stage ordering) ────────────────────────────────────── */
.reorder-col { width: 60px; text-align: center; }
.reorder-btns { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.reorder-btn {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  cursor: pointer;
  color: #6b7280;
  line-height: 1.4;
}
.reorder-btn:hover { background: #e5e7eb; color: #111827; }

/* ── History Note Rows ────────────────────────────────────────────────────── */
.history-note-row { background: #fafafa; }
.history-note-row td { color: #6b7280; font-style: italic; }

/* ── Workflow Flow View ───────────────────────────────────────────────────── */
.flow-view { display: flex; flex-direction: column; gap: 10px; }

.flow-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.flow-entry { border-left: 3px solid #10b981; }
.flow-terminal-card { border-left: 3px solid #16a34a; }

.flow-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  gap: 8px;
}
.flow-title-left { display: flex; flex-direction: column; gap: 4px; }
.flow-stage-name { font-size: 14px; font-weight: 600; color: #111827; }
.flow-badges { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }

.flow-arrows { padding: 6px 0; }
.flow-arrow-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-bottom: 1px solid #f3f4f6;
  flex-wrap: wrap;
}
.flow-arrow-row:last-child { border-bottom: none; }
.flow-arrow-icon { color: #9ca3af; font-size: 14px; flex-shrink: 0; }
.flow-dest { font-size: 13px; font-weight: 500; color: #374151; }
.flow-label-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.flow-owner-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}
.flow-actions { display: flex; gap: 4px; margin-left: auto; }

.flow-end-note {
  padding: 10px 14px;
  font-size: 13px;
  color: #15803d;
  font-style: italic;
}
.flow-no-exit {
  padding: 10px 14px;
  font-size: 13px;
  color: #b91c1c;
  font-style: italic;
}

/* ── Stage Summary (Dashboard) ───────────────────────────────────────────── */
.stage-summary-card { padding: 20px; }
.stage-summary-title { font-size: 14px; font-weight: 600; color: #374151; margin-bottom: 14px; }
.stage-summary-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.stage-summary-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  text-decoration: none;
  color: inherit;
  min-width: 100px;
  max-width: 180px;
  transition: border-color 0.1s, background 0.1s;
  text-align: center;
}
.stage-summary-tile:hover { border-color: #93c5fd; background: #eff6ff; text-decoration: none; color: inherit; }
.tile-bernie { border-color: #c4b5fd; background: #faf5ff; }
.tile-bernie:hover { border-color: #7c3aed; background: #ede9fe; }
.tile-count { font-size: 24px; font-weight: 700; color: #111827; line-height: 1; }
.tile-name { font-size: 11px; color: #6b7280; margin-top: 4px; line-height: 1.3; }
.tile-breakdown { font-size: 10px; color: #9ca3af; margin-top: 2px; }
.tile-owner { font-size: 10px; color: #9ca3af; margin-top: 2px; font-style: italic; }

/* ── Parallel / Thread styles ─────────────────────────────────────────────── */
.thread-card { border-left: 3px solid #8b5cf6; }
.thread-label-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
  margin-right: 4px;
}
.badge-parallel {
  background: #ede9fe;
  color: #5b21b6;
}

/* ── Thread detail cards (sku_detail parallel section) ─────────────────────── */
.thread-detail-card {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid #ddd6fe;
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
}
.thread-detail-card:last-child { margin-bottom: 0; }
.thread-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}
.thread-stage-name { font-size: 13px; font-weight: 500; color: #374151; }
.thread-done { background: #f9fafb; opacity: 0.7; }

/* ── Bernie flow card ─────────────────────────────────────────────────────── */
.flow-bernie-card { border-left: 3px solid #7c3aed; }

/* ── Flow card title actions ──────────────────────────────────────────────── */
.flow-card-actions { display: flex; gap: 4px; flex-shrink: 0; flex-wrap: wrap; align-items: flex-start; }
.flow-stage-name-row { display: flex; align-items: center; }

/* ── Mermaid wrapper ──────────────────────────────────────────────────────── */
.mermaid-wrapper {
  overflow-x: auto;
  padding: 8px 0;
  min-height: 80px;
}
.mermaid { min-height: 60px; }

/* ── Form control static ──────────────────────────────────────────────────── */
.form-control-static {
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
  font-size: 14px;
  color: #374151;
}

/* ── Skip Bernie Button ───────────────────────────────────────────────────── */
.btn-skip-bernie {
  background: #f5f3ff;
  color: #5b21b6;
  border-color: #c4b5fd;
}
.btn-skip-bernie:hover { background: #ede9fe; border-color: #7c3aed; }

/* ── Role Badges ──────────────────────────────────────────────────────────── */
.badge-admin    { background: #dbeafe; color: #1e40af; }
.badge-superuser { background: #fef3c7; color: #92400e; }

/* ── Filter label text ────────────────────────────────────────────────────── */
.filter-label { font-size:12px; color:#6b7280; white-space:nowrap; }

/* ── Date inputs ──────────────────────────────────────────────────────────── */
.date-input { width: 140px; min-width: 120px; font-size:13px; }

/* ── Nav Dropdown ─────────────────────────────────────────────────────────── */
.nav-dropdown { position: relative; display: inline-block; }
.nav-dropdown-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.nav-dropdown-btn:hover, .nav-dropdown-btn.active { color: #2563eb; background: #eff6ff; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  min-width: 160px;
  z-index: 100;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  padding: 8px 14px;
  font-size: 13px;
  color: #374151;
  text-decoration: none;
  white-space: nowrap;
}
.nav-dropdown-menu a:hover { background: #f3f4f6; color: #2563eb; }
.nav-dropdown-menu a.active { color: #2563eb; font-weight: 600; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .navbar { height: auto; padding: 10px 16px; gap: 10px; }
  .container { padding: 16px 12px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .filter-form { gap: 6px; }
  .filter-search { max-width: 100%; flex: 1 0 100%; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; }
  .advance-form { flex-direction: column; align-items: flex-start; }
  .comment-input { width: 100%; }
  .sku-name.truncatable { max-width: 140px; }
}
