:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --error-bg: #fef2f2;
  --error-ink: #b91c1c;
  --warn-bg: #fffbeb;
  --warn-ink: #b45309;
  --ok-bg: #ecfdf5;
  --ok-ink: #047857;
  --admin-bg: #dbeafe;
  --admin-ink: #1e40af;
  --staff-bg: #f3f4f6;
  --staff-ink: #374151;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

.mt-sm { margin-top: 0.75rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.mb-md { margin-bottom: 1rem; }
.mb-lg { margin-bottom: 1.5rem; }

/* Auth Screen */
.auth-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.brand-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--muted);
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
}

.field input,
.field select,
.filter-bar input,
.filter-bar select {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.preview-box {
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-danger-outline {
  background: transparent;
  color: var(--error-ink);
  border: 1px solid #fecaca;
}

.btn-sm {
  min-height: 34px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

.alert {
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-ink);
  border: 1px solid #fecaca;
}

.security-note {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Authenticated App Shell */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-item {
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}

.nav-item.active {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
}

.nav-item:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.role-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--staff-bg);
  color: var(--staff-ink);
}

.role-badge.admin {
  background: var(--admin-bg);
  color: var(--admin-ink);
}

.content-area {
  padding: 1.5rem;
  padding-bottom: 5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.kpi-card.kpi-warn {
  border-left: 4px solid #d97706;
}

.kpi-card.kpi-highlight {
  border-left: 4px solid var(--primary);
}

.kpi-label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
}

/* Cards & Forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.field-span-2 {
  grid-column: span 2;
}

.field-span-full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

.report-controls {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.import-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 0.7rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  font-weight: 600;
  color: var(--muted);
  background: #f9fafb;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-cell {
  text-align: center !important;
  color: var(--muted);
  padding: 1.5rem !important;
}

/* Status & Payment Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-due { background: var(--error-bg); color: var(--error-ink); }
.badge-neutral { background: var(--staff-bg); color: var(--staff-ink); }

/* Masters Grid */
.masters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
}

.simple-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.simple-list li {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Mobile Navigation */
.mobile-only { display: none; }
.mobile-bottom-nav { display: none; }

@media (max-width: 900px) {
  .filter-bar,
  .report-controls {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-only { display: inline-flex; }
  .field-span-2 { grid-column: span 1; }
  .filter-bar,
  .report-controls { grid-template-columns: 1fr; }
  .topbar { padding: 0.9rem 1rem; }
  .content-area { padding: 1rem; padding-bottom: 5.5rem; }
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 20;
  }
  .mobile-nav-btn {
    flex: 1;
    min-height: 56px;
    border: none;
    background: transparent;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
  }
  .mobile-nav-btn.active {
    color: var(--primary);
    border-top: 2px solid var(--primary);
  }
}

/* Print Styles for Accounting Reports */
@media print {
  .no-print {
    display: none !important;
  }
  body {
    background: #ffffff;
  }
  .content-area {
    padding: 0;
  }
  .card {
    border: none;
    box-shadow: none;
    padding: 0;
  }
}
