:root {
  --bg:        #0f0f16;
  --surface:   #17171f;
  --surface-2: #1f1f2a;
  --surface-3: #272733;
  --accent:    #4a8fff;
  --accent-dim:#2d5fcc;
  --text:      #dddde8;
  --text-dim:  #7070a0;
  --success:   #42c87a;
  --warn:      #f0a832;
  --danger:    #f05858;
  --radius:    8px;
  --radius-sm: 5px;
  --sidebar-w: 210px;
  --header-h:  60px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
  overflow-y: auto;
}

#sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 10px;
}
.logo-mark {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  flex-shrink: 0;
}
.logo-text {
  font-weight: 700; font-size: 14px; color: var(--text); letter-spacing: 0.03em;
}

#nav-list {
  list-style: none;
  padding: 0 10px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  user-select: none;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(74,143,255,0.14); color: var(--accent); }
.nav-icon { font-size: 14px; width: 16px; text-align: center; flex-shrink: 0; }
.nav-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 8px 0; }

/* ── Main ────────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ── Views ───────────────────────────────────────────────────────────────── */
.view { display: none; padding: 30px 32px 48px; flex: 1; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.view-header h1 { font-size: 20px; font-weight: 700; }
.view-sub { color: var(--text-dim); font-size: 12px; margin-top: 3px; }
.view-header-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: background 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dim); }
.btn-secondary {
  background: var(--surface-2); color: var(--text);
  border-color: rgba(255,255,255,0.08);
}
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(240,88,88,0.12); }
.btn-success { background: var(--success); color: #0f0f16; border-color: var(--success); }
.btn-sm { padding: 4px 9px; font-size: 11px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
#orders-table-wrap,
#confirm-table-wrap,
.card table {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
thead th {
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 600;
  text-align: left;
  padding: 9px 12px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  user-select: none;
}
thead th[data-sort] { cursor: pointer; }
thead th[data-sort]:hover { color: var(--text); }
.sort-arrow { font-size: 9px; margin-left: 4px; }
thead th.sort-asc .sort-arrow::after  { content: '▲'; }
thead th.sort-desc .sort-arrow::after { content: '▼'; }
tbody tr { border-bottom: 1px solid rgba(255,255,255,0.04); }
tbody tr:hover { background: var(--surface-2); }
tbody td {
  padding: 9px 12px;
  vertical-align: middle;
  color: var(--text);
}
.loading-row td { color: var(--text-dim); text-align: center; padding: 24px; }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-received  { background: rgba(112,112,160,0.2);  color: var(--text-dim); }
.badge-designing { background: rgba(74,143,255,0.18);  color: var(--accent); }
.badge-awaiting  { background: rgba(66,200,122,0.15);  color: var(--success); }
.badge-confirmed { background: rgba(240,168,50,0.18);  color: var(--warn); }
.badge-printed   { background: rgba(66,200,122,0.18);  color: var(--success); }
.badge-manual    { background: rgba(255,255,255,0.08); color: var(--text-dim); }
.badge-app       { background: rgba(74,143,255,0.10); color: var(--accent); }

/* ── Search & filter bar ─────────────────────────────────────────────────── */
.search-wrap input {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 12px;
  font-size: 12px;
  width: 220px;
  outline: none;
}
.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap input:focus { border-color: var(--accent); }
select {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 11.5px; font-weight: 600; color: var(--text-dim); }
.form-group input,
.form-group textarea,
.form-group select {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 11px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--accent); }
.req { color: var(--danger); }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; }

/* ── Workflow steps ───────────────────────────────────────────────────────── */
.workflow { max-width: 760px; }
.steps {
  display: flex; align-items: center; gap: 0;
  margin-bottom: 28px;
}
.step {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.step.active { color: var(--accent); }
.step.done   { color: var(--success); }
.step-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.step.active .step-num { border-color: var(--accent); background: rgba(74,143,255,0.15); color: var(--accent); }
.step.done   .step-num { border-color: var(--success); background: rgba(66,200,122,0.15); color: var(--success); }
.step-line { flex: 1; height: 1px; background: rgba(255,255,255,0.08); min-width: 40px; }

.step-panel { display: none; }
.step-panel.active { display: block; }
.step-actions {
  display: flex; gap: 10px; margin-top: 24px;
}

/* ── Upload zones ────────────────────────────────────────────────────────── */
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.upload-zone {
  position: relative;
  border: 2px dashed rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 32px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(74,143,255,0.06);
}
.upload-zone.has-file { border-color: var(--success); border-style: solid; }
.upload-icon { font-size: 28px; color: var(--text-dim); }
.upload-label { font-weight: 700; font-size: 14px; }
.upload-hint { color: var(--text-dim); font-size: 11px; }
.upload-file-name { color: var(--success); font-size: 11.5px; font-weight: 600; min-height: 16px; }
.file-input {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
  width: 100%; height: 100%;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 20px;
}
.card-title { font-weight: 700; font-size: 13px; margin-bottom: 16px; }
.card-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 760px; }

/* ── QR code ─────────────────────────────────────────────────────────────── */
.qr-placeholder {
  border: 1px dashed rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}
#qr-result img {
  width: 100%; max-width: 220px;
  border-radius: var(--radius-sm);
  display: block; margin: 0 auto 12px;
}
#qr-token-info {
  font-size: 11px; color: var(--text-dim);
  word-break: break-all; margin-top: 8px;
  line-height: 1.6;
}

