/* ═══════════════════════════════════════════════════════
   Pi Platform — Design System CSS
   Pi-huisstijl: rood (#CC0000), Segoe UI, strak & zakelijk
   ═══════════════════════════════════════════════════════ */

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --pi-red:        #CC0000;
  --pi-red-mid:    #D63333;
  --pi-red-dark:   #A83030;
  --pi-red-pale:   #FEF2F2;
  --pi-red-border: #FFC9C9;
  --pi-green:      #0F6E56;
  --pi-amber:      #854F0B;

  --gray-900: #1A1A1A;
  --gray-700: #444444;
  --gray-500: #777777;
  --gray-300: #CCCCCC;
  --gray-100: #F5F5F5;
  --white:    #FFFFFF;

  --sidebar-w:    240px;
  --header-h:     64px;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow-sm:    0 1px 4px rgba(0,0,0,.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,.12);
  --transition:   .15s ease;

  /* Aliassen voor achterwaartse compatibiliteit */
  --pi-teal:         #4b6d7a;
  --pi-teal-mid:     #76a0ad;
  --pi-teal-light:   #b2cad1;
  --pi-teal-pale:    #E3F7FC;
  --bg:              #F5F5F5;
  --bg-alt:          #e8e8e8;
  --white:           #FFFFFF;
  --text-primary:    #1A1A1A;
  --text-secondary:  #777777;
  --text-muted:      #999999;
  --success:         #0F6E56;
  --warning:         #854F0B;
  --danger:          #CC0000;
  --info:            #4b6d7a;
  --divider:         #E8E8E8;
  --sidebar-width:   240px;
  --topbar-height:   64px;
  --font:            'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius-sm:       6px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
ul, ol { list-style: none; }

/* ── Layout ────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

.app-header  { grid-column: 1/-1; grid-row: 1; }
.app-sidebar { grid-column: 1;    grid-row: 2; }
.app-main    { grid-column: 2;    grid-row: 2; overflow-y: auto; }

/* Ondersteuning voor oud #app-shell layout (flex-gebaseerd) */
#app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
#main-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}
#page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Header / Topbar ───────────────────────────────────── */
.app-header,
#topbar {
  background: var(--pi-red);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: var(--header-h);
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  flex-shrink: 0;
}
.header-logo  { height: 40px; width: auto; }
.header-divider { width: 1px; height: 32px; background: rgba(255,255,255,.3); }
.header-title { font-size: 18px; font-weight: 700; color: white; }
.header-sub   { font-size: 11px; color: rgba(255,255,255,.7); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.header-user  { font-size: 13px; color: rgba(255,255,255,.85); }
.header-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: white;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.header-btn:hover { background: rgba(255,255,255,.25); }

/* Topbar logo (oud systeem) */
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.01em;
}
.topbar-logo img,
.topbar-logo svg { width: 32px; height: 32px; flex-shrink: 0; }
.topbar-logo-name { color: white; }
.topbar-logo-name span { color: rgba(255,255,255,.75); }
.topbar-spacer { flex: 1; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.topbar-user:hover { background: rgba(255,255,255,.15); }
.topbar-user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.topbar-user-name { font-size: 13px; font-weight: 600; color: white; }
.topbar-user-role { font-size: 11px; color: rgba(255,255,255,.7); }
#topbar-hamburger {
  display: none;
  background: none;
  border: none;
  padding: 6px;
  color: rgba(255,255,255,.8);
  border-radius: var(--radius-sm);
}
#topbar-hamburger:hover { background: rgba(255,255,255,.15); }

/* ── Sidebar ────────────────────────────────────────────── */
.app-sidebar,
#sidebar {
  background: white;
  border-right: 1px solid #e8e8e8;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  width: var(--sidebar-w);
  transition: transform 0.25s ease;
}

/* Scrollbar sidebar */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 2px; }

.sidebar-section { padding: 20px 0 8px; }
.sidebar-label,
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-300);
  padding: 0 20px 6px;
  display: block;
}

