/* ═══════════════════════════════════════════════════════════════════════════
   MFI Platform — main.css
   Aesthetic: Precise Utilitarian — dense, data-forward, refined dark chrome
   Fonts: IBM Plex Mono (headings/labels) + IBM Plex Sans (body)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg: #0d0f12;
  --bg-1: #13161b;
  --bg-2: #1a1d24;
  --bg-3: #21252e;
  --bg-4: #2a2f3a;
  --border: #2c3040;
  --border-soft: #232733;

  --text: #d4d8e2;
  --text-2: #8892a4;
  --text-3: #555f73;
  --text-inv: #0d0f12;

  --accent: #2dd4a0;
  --accent-dim: #1a7a5e;
  --accent-glow: rgba(45, 212, 160, 0.12);

  --blue: #4a9eff;
  --blue-dim: #1e4a7a;

  --warn: #f0a500;
  --warn-dim: #7a5200;

  --danger: #f05050;
  --danger-dim: #7a2020;

  --success: #2dd4a0;
  --info: #4a9eff;

  --sidebar-w: 196px;
  --sidebar-w-collapsed: 48px;
  --topbar-h: 40px;

  --radius: 4px;
  --radius-lg: 7px;

  --font-mono: 'IBM Plex Mono', monospace;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;

  --t-fast: 120ms ease;
  --t-med: 200ms ease;
}

[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-1: #ffffff;
  --bg-2: #e4e7ec;
  --bg-3: #d1d5db;
  --bg-4: #9ca3af;
  --border: #d1d5db;
  --border-soft: #e5e7eb;

  --text: #111827;
  --text-2: #4b5563;
  --text-3: #6b7280;
  --text-inv: #ffffff;

  --accent: #059669;
  --accent-dim: #d1fae5;
  --accent-glow: rgba(5, 150, 105, 0.12);

  --blue: #2563eb;
  --blue-dim: #dbeafe;

  --warn: #d97706;
  --warn-dim: #fef3c7;

  --danger: #dc2626;
  --danger-dim: #fee2e2;

  --success: #059669;
  --info: #2563eb;
}

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

html {
  font-size: 13px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) var(--bg-1);
}

/* Global Webkit Scrollbar for Dark Mode */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-1);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: 5px;
  border: 2px solid var(--bg-1);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  color: #fff;
}

img {
  max-width: 100%;
  display: block;
}

/* ── App Layout ──────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  transition: width var(--t-med);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
}

.logo-mark {
  color: var(--accent);
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1;
}

.logo-text {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-transform: uppercase;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  flex-shrink: 0;
  transition: color var(--t-fast);
}

.sidebar-collapse-btn:hover {
  color: var(--text);
}

/* Scope selector */
.sidebar-scope {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-soft);
}

.scope-select {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 4px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  outline: none;
}

.scope-select:focus {
  border-color: var(--accent-dim);
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 400;
  transition: all var(--t-fast);
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.nav-item:hover {
  color: var(--text);
  background: var(--bg-2);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.nav-icon svg {
  width: 14px;
  height: 14px;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--t-med), width var(--t-med);
}

/* Nav groups */
.nav-group {}

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.nav-group-toggle:hover {
  color: var(--text);
  background: var(--bg-2);
}

.nav-arrow {
  margin-left: auto;
  flex-shrink: 0;
  transition: transform var(--t-med);
}

.nav-group.open .nav-arrow {
  transform: rotate(180deg);
}

.nav-children {
  display: none;
  padding-left: 22px;
  border-left: 1px solid var(--border-soft);
  margin-left: 17px;
}

.nav-group.open .nav-children {
  display: block;
}

.nav-child {
  display: block;
  padding: 5px 10px;
  color: var(--text-3);
  font-size: 11.5px;
  transition: all var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
  border-radius: var(--radius);
}

.nav-child:hover {
  color: var(--text);
  background: var(--bg-2);
}

.nav-child.active {
  color: var(--accent);
  font-weight: 500;
}

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px 10px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 10px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  color: var(--text-3);
  padding: 3px;
  flex-shrink: 0;
  transition: color var(--t-fast);
}

.logout-btn:hover {
  color: var(--danger);
}

