:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --navy: #0b1324;
  --primary: #2563eb;
  --emerald: #059669;
  --violet: #7c3aed;
  --sky: #0284c7;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  background: radial-gradient(circle at 30% 20%, #1e293b 0%, #090d1a 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.auth-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.auth-header h1 { margin: 0; font-size: 19px; font-weight: 800; }
.auth-header p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #334155; }
.auth-form input {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
}
.auth-hint { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }

.hub-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff; font-weight: 900; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hub-logo.sm { width: 34px; height: 34px; font-size: 13px; border-radius: 9px; }

/* Suite Top Bar */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.suite-bar {
  background: var(--navy);
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  border-bottom: 1px solid #1e293b;
}
.suite-brand { display: flex; align-items: center; gap: 10px; }
.suite-title { font-weight: 800; font-size: 14px; line-height: 1.2; }
.suite-sub { font-size: 11px; color: #94a3b8; }

.app-switcher { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.switcher-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px;
  background: #172036; color: #cbd5e1;
  border: 1px solid #29354d; font-size: 12px; font-weight: 700;
  cursor: pointer; transition: all 0.15s ease;
}
.switcher-pill:hover { background: #1e293b; color: #fff; border-color: #475569; }
.switcher-pill.current { background: #1d4ed8; color: #fff; border-color: #3b82f6; cursor: default; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; display: inline-block; }
.dot.online { background: #10b981; box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25); }
.dot.offline { background: #ef4444; }
.dot-hub { background: #60a5fa; }

.suite-user { display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; flex-direction: column; text-align: right; font-size: 12px; }
.user-chip .muted { color: #94a3b8; font-size: 10.5px; }

/* Body Layout */
.workspace-body { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 245px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 800; padding: 4px 10px 6px;
}
.nav-btn {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 9px 12px; border-radius: 8px; border: none;
  background: transparent; color: #334155; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.nav-btn:hover { background: #f8fafc; color: var(--ink); }
.nav-btn.active { background: #eff6ff; color: var(--primary); font-weight: 700; }

.sidebar-card {
  margin-top: auto;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; flex-direction: column; gap: 7px;
}
.sidebar-card-title { font-size: 11px; font-weight: 800; color: #475569; text-transform: uppercase; }

.main-panel { flex: 1; padding: 22px 26px; overflow-y: auto; }
.tab-panel { display: none; flex-direction: column; gap: 18px; }
.tab-panel.active { display: flex; }

.section-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* App Status Cards */
.app-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.app-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.app-card-title { font-weight: 800; font-size: 15px; }
.app-card-sub { font-size: 11.5px; color: var(--muted); }
.status-badge {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
}
.status-badge.ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.status-badge.warn { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.status-badge.err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

.app-metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  background: #f8fafc; padding: 9px; border-radius: 10px;
}
.metric-item { display: flex; flex-direction: column; }
.metric-k { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.metric-v { font-size: 14px; font-weight: 800; color: var(--ink); }
.app-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.driver-pill {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 6px; background: #e2e8f0; color: #334155;
}

/* Flow Diagram */
.flow-diagram {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; padding: 8px 0;
}
.flow-node {
  flex: 1; min-width: 170px; background: #f8fafc; border: 1px solid var(--border);
  border-radius: 12px; padding: 12px;
}
.flow-badge {
  display: inline-block; font-size: 11px; font-weight: 800; color: #fff;
  padding: 3px 9px; border-radius: 999px; margin-bottom: 6px;
}
.flow-badge.hrms { background: var(--emerald); }
.flow-badge.crm { background: var(--primary); }
.flow-badge.accounts { background: var(--violet); }
.flow-badge.mail { background: var(--sky); }
.flow-detail { font-size: 12px; color: #475569; line-height: 1.4; }
.flow-arrow { font-size: 11.5px; font-weight: 800; color: var(--primary); white-space: nowrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 800; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.flows-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.flow-card { display: flex; flex-direction: column; gap: 10px; }
.flow-card-tag { font-size: 11px; font-weight: 800; color: var(--primary); text-transform: uppercase; }
.flow-card h3 { margin: 0; font-size: 16px; }
.flow-card p { margin: 0; color: #475569; font-size: 12.5px; line-height: 1.5; }
.flow-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }

.kpi-mini-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi-mini { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.kpi-mini span { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi-mini strong { font-size: 22px; font-weight: 800; }

.compact-log-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.compact-log {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 8px; background: #f8fafc; border: 1px solid var(--border);
  font-size: 12px;
}

/* Tables & Forms */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); background: #f8fafc; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #334155; }
.form-grid input, .form-grid select, .form-grid textarea, .input-sm {
  padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 13px; background: #fff;
}
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.checkbox-inline { display: flex !important; flex-direction: row !important; align-items: center; gap: 7px; font-weight: 600 !important; cursor: pointer; }
.toggle-list { display: flex; flex-direction: column; gap: 8px; background: #f8fafc; padding: 12px; border-radius: 10px; border: 1px solid var(--border); }

.guide-list { padding-left: 18px; display: flex; flex-direction: column; gap: 8px; color: #334155; font-size: 13px; line-height: 1.5; }
.env-box { margin-top: 14px; }
.env-title { font-size: 12px; font-weight: 700; color: #334155; }
.json-pre {
  background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 10px;
  font-size: 12px; overflow-x: auto; max-height: 360px; margin: 0;
}

/* Buttons & Alerts */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; padding: 8px 14px; font-weight: 700; font-size: 13px;
  cursor: pointer; border: 1px solid transparent; transition: all 0.15s ease;
}
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-emerald { background: var(--emerald); color: #fff; }
.btn-violet { background: var(--violet); color: #fff; }
.btn-outline { background: #fff; color: #334155; border-color: #cbd5e1; }
.btn-outline:hover { background: #f8fafc; }
.btn-danger-soft { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.suite-bar .btn-outline { background: #172036; color: #e2e8f0; border-color: #334155; }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.45; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 9999;
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600; box-shadow: 0 12px 24px rgba(0,0,0,0.25);
}
.toast.err { background: var(--danger); }

.ref-pill {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  background: #f1f5f9; border: 1px solid #cbd5e1; font-family: monospace; font-size: 11px;
}

.role-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: #1e293b; color: #93c5fd; border: 1px solid #334155;
}
.role-badge.light { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.switcher-pill.locked { opacity: 0.48; border-style: dashed; }

.access-pill-list { display: flex; flex-wrap: wrap; gap: 4px; }
.access-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 700;
  background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0;
}
.access-pill.none { background: #f8fafc; color: #94a3b8; border-color: #e2e8f0; text-decoration: line-through; }

.action-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* Modals & Access Matrix */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(15, 23, 42, 0.58);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  background: #fff; border-radius: 16px; padding: 22px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
}
.modal-card.sm { max-width: 440px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 800; }

.perm-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px; background: #f8fafc; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
}
.perm-check {
  display: flex !important; flex-direction: row !important; align-items: flex-start !important;
  gap: 7px; font-size: 12px !important; font-weight: 600 !important; color: #1e293b !important; cursor: pointer;
}
.app-access-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px; background: #f8fafc; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
}
.app-access-item { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #334155; }

.guide-banner {
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.guide-step {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.guide-step strong { font-size: 12.5px; color: var(--ink); }
.guide-step span { font-size: 11.5px; color: #475569; line-height: 1.45; }

.adv-details {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.adv-details summary { cursor: pointer; font-size: 12.5px; font-weight: 700; color: #334155; }
.adv-details[open] summary { margin-bottom: 10px; }

.plain-summary {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; line-height: 1.6; color: #1e293b;
}

@media (max-width: 900px) {
  .workspace-body { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}