/* ── Pipeline board ──────────────────────────────────────────────────────── */
#pipeline-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  align-items: start;
}
.pipeline-col {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 200px;
}
.pipeline-col-hd {
  font-weight: 700; font-size: 12px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.pipeline-cards { display: flex; flex-direction: column; gap: 8px; }
.pipe-card {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
}
.pipe-card-id   { color: var(--text-dim); font-size: 10.5px; }
.pipe-card-name { font-weight: 600; margin: 2px 0; }
.pipe-card-date { color: var(--text-dim); font-size: 10.5px; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
#modal-overlay.hidden { display: none; }
#modal {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  width: min(780px, 94vw);
  max-height: 82vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
#modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
#modal-title { font-weight: 700; font-size: 14px; }
#modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 16px; cursor: pointer; padding: 2px 6px;
  border-radius: var(--radius-sm); line-height: 1;
}
#modal-close:hover { color: var(--text); background: var(--surface-2); }
#modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

/* Order detail modal */
.order-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.od-section {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.od-section-title {
  font-weight: 700; font-size: 10.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.07em;
  padding: 7px 12px 6px;
  background: var(--surface-3);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.od-table { width: 100%; border-collapse: collapse; }
.od-table tr { border-bottom: 1px solid rgba(255,255,255,0.04); }
.od-table tr:last-child { border-bottom: none; }
.od-label {
  color: var(--text-dim); font-size: 11.5px; font-weight: 500;
  padding: 6px 12px; width: 40%; vertical-align: top;
  white-space: nowrap;
}
.od-val {
  color: var(--text); font-size: 12px;
  padding: 6px 12px; vertical-align: top;
  word-break: break-word;
}
.od-full { grid-column: 1 / -1; }
.od-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(74,143,255,0.12);
  color: var(--accent);
  font-size: 11px;
  margin: 2px 3px 2px 0;
}
.od-tag-cat {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  padding: 1px 4px;
}

/* ── Status messages ─────────────────────────────────────────────────────── */
.status-msg {
  margin-top: 12px; font-size: 12px;
  min-height: 18px;
}
.status-msg.ok  { color: var(--success); }
.status-msg.err { color: var(--danger); }

/* ── Profile ─────────────────────────────────────────────────────────────── */
.profile-avatar {
  width: 60px; height: 60px;
  background: var(--surface-2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--text-dim);
  margin-bottom: 20px;
}

.text-dim { color: var(--text-dim); }

/* ── Clinics table inside card ───────────────────────────────────────────── */
#clinics-table thead th,
#clinics-table tbody td {
  padding: 8px 10px;
}

/* ── Status filter checklist ─────────────────────────────────────────────── */
.status-filter-wrap { position: relative; }
.status-filter-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.status-filter-btn:hover { background: var(--surface-3); }
.status-filter-arrow { font-size: 10px; color: var(--text-dim); }
.status-filter-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 200;
  background: var(--surface); border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius); padding: 6px 0; min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.status-filter-dropdown.hidden { display: none; }