/* Collapsed state */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-arrow,
.sidebar.collapsed .logo-text,
.sidebar.collapsed .user-info,
.sidebar.collapsed .sidebar-scope,
.sidebar.collapsed .nav-children {
  display: none;
}

.sidebar.collapsed .nav-group.open .nav-children {
  display: none;
}

/* ── Main Wrapper ─────────────────────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-width: 0;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--t-med), width var(--t-med);
}

.sidebar.collapsed~.main-wrapper {
  margin-left: var(--sidebar-w-collapsed);
  width: calc(100% - var(--sidebar-w-collapsed));
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-3);
}

.bc-item {
  color: var(--text-2);
}

.bc-item:last-child {
  color: var(--text);
  font-weight: 500;
}

.bc-sep {
  color: var(--text-3);
}

/* Search */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 7px;
  color: var(--text-3);
  pointer-events: none;
}

.search-input {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 11.5px;
  padding: 5px 10px 5px 26px;
  border-radius: var(--radius);
  width: 200px;
  outline: none;
  transition: all var(--t-fast);
}

.search-input:focus {
  border-color: var(--accent-dim);
  width: 240px;
}

.search-input::placeholder {
  color: var(--text-3);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 300px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 300;
  overflow: hidden;
}

.search-results.show {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--t-fast);
  text-decoration: none;
}

.search-result-item:hover {
  background: var(--bg-3);
}

.sr-type {
  font-size: 9px;
  font-family: var(--font-mono);
  background: var(--bg-4);
  color: var(--text-3);
  padding: 1px 5px;
  border-radius: 2px;
}

.sr-label {
  font-size: 12px;
  color: var(--text);
  flex: 1;
}

.sr-sub {
  font-size: 11px;
  color: var(--text-3);
}

/* Topbar buttons */
.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 5px 7px;
  border-radius: var(--radius);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  transition: all var(--t-fast);
}

.topbar-btn:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-family: var(--font-mono);
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 2px;
}

.topbar-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

/* ── Page Content ─────────────────────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 14px;
  max-width: 100%;
  overflow-x: auto;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Alerts / Messages ────────────────────────────────────────────────────── */
.messages-container {
  padding: 0 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  gap: 8px;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-success {
  background: rgba(45, 212, 160, 0.1);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
}

.alert-error,
.alert-danger {
  background: rgba(240, 80, 80, 0.1);
  border: 1px solid var(--danger-dim);
  color: var(--danger);
}

.alert-warning {
  background: rgba(240, 165, 0, 0.1);
  border: 1px solid var(--warn-dim);
  color: var(--warn);
}

.alert-info {
  background: rgba(74, 158, 255, 0.1);
  border: 1px solid var(--blue-dim);
  color: var(--blue);
}

.alert-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.7;
  padding: 0 2px;
  line-height: 1;
}

.alert-close:hover {
  opacity: 1;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.card-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-body {
  padding: 12px 14px;
}

.card-footer {
  padding: 8px 14px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* ── Stat Cards (Dashboard) ────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  cursor: pointer;
  transition: all var(--t-fast);
  text-decoration: none;
  display: block;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent);
  opacity: 0.4;
}

.stat-card.warn::before {
  background: var(--warn);
}

.stat-card.danger::before {
  background: var(--danger);
}

.stat-card.blue::before {
  background: var(--blue);
}

.stat-card:hover {
  border-color: var(--accent-dim);
  background: var(--bg-2);
  transform: translateY(-1px);
}

.stat-label {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
  margin-bottom: 5px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.stat-sub {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 3px;
}

.stat-change {
  font-size: 10px;
  font-family: var(--font-mono);
}

.stat-change.up {
  color: var(--accent);
}

.stat-change.down {
  color: var(--danger);
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead tr {
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 8px 10px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

th:hover {
  color: var(--text-2);
}

th.sorted-asc::after {
  content: ' ↑';
  color: var(--accent);
}

th.sorted-desc::after {
  content: ' ↓';
  color: var(--accent);
}

td {
  padding: 7px 10px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--bg-2);
  color: var(--text);
}

tbody tr.clickable {
  cursor: pointer;
}

.td-mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

.td-name {
  color: var(--text);
  font-weight: 500;
}

.td-link {
  color: var(--accent);
}

.td-link:hover {
  text-decoration: underline;
}

.td-muted {
  color: var(--text-3);
  font-size: 11px;
}

.td-amount {
  font-family: var(--font-mono);
  text-align: right;
}

/* Table toolbar */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
  background: var(--bg-1);
}

.table-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.table-info {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  font-family: var(--font-mono);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-top: 1px solid var(--border-soft);
}

.page-btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--t-fast);
  min-width: 28px;
  text-align: center;
}

