/* ====================================================
   Order Wizard — Apple-inspired UI
   ==================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-nav: rgba(255, 255, 255, 0.85);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.15);

  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-light: #e8f0fd;

  --green: #28a745;
  --green-light: #d4edda;
  --orange: #e07b20;
  --orange-light: #fff3e0;
  --red: #dc3545;
  --red-light: #fde8ea;
  --blue: #0071e3;
  --blue-light: #e8f0fd;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 16px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.06);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Courier New', monospace;

  --nav-height: 56px;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-card: #1c1c1e;
  --bg-nav: rgba(28, 28, 30, 0.9);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);

  --text-primary: #f5f5f7;
  --text-secondary: #98989d;
  --text-tertiary: #636366;

  --accent: #2997ff;
  --accent-hover: #47a8ff;
  --accent-light: rgba(41, 151, 255, 0.15);

  --green: #32d74b;
  --green-light: rgba(50, 215, 75, 0.15);
  --orange: #ff9f0a;
  --orange-light: rgba(255, 159, 10, 0.15);
  --red: #ff453a;
  --red-light: rgba(255, 69, 58, 0.15);
  --blue: #2997ff;
  --blue-light: rgba(41, 151, 255, 0.15);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: 0.8; }

/* ---------- Navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  overflow: visible;
  height: var(--nav-height);
  background: var(--bg-nav);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
}

.nav-left { display: flex; align-items: center; gap: 20px; flex: 1; }
.nav-right { display: flex; align-items: center; gap: 12px; }

.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  text-decoration: none;
}
.nav-link:hover, .nav-link.active { color: var(--text-primary); background: var(--border); opacity: 1; }

.nav-user {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ---------- Main Content ---------- */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.meta-sep { color: var(--text-tertiary); }

.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.header-back { display: flex; flex-direction: column; gap: 6px; }

.breadcrumb {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.breadcrumb a { color: var(--accent); }

/* ---------- Stats ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 500;
}

/* ---------- Filter Tabs ---------- */
.filter-tabs, .admin-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}
.tab:hover { color: var(--text-primary); opacity: 1; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--accent-light); }

.table tbody td {
  padding: 13px 16px;
  vertical-align: middle;
  color: var(--text-primary);
}

.table tfoot td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-secondary);
  background: var(--bg);
}

.table-total { text-align: right; color: var(--text-secondary); }
.table-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: var(--green-light);  color: var(--green); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-red    { background: var(--red-light);    color: var(--red); }
.badge-blue   { background: var(--blue-light);   color: var(--blue); }
.badge-neutral { background: var(--border); color: var(--text-secondary); }
.badge-xs { padding: 2px 6px; font-size: 0.7rem; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); opacity: 1; color: white; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg); opacity: 1; color: var(--text-primary); }

.btn-danger {
  background: var(--bg-card);
  color: #ef4444;
  border: 1px solid #ef444466;
  box-shadow: var(--shadow-sm);
}
.btn-danger:hover { background: #ef44440f; opacity: 1; color: #ef4444; border-color: #ef4444; }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--accent-light); opacity: 1; }

.btn-danger {
  background: var(--red);
  color: white;
}
.btn-danger:hover { opacity: 0.88; color: white; }

.btn-green {
  background: var(--green);
  color: white;
}
.btn-green:hover { opacity: 0.88; color: white; }
.btn-green:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text-primary); }

.btn-copy-inline {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s;
  vertical-align: middle;
}
.btn-copy-inline:hover, .btn-copy-inline.copied { color: var(--green); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 18px; }
.form-row { display: flex; gap: 16px; }
.form-row.two-col > .form-group { flex: 1; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}
textarea.form-input { resize: vertical; }
.form-hint { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.form-optional { font-size: 0.75rem; color: var(--text-tertiary); font-weight: 400; margin-left: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; cursor: pointer; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.form-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px 32px; box-shadow: var(--shadow-sm); max-width: 560px; }
.mb-4 { margin-bottom: 16px; }

/* ---------- Section ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 12px;
}
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.section-actions { display: flex; gap: 8px; }
.section-hint { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.5; }

/* ---------- Detail Grid ---------- */
.detail-grid { margin-bottom: 8px; }
.detail-meta {
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px 32px;
}
.meta-item { display: flex; flex-direction: column; gap: 3px; }
.meta-key { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }
.meta-val { font-size: 0.9rem; color: var(--text-primary); display: flex; align-items: center; gap: 6px; }

/* ---------- Correction Badge ---------- */
.correction-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--green-light);
  color: var(--green);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  cursor: help;
}

