:root {
  --bg: #0f172a;
  --sidebar: #1e293b;
  --card: #ffffff;
  --border: #e2e8f0;
  --primary: #0057b7;
  --primary-dark: #003087;
  --accent: #93c2f8;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  color: var(--text);
}

.hidden { display: none !important; }

/* Login — SSO only */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f4f6f8;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 36px 40px 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 2px 12px rgba(0, 45, 86, 0.06);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
}
.login-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #002d56;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  border-radius: 6px;
  line-height: 1;
}
.login-brand-divider {
  width: 1px;
  height: 28px;
  background: #c5ced8;
}
.login-brand-title {
  color: #0057b7;
  font-size: 1.05rem;
  font-weight: 500;
}
.login-heading {
  margin: 0 0 28px;
  font-size: 1.75rem;
  font-weight: 700;
  color: #002d56;
  letter-spacing: -0.02em;
}
.btn-sign-in {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  text-decoration: none;
  background: #002d56;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  padding: 14px 24px;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
}
.btn-sign-in:hover { background: #003087; color: #fff; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand h2 { margin: 0; font-size: 1.1rem; color: #fff; }
.sidebar-brand span { font-size: 0.75rem; color: var(--accent); }
.nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  margin-bottom: 2px;
}
.nav button:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav button.active { background: var(--primary); color: #fff; }
.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sidebar-user-meta {
  min-width: 0;
  flex: 1;
}
.sidebar-footer .user-name {
  color: #fff;
  font-weight: 600;
  font-size: 0.78rem;
  line-height: 1.3;
  word-break: break-all;
}
.sidebar-footer .user-email {
  color: var(--accent);
  font-size: 0.72rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-signout {
  flex-shrink: 0;
  background: #fff;
  color: #002d56;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-signout:hover { background: #e8f1fb; color: #002d56; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.content { padding: 24px; flex: 1; overflow-y: auto; }

/* Dashboard — per-application metrics */
.app-metric-stack { display: flex; flex-direction: column; gap: 16px; }
.app-metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.app-metric-card.disabled { opacity: 0.72; }
.app-metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(90deg, #f8fafc 0%, #fff 100%);
  border-bottom: 1px solid var(--border);
}
.app-metric-title { margin: 0; font-size: 1.05rem; color: #002d56; font-weight: 700; }
.app-metric-code { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.app-metric-body { padding: 16px 20px 20px; }
.app-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.app-metric-tile {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
}
.app-metric-tile .n {
  font-size: 1.75rem;
  font-weight: 700;
  color: #002d56;
  line-height: 1.1;
}
.app-metric-tile .l {
  margin-top: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.app-simple-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.app-simple-card:hover,
.app-simple-card:focus {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 87, 183, 0.12);
  outline: none;
}
.app-simple-card.disabled { opacity: 0.72; }
.app-simple-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.app-simple-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 900px) {
  .app-simple-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
.app-simple-stats > div {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}
.app-simple-stats .n {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #002d56;
  line-height: 1.2;
}
.app-simple-stats .l {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}
.hint-line {
  font-size: 0.85rem;
  color: #64748b;
  margin: 4px 0 14px;
}

/* Cards & stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-card .label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value { font-size: 2rem; font-weight: 700; color: var(--primary); margin-top: 4px; }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-header h3 { margin: 0; font-size: 1rem; }
.panel-body { padding: 20px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
tr:hover td { background: #f8fafc; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-red { background: #fee2e2; color: #991b1b; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 87, 183, 0.15);
}
textarea { min-height: 80px; resize: vertical; }
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}
.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.empty { text-align: center; padding: 40px; color: var(--muted); }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  background: #e0f2fe;
  color: #0369a1;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: monospace;
}

/* Domain multi-picker: dropdown + removable chips */
.chip-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chip-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}
.chip-picker-list.is-empty {
  align-items: center;
}
.chip-picker-empty {
  margin: 0;
  font-size: 0.8rem;
  color: #94a3b8;
}
.domain-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 6px 5px 10px;
  border-radius: 999px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  font-size: 0.8125rem;
  line-height: 1.2;
}
.domain-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.domain-chip-org {
  color: #64748b;
  font-weight: 400;
}
.domain-chip-remove {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e40af;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}
.domain-chip-remove:hover {
  background: #fee2e2;
  color: #991b1b;
}
.chip-picker-add {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.chip-picker-add select {
  flex: 1;
  min-width: 0;
}
.chip-picker-add .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}
.filter-bar select { min-width: 200px; }

.role-section {
  margin-bottom: 16px;
}
.role-section .panel-header {
  align-items: center;
  gap: 10px;
}
.role-section .role-title {
  margin: 0;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.role-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 0;
  border-top: 1px solid #e2e8f0;
  margin-top: 8px;
  font-size: 0.8rem;
  color: #64748b;
}
.role-pager-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.role-pager-page {
  min-width: 3.5rem;
  text-align: center;
  color: #334155;
  font-variant-numeric: tabular-nums;
}
.role-pager .btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.team-link {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.team-link:hover { text-decoration: underline; }
tr.clickable-row { cursor: pointer; }
tr.clickable-row:hover td { background: #eff6ff !important; }
.stat-card.clickable-row { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.stat-card.clickable-row:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(0, 87, 183, 0.12); }
.breadcrumb {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 16px;
}
.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}
.breadcrumb a:hover { text-decoration: underline; }

/* ─── New Product Wizard ─────────────────────────────────────────────────── */
.wizard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 16px;
}
.wizard-modal {
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 960px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.28);
}
.wizard-header {
  padding: 18px 24px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.wizard-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: #002d56;
}
.wizard-header p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.wizard-stepper {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  padding: 20px 28px 8px;
  overflow-x: auto;
}
.wizard-step {
  flex: 1;
  min-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  text-align: center;
}
.wizard-step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  left: calc(50% + 16px);
  right: calc(-50% + 16px);
  height: 3px;
  background: #cbd5e1;
  z-index: 0;
}
.wizard-step.done:not(:last-child)::after,
.wizard-step.active:not(:last-child)::after {
  background: var(--primary);
}
.wizard-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #64748b;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  border: 2px solid #e2e8f0;
}
.wizard-step.active .wizard-step-num {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.wizard-step.done .wizard-step-num {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.wizard-step-label {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.25;
}
.wizard-step.active .wizard-step-label {
  color: var(--primary);
  font-weight: 700;
}
.wizard-step.done .wizard-step-label {
  color: var(--text);
}
.wizard-body {
  padding: 16px 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 280px;
}
.wizard-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border-radius: 0 0 12px 12px;
}
.wizard-footer-right { display: flex; gap: 8px; }
.wizard-section-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  color: #002d56;
}
.wizard-section-hint {
  margin: 0 0 16px;
  font-size: 0.85rem;
  color: var(--muted);
}
.wizard-table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: 320px;
}
.wizard-table-wrap table {
  margin: 0;
  width: 100%;
  border-collapse: collapse;
}
.wizard-table-wrap th {
  background: #f1f5f9;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.wizard-table-wrap td {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
.wizard-table-wrap input,
.wizard-table-wrap select {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.85rem;
}
.wizard-table-wrap input[type="checkbox"] {
  width: auto;
}
.wizard-summary {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
}
.wizard-summary dl {
  margin: 0;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
  font-size: 0.9rem;
}
.wizard-summary dt { color: var(--muted); }
.wizard-summary dd { margin: 0; font-weight: 600; }
.wizard-error {
  display: none;
  margin-bottom: 12px;
}
.wizard-error.visible { display: block; }

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav button { width: auto; }
  .wizard-stepper { padding: 16px 12px 4px; }
  .wizard-step-label { font-size: 0.65rem; }
  .wizard-summary dl { grid-template-columns: 1fr; }
}