.page-btn:hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

.page-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inv);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: #25b88a;
  color: var(--text-inv);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}

.btn-outline:hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--bg-3);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #d04040;
}

.btn-warn {
  background: var(--warn);
  color: var(--text-inv);
  border-color: var(--warn);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
  gap: 4px;
}

.btn-xs {
  padding: 3px 6px;
  font-size: 10.5px;
  gap: 3px;
}

.btn-icon {
  padding: 5px;
}

.btn svg {
  width: 13px;
  height: 13px;
}

.btn-sm svg {
  width: 12px;
  height: 12px;
}

.btn-xs svg {
  width: 11px;
  height: 11px;
}

/* ── Badges / Pills ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-success {
  background: rgba(45, 212, 160, 0.15);
  color: var(--accent);
}

.badge-danger {
  background: rgba(240, 80, 80, 0.15);
  color: var(--danger);
}

.badge-warn {
  background: rgba(240, 165, 0, 0.15);
  color: var(--warn);
}

.badge-info {
  background: rgba(74, 158, 255, 0.15);
  color: var(--blue);
}

.badge-muted {
  background: var(--bg-4);
  color: var(--text-3);
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-section {
  margin-bottom: 16px;
}

.form-section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.form-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.form-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.form-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.span-2 {
  grid-column: span 2;
}

.form-group.span-3 {
  grid-column: span 3;
}

.form-group.full {
  grid-column: 1 / -1;
}

label {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-3);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-control,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="password"],
select,
textarea {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 6px 9px;
  border-radius: var(--radius);
  width: 100%;
  outline: none;
  transition: border-color var(--t-fast);
  appearance: none;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-dim);
  background: var(--bg-2);
}

.form-control::placeholder {
  color: var(--text-3);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 24 15'%3E%3Cpath d='M0 0l12 15 12-15z' fill='%23555f73'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 28px;
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 70px;
}

.form-hint {
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 2px;
}

.form-error {
  font-size: 10.5px;
  color: var(--danger);
  margin-top: 2px;
}

.field-error {
  border-color: var(--danger) !important;
}

/* Checkbox / Radio */
.check-group {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.check-group input[type="checkbox"],
.check-group input[type="radio"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.check-label {
  font-size: 12px;
  color: var(--text-2);
  font-family: var(--font-sans);
}

/* File upload */
.file-upload {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--t-fast);
  background: var(--bg-2);
}

.file-upload:hover {
  border-color: var(--accent-dim);
  background: var(--bg-3);
}

.file-upload-label {
  font-size: 11px;
  color: var(--text-3);
}

.file-preview {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 6px auto 0;
}

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 400;
  display: none;
  backdrop-filter: blur(2px);
}

.modal-backdrop.show {
  display: block;
}