/* Sidebar links — nieuw systeem */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--gray-700);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: var(--transition);
  cursor: pointer;
}
.sidebar-link:hover { background: var(--pi-red-pale); color: var(--pi-red); }
.sidebar-link.active {
  background: var(--pi-red-pale);
  color: var(--pi-red);
  border-left-color: var(--pi-red);
  font-weight: 600;
}
.sidebar-link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.sidebar-link.active svg, .sidebar-link:hover svg { opacity: 1; }
.sidebar-badge {
  margin-left: auto;
  background: var(--pi-red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

/* Nav items — oud systeem */
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 12px;
  margin: 1px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  position: relative;
  white-space: nowrap;
}
.nav-item:hover { background: var(--pi-red-pale); color: var(--pi-red); }
.nav-item.active {
  background: var(--pi-red-pale);
  color: var(--pi-red);
  font-weight: 600;
  border-left: 3px solid var(--pi-red);
  padding-left: 9px;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }
.nav-divider {
  height: 1px;
  background: #f0f0f0;
  margin: 8px 16px;
}

/* ── Page content ───────────────────────────────────────── */
.page { padding: 24px; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.page-sub   { font-size: 13px; color: var(--gray-500); margin-top: 2px; }
.page-header-actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Stat cards ─────────────────────────────────────────── */
.stats-grid,
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--pi-red);
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid #eee;
  border-left: 3px solid var(--pi-red);
  transition: border-left-color 0.15s;
}
.stat-card:hover { border-left-color: var(--pi-red-dark); }
.stat-card.green  { border-left-color: var(--pi-green); }
.stat-card.amber  { border-left-color: var(--pi-amber); }
.stat-card.gray   { border-left-color: var(--gray-300); }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.red    { background: var(--pi-red-pale);  color: var(--pi-red); }
.stat-icon.green  { background: #F0FDF4;              color: var(--pi-green); }
.stat-icon.amber  { background: #FFFBEB;              color: var(--pi-amber); }
.stat-icon.blue   { background: #EEF5FB;              color: #1B3A5C; }
.stat-icon svg { width: 20px; height: 20px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-trend { font-size: 11px; color: var(--gray-500); margin-top: 4px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none;
  height: 36px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary  { background: var(--pi-red);  color: white; }
.btn-primary:hover:not(:disabled)  { background: var(--pi-red-dark); box-shadow: 0 2px 8px rgba(204,0,0,.3); }

.btn-success  { background: var(--pi-green); color: white; }
.btn-success:hover:not(:disabled)  { background: #0A5040; }

.btn-outline,
.btn-secondary  { background: white; color: var(--pi-red); border: 1px solid var(--pi-red-border); }
.btn-outline:hover:not(:disabled),
.btn-secondary:hover:not(:disabled)  { background: var(--pi-red-pale); }

.btn-ghost    { background: transparent; color: var(--gray-700); border: 1px solid #e8e8e8; }
.btn-ghost:hover:not(:disabled)    { background: var(--gray-100); }

.btn-danger   { background: white; color: #c00; border: 1px solid #fcc; }
.btn-danger:hover:not(:disabled)   { background: #fef2f2; }

/* Teal-knop (achterwaartse compatibiliteit) */
.btn-teal { background: #4b6d7a; color: white; border: none; }
.btn-teal:hover:not(:disabled) { background: #3d5a65; box-shadow: 0 2px 8px rgba(75,109,122,.3); }

.btn-sm   { padding: 5px 10px; font-size: 12px; height: 28px; }
.btn-lg   { padding: 12px 24px; font-size: 15px; height: auto; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; }

/* ── Toolbar ────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-right { margin-left: auto; }
.toolbar-divider { width: 1px; height: 24px; background: #e8e8e8; }

/* ── Search & filters ───────────────────────────────────── */
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-input-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--gray-500);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  height: 36px;
  background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 10px center;
  transition: var(--transition);
}
.search-input:focus { border-color: var(--pi-red); box-shadow: 0 0 0 3px rgba(204,0,0,.1); }

.filter-select {
  padding: 0 28px 0 10px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: white;
  color: var(--gray-900);
  cursor: pointer;
  transition: var(--transition);
  height: 36px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23777' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.filter-select:focus { border-color: var(--pi-red); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid #e8e8e8;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tab-btn {
  height: 38px;
  padding: 0 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -2px;
  font-family: inherit;
}
.tab-btn:hover { color: var(--pi-red); }
.tab-btn.active { color: var(--pi-red); border-bottom-color: var(--pi-red); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Table ──────────────────────────────────────────────── */
.table-wrap,
.datagrid-wrapper { background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
table,
.datagrid { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--pi-red-dark);
  color: white;
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.datagrid th {
  background: var(--pi-red-pale);
  color: var(--pi-red-dark);
  border-bottom: 2px solid var(--pi-red-border);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
thead th:hover { background: var(--pi-red-mid); }
thead th.sort-asc::after  { content: ' ↑'; opacity: .8; }
thead th.sort-desc::after { content: ' ↓'; opacity: .8; }
tbody tr { border-bottom: 1px solid #f0f0f0; transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--pi-red-pale); cursor: pointer; }
tbody tr:nth-child(even) { background: #fafafa; }
tbody tr:nth-child(even):hover { background: var(--pi-red-pale); }
tbody tr.selected { background: var(--pi-red-pale); }
td { padding: 10px 14px; vertical-align: middle; }
.datagrid td { height: 42px; padding: 0 12px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.td-muted { color: var(--gray-500); font-size: 12px; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  border: 1px solid #eee;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--gray-900); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active   { background: #ecf9f4; color: var(--pi-green); }
.badge-locked   { background: var(--pi-red-pale); color: var(--pi-red); }
.badge-inactive { background: var(--gray-100); color: var(--gray-500); }
.badge-invited  { background: #FFF8E1; color: #7B5800; }
.badge-mfa      { background: #ecf9f4; color: var(--pi-green); }
.badge-no-mfa   { background: var(--pi-red-pale); color: var(--pi-red); }
.badge-role {
  background: var(--pi-red-pale);
  color: var(--pi-red-dark);
  border: 1px solid var(--pi-red-border);
}
.badge-success  { background: #ecf9f4; color: var(--pi-green); }
.badge-warning  { background: #FFF8E1; color: var(--pi-amber); }
.badge-info     { background: #EEF5FB; color: #1B3A5C; }
.badge-danger   { background: var(--pi-red-pale); color: var(--pi-red); }
.badge-neutral  { background: var(--gray-100); color: var(--gray-500); }
.badge-purple   { background: #F5F3FF; color: #7C3AED; }
.badge-teal     { background: #E3F7FC; color: #4b6d7a; }
.badge-dot::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid #f0f0f0;
  font-size: 12px;
  color: var(--gray-500);
  flex-wrap: wrap;
}
.page-btns { display: flex; gap: 4px; }
.page-btn {
  border: 1px solid #ddd;
  background: white;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
  color: var(--gray-900);
  font-family: inherit;
  height: 30px;
  min-width: 30px;
}
.page-btn:hover  { background: var(--pi-red-pale); border-color: var(--pi-red); color: var(--pi-red); }
.page-btn.active { background: var(--pi-red); border-color: var(--pi-red); color: white; }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transform: scale(.96);
  transition: transform .2s;
  display: flex;
  flex-direction: column;
  border-top: 3px solid var(--pi-red);
}
.modal-lg { max-width: 800px; }
.modal-overlay.open .modal { transform: scale(1); }
.modal-header {
  background: var(--pi-red);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 700; color: white; }
.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  opacity: .8;
  line-height: 1;
  padding: 0 4px;
  font-family: inherit;
}
.modal-close:hover { opacity: 1; }
.modal-body { padding: 24px; overflow-y: auto; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Forms ──────────────────────────────────────────────── */
/* Nieuw systeem: .field */
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-700);
  margin-bottom: 5px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--gray-900);
  outline: none;
  transition: border-color var(--transition);
  background: white;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--pi-red);
  box-shadow: 0 0 0 3px rgba(204,0,0,.1);
}
.field input.is-error { border-color: var(--pi-red); background: var(--pi-red-pale); }
.field-error { font-size: 11px; color: var(--pi-red); margin-top: 4px; }
.field textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 11px; color: var(--gray-500); margin-top: 4px; }

/* Oud systeem: .form-group / .form-control */
.form-group,
.form-row    { margin-bottom: 16px; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3  { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 5px;
}
.form-control {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--gray-900);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  font-family: inherit;
}
.form-control:focus {
  border-color: var(--pi-red);
  box-shadow: 0 0 0 3px rgba(204,0,0,.1);
}
textarea.form-control { height: auto; padding: 8px 10px; resize: vertical; }
select.form-control   { cursor: pointer; }

/* ── Alert / toast ──────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error   { background: var(--pi-red-pale); color: var(--pi-red-dark); border: 1px solid var(--pi-red-border); }
.alert-success { background: #ecf9f4; color: var(--pi-green); border: 1px solid #b8e8d8; }
.alert-info    { background: #EEF5FB; color: #1B3A5C; border: 1px solid #c9dff0; }
.alert-warn    { background: #FFF8E1; color: var(--pi-amber); border: 1px solid #FFE082; }

/* ── Toast ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  max-width: 360px;
  pointer-events: all;
  background: white;
  border-left: 4px solid var(--gray-300);
  animation: toast-in 0.25s ease;
}
.toast.success { border-left-color: var(--pi-green); }
.toast.error   { border-left-color: var(--pi-red); }
.toast.info    { border-left-color: #1B3A5C; }
.toast.warning { border-left-color: var(--pi-amber); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Loading / Spinner ──────────────────────────────────── */
.spinner-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--pi-red-border);
  border-top-color: var(--pi-red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.7);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
  gap: 10px;
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state svg  { width: 40px; height: 40px; opacity: 0.35; }
.empty-state h3   { font-size: 15px; font-weight: 600; color: var(--pi-red); margin-bottom: 6px; }
.empty-state p    { font-size: 13px; }

/* ── Back Button ────────────────────────────────────────── */
.back-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--pi-red);
  background: none;
  border: 1px solid var(--pi-red-border);
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
}
.back-btn:hover { background: var(--pi-red-pale); }

/* ── Detail Header ──────────────────────────────────────── */
.detail-header {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  border-left: 4px solid var(--pi-red);
}
.detail-header-info { flex: 1; min-width: 200px; }
.detail-object-name { font-size: 20px; font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.detail-meta { font-size: 12px; color: var(--gray-500); display: flex; flex-wrap: wrap; gap: 12px; margin-top: 6px; }
.detail-meta span { display: flex; align-items: center; gap: 4px; }
.detail-header-actions { display: flex; gap: 8px; align-items: flex-start; }

/* ── MFA warning ────────────────────────────────────────── */
.mfa-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #FFF8E1;
  border: 1px solid #FFE082;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--pi-amber);
  margin-bottom: 16px;
}

/* ── Timeline ───────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: flex;
  gap: 14px;
  padding-bottom: 20px;
  position: relative;
}
.timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 11px; top: 24px; bottom: 0;
  width: 2px;
  background: #f0f0f0;
}
.timeline-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid #ddd;
  background: white;
  flex-shrink: 0;
  margin-top: 2px;
}
.timeline-dot.done   { background: var(--pi-green); border-color: var(--pi-green); }
.timeline-dot.active { background: var(--pi-red);   border-color: var(--pi-red); }
.timeline-dot.danger { background: var(--pi-red);   border-color: var(--pi-red); }
.timeline-content { flex: 1; }
.timeline-label { font-size: 13px; font-weight: 600; }
.timeline-time  { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* ── Key-Value List ─────────────────────────────────────── */
.kv-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.kv-item {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.kv-item:nth-child(odd) { border-right: 1px solid #f0f0f0; }
.kv-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gray-500);
  margin-bottom: 2px;
  letter-spacing: 0.05em;
}
.kv-value { font-size: 13px; color: var(--gray-900); }

/* ── Section divider ────────────────────────────────────── */
.section-divider { height: 1px; background: #f0f0f0; margin: 20px 0; }

/* ── Info Banner ────────────────────────────────────────── */
.info-banner {
  background: var(--pi-red-pale);
  border: 1px solid var(--pi-red-border);
  border-left: 3px solid var(--pi-red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--pi-red-dark);
  margin-bottom: 16px;
}

/* ── Map ────────────────────────────────────────────────── */
#map-container {
  height: 340px;
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Login Page ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--pi-red-dark) 0%, var(--pi-red) 50%, var(--pi-red-mid) 100%);
  padding: 20px;
}
.login-card {
  background: white;
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
  padding: 44px 40px 36px;
  width: 100%;
  max-width: 400px;
}
.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 32px;
}
.login-logo svg,
.login-logo img { width: 64px; height: 64px; }
.login-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--pi-red);
  letter-spacing: -0.02em;
}
.login-logo-sub {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: -4px;
  letter-spacing: 0.02em;
}
.login-title    { font-size: 17px; font-weight: 600; margin-bottom: 5px; color: var(--gray-900); }
.login-subtitle { font-size: 13px; color: var(--gray-500); margin-bottom: 24px; }
.login-error {
  background: var(--pi-red-pale);
  color: var(--pi-red-dark);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--pi-red);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.login-btn {
  width: 100%;
  height: 44px;
  background: var(--pi-red);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
}
.login-btn:hover { background: var(--pi-red-dark); box-shadow: 0 4px 12px rgba(204,0,0,.35); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.login-card .form-control:focus {
  border-color: var(--pi-red);
  box-shadow: 0 0 0 3px rgba(204,0,0,.1);
}

/* ── Checkbox Toggle ────────────────────────────────────── */
.toggle-row { display: flex; align-items: center; gap: 10px; height: 36px; }
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #D1D5DB;
  border-radius: 10px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--pi-red); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 240px; --sidebar-width: 240px; }
  .app-sidebar { display: none; }
  .app-layout  { grid-template-columns: 1fr; }
  .app-main    { grid-column: 1; }

  #topbar-hamburger { display: flex; }
  #sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    bottom: 0;
    z-index: 150;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.20);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 140;
  }
  #sidebar-overlay.visible { display: block; }
  #page-content { padding: 16px; }
  .stats-grid, .stats-bar { grid-template-columns: 1fr 1fr; }
  .field-row, .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .kv-list { grid-template-columns: 1fr; }
  .kv-item:nth-child(odd) { border-right: none; }
  .login-card { padding: 32px 24px; }
}

@media (max-width: 480px) {
  .stats-grid, .stats-bar { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; }
}
