/* Ancillarate Billing — Ops UI · Brand Design System */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Brand */
  --brand-primary:       hsl(217, 91%, 40%);
  --brand-primary-light: hsl(217, 91%, 60%);
  --brand-primary-dark:  hsl(217, 91%, 28%);
  --brand-accent:        #FF7C24;
  --brand-accent-soft:   #FFC8B2;

  /* Light theme surfaces */
  --bg:          hsl(220, 15%, 97%);
  --surface-1:   hsl(0, 0%, 100%);
  --surface-2:   hsl(217, 10%, 96%);
  --surface-3:   hsl(217, 20%, 88%);
  --border:      hsl(217, 20%, 88%);
  --border-soft: hsl(217, 20%, 92%);

  /* Text */
  --text:        hsl(220, 10%, 15%);
  --text-muted:  hsl(215, 15%, 45%);
  --text-subtle: hsl(215, 15%, 62%);

  /* Semantic (accent = brand orange) */
  --accent:       #FF7C24;
  --accent-dim:   rgba(255,124,36,.10);
  --accent-hover: #E06010;

  --info:         #1F83A1;
  --info-dim:     rgba(31,131,161,.10);
  --warning:      #E3A800;
  --warning-dim:  rgba(227,168,0,.10);
  --danger:       #D84335;
  --danger-dim:   rgba(216,67,53,.10);
  --success:      #2EA24C;
  --success-dim:  rgba(46,162,76,.10);

  /* Sidebar — white, matching Backend */
  --sidebar-w:           240px;
  --sidebar-bg:          hsl(0, 0%, 100%);
  --sidebar-border:      hsl(217, 20%, 88%);
  --sidebar-text:        hsl(215, 15%, 45%);
  --sidebar-text-active: hsl(220, 10%, 15%);
  --sidebar-hover-bg:    hsl(217, 10%, 96%);
  --sidebar-active-bg:   hsl(217, 10%, 96%);
  --sidebar-active-color:hsl(217, 91%, 40%);

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 2px rgba(21,101,216,.04);
  --shadow-lg: 0 4px 16px rgba(21,101,216,.08);
  --transition: 150ms cubic-bezier(.4,0,.2,1);

  --font-mono: 'JetBrains Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 50;
}

.sidebar-header {
  padding: 24px 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}

.logo-mark {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-icon img { width: 34px; height: 34px; object-fit: contain; }

.logo-text { display: flex; flex-direction: column; gap: 1px; }
.logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.logo-sub {
  font-size: 10px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 500;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-subtle);
  padding: 16px 20px 6px;
}

.nav-links { list-style: none; padding: 8px 10px; flex: 1; overflow-y: auto; }
.nav-links li { margin-bottom: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}

.nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
  font-weight: 600;
}

.nav-link.active .nav-icon svg { color: var(--sidebar-active-color); }

.nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-subtle);
  transition: color var(--transition);
}

.nav-link:hover .nav-icon { color: var(--brand-primary); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-footer #sidebar-user-role { color: var(--text-subtle); }

.env-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 20px;
}

.env-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}