.modal {
  position: fixed;
  z-index: 500;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  /* Center with inset + margin so animation transform doesn't fight centering */
  inset: 0;
  margin: auto;
  height: fit-content;
  animation: modalIn 0.15s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(-6px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-sm {
  width: 420px;
}

.modal-md {
  width: 620px;
}

.modal-lg {
  width: 860px;
}

.modal-xl {
  width: min(95vw, 1100px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 5px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Multi-step modal */
.modal-steps {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.modal-step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--t-fast);
}

.modal-step.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.modal-step.done {
  color: var(--text-2);
}

.step-num {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-4);
  font-family: var(--font-mono);
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-step.active .step-num {
  background: var(--accent-dim);
  color: var(--accent);
}

.modal-step.done .step-num {
  background: var(--accent);
  color: var(--text-inv);
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  overflow-x: auto;
}

.tab {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: all var(--t-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-sans);
}

.tab:hover {
  color: var(--text-2);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ── Timeline / Activity ──────────────────────────────────────────────────── */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  position: relative;
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
  flex-shrink: 0;
}

.timeline-body {
  flex: 1;
}

.timeline-title {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.timeline-meta {
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 2px;
}

/* ── Approval Steps ───────────────────────────────────────────────────────── */
.approval-chain {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.approval-step {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  color: var(--text-3);
  background: var(--bg-3);
}

.approval-step.approved {
  border-color: var(--accent-dim);
  background: rgba(45, 212, 160, 0.08);
  color: var(--accent);
}

.approval-step.rejected {
  border-color: var(--danger-dim);
  background: rgba(240, 80, 80, 0.08);
  color: var(--danger);
}

.approval-step.pending {
  border-color: var(--warn-dim);
  background: rgba(240, 165, 0, 0.08);
  color: var(--warn);
}

.approval-arrow {
  color: var(--text-3);
  font-size: 10px;
}

/* ── Notification Panel ───────────────────────────────────────────────────── */
.notif-panel {
  position: fixed;
  top: var(--topbar-h);
  right: -340px;
  width: 320px;
  height: calc(100vh - var(--topbar-h));
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  z-index: 300;
  transition: right var(--t-med);
  display: flex;
  flex-direction: column;
}

.notif-panel.open {
  right: 0;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
}

.notif-mark-all {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font-sans);
}

.notif-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.notif-item {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--t-fast);
}

.notif-item:hover {
  background: var(--bg-2);
}

.notif-item.unread {
  border-left: 2px solid var(--accent);
}

.notif-title {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.notif-msg {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}

.notif-time {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 3px;
  font-family: var(--font-mono);
}

.notif-empty {
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  padding: 24px 0;
}

.panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 290;
  display: none;
}

.panel-overlay.show {
  display: block;
}

/* ── Profile Layout ───────────────────────────────────────────────────────── */
.profile-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 10px;
  align-items: start;
}

.profile-sidebar-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky;
  top: calc(var(--topbar-h) + 14px);
}

.profile-avatar-block {
  text-align: center;
  padding: 20px 14px 14px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  margin: 0 auto 8px;
  display: block;
}

.profile-avatar-initials {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
}

.profile-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.profile-id {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
}

.profile-meta-list {
  list-style: none;
  padding: 10px 0;
}

.profile-meta-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
  font-size: 11px;
  border-bottom: 1px solid var(--border-soft);
}

.profile-meta-item:last-child {
  border-bottom: none;
}

.pm-key {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10px;
}

.pm-val {
  color: var(--text);
  font-weight: 500;
  text-align: right;
}

/* ── Grid Layouts ─────────────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.flex {
  display: flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: 6px;
}

.gap-3 {
  gap: 10px;
}

.gap-4 {
  gap: 14px;
}

.mt-1 {
  margin-top: 4px;
}

.mt-2 {
  margin-top: 8px;
}

.mt-3 {
  margin-top: 12px;
}

.mb-1 {
  margin-bottom: 4px;
}

.mb-2 {
  margin-bottom: 8px;
}

.mb-3 {
  margin-bottom: 12px;
}

.text-mono {
  font-family: var(--font-mono);
}

.text-xs {
  font-size: 10.5px;
}

.text-sm {
  font-size: 11.5px;
}

.text-muted {
  color: var(--text-3);
}

.text-accent {
  color: var(--accent);
}

.text-danger {
  color: var(--danger);
}

.text-warn {
  color: var(--warn);
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

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

.empty-state-icon {
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.4;
}

.empty-state-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 4px;
}

.empty-state-sub {
  font-size: 11.5px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.page-loading {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -10px);
  transition: opacity .15s ease, transform .15s ease;
}

.page-loading.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.page-loading .spinner {
  width: 14px;
  height: 14px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Auth Layout ──────────────────────────────────────────────────────────── */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(45, 212, 160, 0.04) 0%, transparent 60%);
}

.auth-card {
  width: 380px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.auth-card-header {
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.auth-logo {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--accent);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 11px;
  color: var(--text-3);
}

.auth-card-body {
  padding: 20px 24px 24px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--t-med);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0 !important;
  }

  .profile-layout {
    grid-template-columns: 1fr;
  }

  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .modal-lg,
  .modal-xl {
    width: 98vw;
  }
}

@media (max-width: 600px) {

  .form-grid,
  .form-grid-2,
  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .form-group.span-2,
  .form-group.span-3 {
    grid-column: 1;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-sm,
  .modal-md {
    width: 97vw;
  }
}