/* ---------- Raw PDF Section ---------- */
.raw-section { margin-top: 24px; }
.email-iframe {
  width: 100%; min-height: 400px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-top: 8px; background: #fff;
}
.raw-summary {
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  list-style: none;
  transition: background 0.12s;
}
.raw-summary:hover { background: var(--border); color: var(--text-primary); }
.raw-text {
  margin-top: 8px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-x: auto;
  line-height: 1.6;
}

/* ---------- Status Banner ---------- */
.status-banner {
  margin-top: 20px;
  padding: 14px 20px;
  background: var(--green-light);
  border: 1px solid var(--green);
  color: var(--green);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 64px 24px;
  color: var(--text-tertiary);
  text-align: center;
  line-height: 1.6;
}
.empty-state.small { padding: 32px 24px; }
.empty-state svg { opacity: 0.3; }

/* ---------- Alerts ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.875rem;
  font-weight: 500;
}
.alert-text { flex: 1; word-break: break-word; }
.alert-actions { display: flex; gap: 4px; flex-shrink: 0; }
.alert-copy, .alert-close {
  background: none; border: none; cursor: pointer;
  opacity: 0.6; padding: 2px; border-radius: 4px;
  color: inherit; line-height: 1;
}
.alert-copy:hover, .alert-close:hover { opacity: 1; }
.alert-success { background: var(--green-light); color: var(--green); }
.alert-error { background: var(--red-light); color: var(--red); }
.alert-info { background: var(--blue-light); color: var(--blue); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }
.toast.success { background: #1a1a1a; }
.toast.error { background: var(--red); }

/* ---------- Spinner ---------- */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ---------- Selected Items Preview ---------- */
.selected-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  min-height: 32px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.item-tag {
  padding: 3px 10px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 100px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* ---------- Text Utilities ---------- */
.font-mono { font-family: var(--font-mono); font-size: 0.85em; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-danger { color: var(--red); }
.text-green { color: var(--green); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }

/* ---------- Login Page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-container { width: 100%; max-width: 380px; padding: 24px; }
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: var(--radius);
  color: white;
  margin-bottom: 16px;
}
.login-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 28px; }
.login-card .form-group { text-align: left; }
.login-card .btn-primary { margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .main-content { padding: 20px 16px 48px; }
  .navbar { padding: 0 16px; gap: 12px; }
  .page-title { font-size: 1.4rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .detail-meta { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; }
  .form-card { padding: 20px; }
  .table thead th:nth-child(3),
  .table tbody td:nth-child(3) { display: none; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .nav-user { display: none; }
  .page-header { flex-direction: column; }
  .header-actions { width: 100%; }
}

/* ---------- Notification Bell ---------- */
.notif-wrapper { position: relative; }
.notif-bell { position: relative; }
.notif-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--red); color: #fff;
  font-size: 0.65rem; font-weight: 700; line-height: 1;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px; pointer-events: none;
}
.notif-dropdown {
  position: fixed; top: 60px; right: 16px;
  width: 340px; max-height: 480px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 99999; display: flex; flex-direction: column;
}
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  gap: 8px;
}
.notif-title { font-weight: 600; font-size: 0.875rem; }
.notif-header-actions { display: flex; gap: 6px; }
.notif-action-btn {
  background: none; border: 1px solid var(--border); cursor: pointer;
  font-size: 0.75rem; padding: 3px 8px; border-radius: var(--radius-sm);
  color: var(--text-secondary); white-space: nowrap;
}
.notif-action-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.notif-danger { color: var(--red) !important; border-color: var(--red) !important; }
.notif-danger:hover { background: var(--red-light) !important; }
.notif-list { overflow-y: auto; flex: 1; }
.notif-empty { padding: 24px 16px; text-align: center; color: var(--text-secondary); font-size: 0.875rem; }
.notif-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.notif-item.unread { background: var(--blue-light); }
.notif-msg { font-size: 0.875rem; color: var(--text-primary); }
.notif-meta { font-size: 0.75rem; color: var(--text-secondary); }
.notif-item-actions { display: flex; gap: 6px; margin-top: 4px; }

/* ---------- Copy feedback ---------- */
.btn-copied {
  background: var(--green) !important;
  color: #fff !important;
  border-color: var(--green) !important;
  transition: background 0.15s, color 0.15s;
}
.copy-inline-feedback {
  font-size: 0.75rem; font-weight: 600;
  color: var(--green); margin-left: 6px;
  animation: fadeout 1.5s forwards;
}
@keyframes fadeout { 0%,60% { opacity:1; } 100% { opacity:0; } }
