/* ======================== RESET & BASE ======================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 1px 3px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,0.07), 0 2px 4px -2px rgba(15,23,42,0.05);
  --shadow-lg: 0 10px 25px -5px rgba(15,23,42,0.12), 0 8px 10px -6px rgba(15,23,42,0.08);
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

::selection { background: rgba(37,99,235,0.18); }

/* Quieter, thinner scrollbars throughout */
* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: padding-box; }

/* Visible keyboard focus for anything interactive that has no ring of its own */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ======================== SIDEBAR ======================== */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}
.sidebar::-webkit-scrollbar-thumb { background: #475569; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #64748b; }

.sidebar-header {
  padding: 22px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  z-index: 1;
}

.sidebar-header h2 { color: #fff; font-size: 1.3rem; letter-spacing: -0.01em; }
.sidebar-header p { font-size: 0.75rem; color: #94a3b8; margin-top: 4px; }

.sidebar nav { padding: 10px 0 24px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active {
  background: rgba(37,99,235,0.16);
  color: #fff;
  border-left-color: var(--sidebar-active);
  font-weight: 600;
}

.sidebar nav a .icon { font-size: 1.1rem; width: 24px; text-align: center; }

.nav-section {
  padding: 14px 20px 5px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #64748b;
  font-weight: 700;
  margin-top: 4px;
}

/* ======================== MAIN CONTENT ======================== */
.main-content {
  margin-left: 250px;
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
  max-width: 100%;
}

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

.page-header h1 { font-size: 1.55rem; color: var(--text); font-weight: 700; letter-spacing: -0.02em; }

/* ======================== CARDS ======================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card h3 { letter-spacing: -0.01em; }

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

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.yellow { background: #fef3c7; color: #f59e0b; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }

.stat-info h3 { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.stat-info p { font-size: 1.5rem; font-weight: 700; margin-top: 3px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ======================== FORMS ======================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

.form-group input:hover:not(:disabled):not([readonly]),
.form-group select:hover:not(:disabled):not([readonly]),
.form-group textarea:hover:not(:disabled):not([readonly]) {
  border-color: #cbd5e1;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-group textarea { resize: vertical; min-height: 80px; }

/* Disabled / read-only fields (the pale-yellow highlight is intentional -
   it marks auto-filled / computed values across the portal). */
.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled,
.form-group input[readonly],
.form-group select[readonly],
.form-group textarea[readonly],
input:disabled,
select:disabled,
textarea:disabled,
input[readonly],
select[readonly],
textarea[readonly] {
  background: #fef9e7 !important;
  color: #1e293b !important;
  -webkit-text-fill-color: #1e293b !important;
  opacity: 1 !important;
  border-color: #e2d47a;
  cursor: not-allowed;
}

/* ======================== BUTTONS ======================== */
.btn {
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.2;
  white-space: nowrap;
  font-family: inherit;
}

.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(37,99,235,0.25); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 1px 2px rgba(22,163,74,0.25); }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 1px 2px rgba(220,38,38,0.25); }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #eef2f6; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ======================== TABLE ======================== */
.table-container {
  overflow: auto;
  /* ponytail: fixed viewport cap rather than measuring the header stack.
     If the toolbar above ever gets taller, raise the 240px. */
  max-height: calc(100vh - 240px);
}
/* headers ride along so you still know which column you are looking at */
.table-container thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
/* the scrollbars are the only cue the box scrolls - make them visible */
.table-container::-webkit-scrollbar { width: 12px; height: 12px; }
.table-container::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 6px; }
.table-container::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 6px; }
.table-container::-webkit-scrollbar-thumb:hover { background: #64748b; }
.table-container { scrollbar-width: thin; scrollbar-color: #94a3b8 #f1f5f9; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  background: #f8fafc;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: #f1f5f9; }
tbody tr:last-child td { border-bottom: none; }

/* ======================== BADGES ======================== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ======================== ALERTS ======================== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
  display: none;
  border: 1px solid transparent;
}

.alert-success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* ======================== FILTER BAR ======================== */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-bar input,
.filter-bar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
  font-family: inherit;
}

.filter-bar input:focus,
.filter-bar select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ======================== SUMMARY SECTION ======================== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.summary-item h4 {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
  letter-spacing: 0.4px;
}

.summary-item p {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary-item p.income { color: var(--success); }
.summary-item p.expense { color: var(--danger); }
.summary-item p.profit { color: var(--primary); }

/* ======================== TOGGLE BUTTONS (FY chips etc.) ======================== */
.btn-toggle { background: #eef2f6; color: var(--text); border: 1px solid var(--border); }
.btn-toggle:hover { background: #e2e8f0; }
.btn-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Shared across Billing, Purchase & Work Orders, Academia Customers, Settings, Courses */
.section-label { grid-column: 1/-1; text-transform: uppercase; font-size: 11px; font-weight: 700; letter-spacing: .04em; color: #6b7280; margin: 6px 0 0; }
.hint { color: #64748b; font-size: 0.85rem; }

/* ======================== RESPONSIVE ======================== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header h2, .sidebar-header p, .sidebar nav a span, .nav-section { display: none; }
  .sidebar nav a { justify-content: center; padding: 14px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header h1 { font-size: 1.3rem; }
}