.sf-option {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; font-size: 12px; cursor: pointer;
  color: var(--text); user-select: none;
}
.sf-option:hover { background: rgba(255,255,255,0.05); }
.sf-option input { accent-color: var(--accent); cursor: pointer; }
.sf-option-dim { color: var(--text-dim); }
.sf-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 4px 0; }

/* ── Bulk selection bar ──────────────────────────────────────────────────── */
.bulk-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px;
  background: rgba(74,143,255,0.08);
  border: 1px solid rgba(74,143,255,0.2);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.bulk-bar.hidden { display: none; }
.bulk-count { font-size: 12px; font-weight: 600; color: var(--accent); min-width: 80px; }
.bulk-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bulk-actions select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  padding: 4px 8px; font-size: 11px; cursor: pointer;
}

/* ── Checkbox column ─────────────────────────────────────────────────────── */
.th-check, .td-check {
  width: 36px; text-align: center; padding: 6px 4px !important;
}
.th-check input, .td-check input { cursor: pointer; accent-color: var(--accent); }
tr.row-selected td { background: rgba(74,143,255,0.07); }

/* ── Automate button ─────────────────────────────────────────────────────── */
.btn-automate {
  background: rgba(74,143,255,0.10);
  color: var(--accent);
  border-color: rgba(74,143,255,0.25);
}
.btn-automate:hover { background: rgba(74,143,255,0.22); border-color: var(--accent); }

/* ── Automate modal ──────────────────────────────────────────────────────── */
#auto-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1001;
  backdrop-filter: blur(4px);
}
#auto-overlay.hidden { display: none; }
#auto-modal {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  width: min(520px, 92vw);
  max-height: 80vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
#auto-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
#auto-header span { font-weight: 700; font-size: 14px; }
#auto-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 16px; cursor: pointer; padding: 2px 6px;
  border-radius: var(--radius-sm);
}
#auto-close:hover { color: var(--text); background: var(--surface-2); }
#auto-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  display: flex; flex-direction: column; gap: 12px;
}
#auto-steps { display: flex; flex-direction: column; gap: 6px; }
.auto-step {
  display: grid;
  grid-template-columns: 20px 1fr;
  grid-template-rows: auto auto;
  gap: 0 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.auto-step-icon  { font-size: 14px; line-height: 1.4; grid-row: 1 / 3; align-self: center; }
.auto-step-label { font-weight: 600; color: var(--text); }
.auto-step-detail {
  color: var(--text-dim); font-size: 11px;
  grid-column: 2; word-break: break-word;
}
#auto-footer {
  display: flex; gap: 10px; padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.05);
  padding: 12px 0 0;
}
#auto-footer.hidden { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  #sidebar { width: 46px; min-width: 46px; }
  .logo-text, .nav-item { font-size: 0; }
  .nav-icon { font-size: 16px; width: 100%; text-align: center; }
  #sidebar-logo { justify-content: center; padding: 14px 8px; }
  .logo-mark { margin: 0 auto; }
  .two-col, .upload-grid, .form-grid, .config-grid { grid-template-columns: 1fr; }
  #pipeline-board { grid-template-columns: 1fr 1fr; }
  .mod-pickers { grid-template-columns: 1fr; }
}

/* ── Modifier pickers (step 3) ───────────────────────────────────────────── */
.mod-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
  margin-top: 20px;
}

.mod-picker-side {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.mod-picker-hd {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.mod-picker-add {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mod-picker-select {
  flex: 1;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
}

.mod-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  min-height: 28px;
}

.mod-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-3);
  border: 1px solid rgba(74,143,255,0.3);
  border-radius: 20px;
  padding: 3px 10px 3px 10px;
  font-size: 11.5px;
  color: var(--text);
}

.mod-chip-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
}

.mod-chip-remove:hover { color: var(--danger); }
