:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --nav-bg: #0f172a;
  --nav-hover: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.18);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--primary); text-decoration: none; }

/* Utility */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.text-muted { color: var(--text-muted); }
.text-xs { font-size: 11.5px; }
.text-sm { font-size: 12.5px; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); border-color: #94a3b8; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: #e2e8f0; color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-xs { padding: 2px 7px; font-size: 11.5px; }

/* Inputs */
.input, .select, .textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: #f1f5f9;
  color: #64748b;
  cursor: not-allowed;
}
.textarea { min-height: 76px; resize: vertical; }

.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; font-weight: 600; color: #334155; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  color: #1e293b;
}
.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Auth & Setup Screens */
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #0f172a 100%);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.setup-card {
  width: 100%;
  max-width: 720px;
  background: var(--surface);
  border-radius: 14px;
  padding: 30px;
  box-shadow: var(--shadow-lg);
}
.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  background: var(--surface-alt);
}
.check-item.ok { border-color: #a7f3d0; background: #ecfdf5; }
.check-item.fail { border-color: #fecaca; background: #fef2f2; }
.check-dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}
.check-item.ok .check-dot { background: #10b981; color: #fff; }
.check-item.fail .check-dot { background: #ef4444; color: #fff; }
.setup-steps {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.55;
}
.setup-steps ol { margin: 6px 0 0 18px; padding: 0; }
.setup-steps li { margin-bottom: 6px; }
.setup-steps code {
  background: #e2e8f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.alert {
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.alert-error { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: var(--info-soft); color: #075985; border: 1px solid #bae6fd; }
.alert-warn { background: var(--warning-soft); color: #92400e; border: 1px solid #fde68a; }

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.topbar {
  height: 56px;
  background: var(--nav-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 14px;
  flex-shrink: 0;
  border-bottom: 1px solid #1e293b;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
.topbar-brand .brand-icon { width: 30px; height: 30px; font-size: 13px; border-radius: 7px; }
.topbar-brand small {
  font-size: 10.5px;
  font-weight: 500;
  color: #94a3b8;
  display: block;
  line-height: 1;
  margin-top: 2px;
}

.view-switcher {
  display: inline-flex;
  background: #1e293b;
  padding: 3px;
  border-radius: 7px;
  gap: 2px;
}
.view-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.view-btn:hover { color: #fff; }
.view-btn.active { background: #2563eb; color: #fff; }

.topbar-search {
  flex: 1;
  max-width: 360px;
  position: relative;
}
.topbar-search input {
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  color: #f8fafc;
  padding: 6px 10px 6px 32px;
  border-radius: 7px;
  font-size: 13px;
  outline: none;
}
.topbar-search input::placeholder { color: #94a3b8; }
.topbar-search input:focus { border-color: #60a5fa; background: #0f172a; }
.topbar-search svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  pointer-events: none;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #cbd5e1;
  background: #1e293b;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid #334155;
}
.sync-pill:hover { border-color: #64748b; color: #fff; }
.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #10b981;
}
.sync-pill.syncing .sync-dot { background: #f59e0b; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.user-menu-wrap { position: relative; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 999px;
  color: #f8fafc;
  cursor: pointer;
}
.user-chip:hover { border-color: #64748b; }
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 230px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 60;
  color: var(--text);
}
.user-dropdown-header {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.dropdown-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dropdown-item:hover { background: var(--surface-alt); }
.dropdown-item.danger { color: var(--danger); }

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 16px 8px;
  background: var(--bg);
  flex-shrink: 0;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.kpi-card.active { border-color: var(--primary); background: var(--primary-soft); }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.kpi-value { font-size: 20px; font-weight: 800; color: var(--text); line-height: 1.15; }
.kpi-sub { font-size: 11px; color: var(--text-muted); }
.kpi-card.kpi-warn .kpi-value { color: var(--warning); }
.kpi-card.kpi-danger .kpi-value { color: var(--danger); }
.kpi-card.kpi-success .kpi-value { color: var(--success); }

/* Toolbar & Department Tabs */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.dept-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.dept-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.dept-tab:hover { background: #e2e8f0; color: var(--text); }
.dept-tab.active {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.tab-count {
  font-size: 11px;
  background: #e2e8f0;
  color: #475569;
  padding: 1px 6px;
  border-radius: 999px;
}
.dept-tab.active .tab-count { background: #dbeafe; color: #1d4ed8; }

.filter-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.filter-controls .select {
  width: auto;
  padding: 5px 9px;
  font-size: 12.5px;
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-height: 0;
  padding: 0 16px 14px;
  display: flex;
  flex-direction: column;
}

/* DataGrid */
.grid-card {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.grid-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
}
table.datagrid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
table.datagrid thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid #eef2f6;
  padding: 9px 10px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
table.datagrid thead th:hover { background: #f1f5f9; color: var(--text); }
table.datagrid thead th.sticky-col {
  left: 0;
  z-index: 20;
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.06);
}
table.datagrid tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid #eef2f6;
  border-right: 1px solid #f1f5f9;
  vertical-align: top;
  background: var(--surface);
}
table.datagrid tbody td.sticky-col {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--surface);
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.05);
}
table.datagrid tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
table.datagrid tbody tr:hover td { background: #f8fafc; }
table.datagrid tbody tr.row-urgent td.sticky-col {
  border-left: 3px solid var(--danger);
}
table.datagrid tbody tr.row-ready td.sticky-col {
  border-left: 3px solid var(--success);
}
table.datagrid tbody tr.row-delivered td { opacity: 0.72; }
table.datagrid tbody tr.row-cancelled td { opacity: 0.52; text-decoration: line-through; }

.cell-primary { font-weight: 600; color: var(--text); line-height: 1.3; }
.cell-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; line-height: 1.3; }
.cell-date {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  color: #475569;
  margin-top: 3px;
  white-space: nowrap;
}
.cell-date.overdue { color: var(--danger); font-weight: 700; }
.cell-date.soon { color: var(--warning); font-weight: 700; }

/* Status Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.45;
}
.pill-clickable { cursor: pointer; }
.pill-clickable:hover { filter: brightness(0.95); transform: translateY(-0.5px); }
.pill-green { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.pill-blue { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.pill-amber { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.pill-red { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.pill-purple { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.pill-teal { background: #ccfbf1; color: #115e59; border-color: #99f6e4; }
.pill-slate { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }

/* Mini Department Readiness Dots */
.readiness-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.rdot {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
}
.rdot-done { background: #dcfce7; color: #166534; border-color: #86efac; }
.rdot-prog { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.rdot-wait { background: #f1f5f9; color: #94a3b8; border-color: #cbd5e1; }

.pinned-banner {
  margin-top: 4px;
  font-size: 11px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Inline Quick-Edit Popover */
.quick-popover {
  position: fixed;
  z-index: 90;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
}
.quick-popover-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Pipeline Kanban View */
.pipeline-board {
  flex: 1;
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  min-height: 0;
}
.pipeline-col {
  width: 290px;
  min-width: 290px;
  background: #e2e8f0;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
}
.pipeline-col-header {
  padding: 10px 12px;
  font-weight: 700;
  font-size: 12.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #cbd5e1;
}
.pipeline-cards {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.deal-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.deal-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: #93c5fd; }
.deal-card-urgent { border-left: 3px solid var(--danger); }

/* Schedule Timeline View */
.schedule-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 12px;
}
.schedule-group {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 110px;
  overflow: hidden;
}
.schedule-group-header {
  flex-shrink: 0;
  background: #f8fafc;
  padding: 9px 14px;
  font-weight: 700;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.schedule-group-body {
  min-height: 68px;
  max-height: 360px;
  overflow-y: auto;
}
.schedule-event {
  display: grid;
  grid-template-columns: 115px 130px 1fr 160px 130px;
  gap: 10px;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}
.schedule-event:last-child { border-bottom: none; }
.schedule-event:hover { background: #f8fafc; }

/* Slide-Over Deal Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 70;
  display: flex;
  justify-content: flex-end;
}
.drawer-panel {
  width: 100%;
  max-width: 820px;
  height: 100%;
  background: var(--surface);
  box-shadow: -8px 0 32px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer-header {
  padding: 14px 20px;
  background: #0f172a;
  color: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.drawer-header h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.drawer-header-meta { font-size: 12px; color: #cbd5e1; margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.drawer-readiness-bar {
  display: flex;
  gap: 6px;
  padding: 8px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.drawer-tabs {
  display: flex;
  gap: 2px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.drawer-tab {
  border: none;
  background: transparent;
  padding: 10px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.drawer-tab:hover { color: var(--text); }
.drawer-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
}
.drawer-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.section-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.section-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Aftermarket Table inside Drawer */
.am-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.am-table th, .am-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.am-table th { background: #f8fafc; font-size: 11.5px; color: #475569; text-transform: uppercase; }
.am-table tr:last-child td { border-bottom: none; }

/* Comments & Audit */
.comment-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  margin-bottom: 9px;
}
.comment-item.pinned { border-color: #f59e0b; background: #fffbeb; }
.comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.comment-body { font-size: 13px; line-height: 1.45; white-space: pre-wrap; color: var(--text); }

.audit-item {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 12.5px;
}
.audit-diff {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.diff-old { background: #fee2e2; color: #991b1b; padding: 1px 6px; border-radius: 4px; text-decoration: line-through; font-size: 11.5px; }
.diff-new { background: #dcfce7; color: #166534; padding: 1px 6px; border-radius: 4px; font-weight: 600; font-size: 11.5px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  width: 100%;
  max-width: 740px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-card.modal-lg { max-width: 960px; }
.modal-card.modal-sm { max-width: 440px; }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Column Toggle Menu */
.popover-menu {
  position: relative;
}
.popover-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  padding: 10px 12px;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
}
.toast.toast-success { border-left: 4px solid #10b981; }
.toast.toast-error { border-left: 4px solid #ef4444; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

@media (max-width: 1100px) {
  .kpi-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3 { grid-column: span 1; }
  .schedule-event { grid-template-columns: 1fr; gap: 4px; }
}