.env-development { background: rgba(46,162,76,.15);  color: #2EA24C; }
.env-staging     { background: rgba(227,168,0,.15);  color: #E3A800; }
.env-production  { background: rgba(216,67,53,.15);  color: #D84335; }

/* Sidebar logout button */
.sidebar .btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.sidebar .btn-ghost:hover {
  background: var(--sidebar-hover-bg);
  color: var(--text);
}

/* ── Main content ─────────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
}

.page-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: -0.3px;
}

.header-actions { display: flex; gap: 10px; align-items: center; }

.content { padding: 28px 32px; }

/* ── Cards ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

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

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

/* ── Stats grid ───────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition);
  cursor: default;
}

.stat-card:hover {
  border-color: var(--brand-primary-light);
  box-shadow: var(--shadow-lg);
}

.stat-card .stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-subtle);
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  margin: 8px 0 4px;
  color: var(--brand-primary);
  letter-spacing: -0.5px;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Tables ───────────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-subtle);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-muted);
  font-size: 13px;
}

.data-table td:first-child { color: var(--text); font-weight: 500; }

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr {
  transition: background var(--transition);
  cursor: pointer;
}

.data-table tbody tr:hover td { background: var(--surface-2); color: var(--text); }

.loading-row {
  text-align: center;
  color: var(--text-subtle);
  padding: 32px !important;
  font-style: italic;
  font-size: 13px;
}

/* ── Badges ───────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
}

.badge-pending, .badge-draft     { background: var(--warning-dim); color: #B38600; }
.badge-ingested, .badge-review   { background: var(--info-dim);    color: #1F83A1; }
.badge-reconciled                { background: var(--success-dim); color: #2EA24C; }
.badge-failed, .badge-cancelled  { background: var(--danger-dim);  color: #D84335; }
.badge-disputed                  { background: var(--danger-dim);  color: #D84335; }
.badge-approved                  { background: var(--success-dim); color: #2EA24C; border: 1px solid rgba(46,162,76,.25); }
.badge-issued, .badge-paid, .badge-settled { background: hsl(217, 91%, 95%); color: var(--brand-primary); }
.badge-issuing, .badge-running   { background: var(--accent-dim);  color: #E06010; }
.badge-succeeded                 { background: var(--success-dim); color: #2EA24C; }
.badge-warning                   { background: var(--warning-dim); color: #B38600; padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 700; }

/* ── Buttons ──────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(255,124,36,.25);
}

.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 6px rgba(255,124,36,.35); }

.btn-secondary {
  background: var(--surface-1);
  color: var(--brand-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface-2); border-color: var(--brand-primary-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(216,67,53,.2); }
.btn-danger:hover { background: rgba(216,67,53,.15); }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* ── Forms ────────────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 7px;
}

.form-group input:not([type=checkbox]):not([type=radio]),
.form-group select,
.form-group textarea,
.filter-bar select,
.filter-bar input,
.field-input,
.field-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface-1);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.filter-bar select,
.filter-bar input { width: auto; min-width: 160px; }

.form-group input:focus,
.form-group select:focus,
.filter-bar select:focus,
.filter-bar input:focus,
.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,124,36,.12);
}

.form-group input::placeholder,
.field-input::placeholder { color: var(--text-subtle); }

/* ── Compact inline inputs (dense table-cell editing) ────────────────────── */
.input-compact,
.select-compact {
  padding: 6px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-compact { width: 82px; text-align: right; }
.select-compact { cursor: pointer; }

.input-compact:focus,
.select-compact:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,124,36,.12);
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── File drop zone ───────────────────────────────────────────────────────────── */
.file-drop-zone {
  border: 2px dashed var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 36px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  color: var(--text-muted);
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.file-drop-zone input[type=file] { position: absolute; opacity: 0; width: 0; height: 0; }
.file-label { color: var(--accent); cursor: pointer; font-weight: 600; }
.file-hint { font-size: 11px; color: var(--text-subtle); margin-top: 8px; }

/* ── Modal ────────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(21,101,216,.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 520px;
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: -0.3px;
}

.modal-close {
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background var(--transition), color var(--transition);
}

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

/* ── Layout helpers ───────────────────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.mt-20 { margin-top: 20px; }

/* ── Tabs ─────────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px;
  margin-bottom: 20px;
  width: fit-content;
}

.tab {
  background: none;
  border: none;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
}

.tab:hover { color: var(--text); background: var(--surface-1); }

.tab.active {
  background: var(--surface-1);
  color: var(--brand-primary);
  box-shadow: var(--shadow);
}

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

/* ── Side panel ───────────────────────────────────────────────────────────────── */
.side-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 420px;
  height: 100vh;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
  z-index: 45;
  box-shadow: -4px 0 16px rgba(21,101,216,.06);
}

.side-panel.open { transform: translateX(0); }

/* ── Scrollbar ────────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ── Monospace (amounts, IDs, codes) ─────────────────────────────────────────── */
.mono, code, .amount, .tx-id {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ── Reduced motion ───────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
