/* ==========================================================================
   EMIS Phase II - shared stylesheet
   Single source of truth for the UI. Previously every template carried its own
   ~250 line <style> block, so a change had to be made 24 times.
   ========================================================================== */

:root {
  /* UETCL brand */
  --emis-navy: #003366;
  --emis-navy-dark: #002244;
  --emis-navy-light: #004b94;
  --emis-gold: #ffcc00;
  --emis-gold-dark: #e6b800;

  /* Neutrals */
  --bg: #f1f4f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1c2430;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  /* Status */
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #0284c7;
  --info-bg: #e0f2fe;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 12px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);

  --sidebar-w: 248px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--emis-navy); text-decoration: none; }
a:hover { color: var(--emis-navy-light); text-decoration: underline; }

/* ==========================================================================
   App shell: fixed sidebar + topbar, scrolling content
   ========================================================================== */

.app { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--emis-navy);
  display: flex;
  flex-direction: column;
  z-index: 1030;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 18px;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .5px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  flex-shrink: 0;
}
.sidebar-brand:hover { color: #fff; text-decoration: none; }
.sidebar-brand i { color: var(--emis-gold); font-size: 20px; }

/* UETCL mark. The source logo is on a white background, so it sits on a white
   rounded tile rather than directly on the navy sidebar. */
.brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  background: #fff;
  border-radius: 7px;
  padding: 2px;
  flex-shrink: 0;
}
.sidebar-brand small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  opacity: .65;
  letter-spacing: .3px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
}

.nav-section {
  padding: 14px 10px 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: rgba(255, 255, 255, .42);
}

.nav-item-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, .82);
  font-weight: 500;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item-link:hover {
  background: rgba(255, 255, 255, .09);
  color: #fff;
  text-decoration: none;
}
.nav-item-link i { width: 17px; text-align: center; font-size: 14px; opacity: .9; }

.nav-item-link.active {
  background: var(--emis-gold);
  color: var(--emis-navy);
  font-weight: 600;
}
.nav-item-link.active i { opacity: 1; }

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, .1);
  font-size: 11px;
  color: rgba(255, 255, 255, .5);
  flex-shrink: 0;
}

/* Topbar */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
  z-index: 1020;
}

.topbar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.topbar-title small { display: block; font-size: 11.5px; font-weight: 400; color: var(--text-muted); }

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.avatar {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--emis-navy);
  color: var(--emis-gold);
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Content */
.content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 24px) 24px 32px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  padding: 6px;
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 1025;
}

/* ==========================================================================
   Page header
   ========================================================================== */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
}
.page-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card-emis {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-emis + .card-emis { margin-top: 18px; }

.card-emis-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-emis-head h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card-emis-head h2 i { color: var(--emis-navy); }
.card-emis-body { padding: 18px; }

/* ==========================================================================
   Stat tiles
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .15s, transform .15s;
}
a.stat:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  text-decoration: none;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 17px;
  flex-shrink: 0;
}
.stat-icon.navy { background: #e5edf7; color: var(--emis-navy); }
.stat-icon.gold { background: #fff7d6; color: #a67c00; }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.blue { background: var(--info-bg); color: var(--info); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }

.stat-value {
  font-size: 23px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
}
.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}

/* ==========================================================================
   Quick actions
   ========================================================================== */

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 550;
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.action:hover {
  border-color: var(--emis-navy);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  color: var(--emis-navy);
  text-decoration: none;
}
.action i {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: #e5edf7;
  color: var(--emis-navy);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex-shrink: 0;
}
.action span { display: block; }
.action small { display: block; font-weight: 400; font-size: 11.5px; color: var(--text-muted); }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}
.form-grid .full { grid-column: 1 / -1; }

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

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field label .req { color: var(--danger); }

.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=tel],
.field input[type=number],
.field input[type=date],
.field input[type=month],
.field input[type=datetime-local],
.field input[type=file],
.field select,
.field textarea,
.input-emis {
  width: 100%;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fbfcfe;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.input-emis:focus {
  outline: none;
  background: #fff;
  border-color: var(--emis-navy);
  box-shadow: 0 0 0 3px rgba(0, 51, 102, .1);
}
.field input:disabled,
.field select:disabled,
.field input[readonly] {
  background: #eef1f5;
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Highlight selects still on their placeholder value. */
.field select.untouched { color: var(--text-faint); border-color: #f0c36d; }

.field .hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.field .err { font-size: 11.5px; color: var(--danger); margin-top: 5px; }

fieldset.section {
  border: none;
  padding: 0;
  margin: 0 0 22px;
}
fieldset.section > legend {
  width: 100%;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--emis-navy);
  padding-bottom: 7px;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--border);
}

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

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn-emis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .15s, border-color .15s;
  white-space: nowrap;
}
.btn-emis:hover { transform: translateY(-1px); text-decoration: none; }
.btn-emis:active { transform: none; }
.btn-emis:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary-emis { background: var(--emis-navy); color: #fff; }
.btn-primary-emis:hover { background: var(--emis-navy-dark); color: #fff; box-shadow: var(--shadow); }

.btn-gold-emis { background: var(--emis-gold); color: var(--emis-navy); }
.btn-gold-emis:hover { background: var(--emis-gold-dark); color: var(--emis-navy); box-shadow: var(--shadow); }

.btn-ghost-emis { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost-emis:hover { background: var(--bg); border-color: var(--text-faint); color: var(--text); }

.btn-danger-emis { background: var(--danger); color: #fff; }
.btn-danger-emis:hover { background: #b91c1c; color: #fff; }

.btn-sm-emis { padding: 6px 12px; font-size: 12.5px; }
.btn-block-emis { width: 100%; }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap { overflow-x: auto; }

.table-emis {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table-emis th {
  text-align: left;
  padding: 10px 14px;
  background: #f7f9fc;
  border-bottom: 1.5px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  white-space: nowrap;
}
.table-emis td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table-emis tbody tr:hover { background: #f9fbfd; }
.table-emis tbody tr:last-child td { border-bottom: none; }
.table-emis .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-emis .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ==========================================================================
   Badges, alerts, empty state
   ========================================================================== */

.badge-emis {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .2px;
}
.badge-navy { background: #e5edf7; color: var(--emis-navy); }
.badge-green { background: var(--success-bg); color: #15803d; }
.badge-red { background: var(--danger-bg); color: #b91c1c; }
.badge-amber { background: var(--warning-bg); color: #b45309; }
.badge-blue { background: var(--info-bg); color: #0369a1; }
.badge-grey { background: #eef1f5; color: var(--text-muted); }

.alert-emis {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.alert-emis i { margin-top: 2px; flex-shrink: 0; }
.alert-success-emis { background: var(--success-bg); border-color: #a7f3c4; color: #14532d; }
.alert-danger-emis { background: var(--danger-bg); border-color: #fecaca; color: #7f1d1d; }
.alert-warning-emis { background: var(--warning-bg); border-color: #fde68a; color: #78350f; }
.alert-info-emis { background: var(--info-bg); border-color: #bae6fd; color: #0c4a6e; }

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-muted);
}
.empty i { font-size: 34px; color: var(--text-faint); margin-bottom: 12px; display: block; }
.empty h3 { font-size: 15px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.empty p { margin: 0 0 16px; font-size: 13px; }

/* ==========================================================================
   Auth pages (no sidebar)
   ========================================================================== */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -10%, var(--emis-navy-light) 0%, var(--emis-navy) 45%, transparent 100%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.auth-head {
  background: var(--emis-navy);
  color: #fff;
  padding: 26px 28px;
  text-align: center;
  border-bottom: 4px solid var(--emis-gold);
}
.auth-head .logo {
  width: 76px;
  height: 76px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .22);
  font-size: 30px;
  color: var(--emis-navy);
}
.auth-head .logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}
.auth-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: 1.5px; }
.auth-head p { margin: 4px 0 0; font-size: 12.5px; opacity: .82; }

.auth-body-inner { padding: 28px; }
.auth-body-inner h2 { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
.auth-body-inner .sub { margin: 0 0 22px; font-size: 13px; color: var(--text-muted); }

.auth-foot {
  padding: 16px 28px;
  background: #f7f9fc;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.divider-emis {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  font-size: 11.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.divider-emis::before,
.divider-emis::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* OTP entry */
.otp-input {
  width: 100%;
  text-align: center;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: 11px;
  padding: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 2px dashed var(--emis-gold);
  border-radius: var(--radius-sm);
  background: #fffdf2;
  color: var(--emis-navy);
}
.otp-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--emis-navy);
  background: #fff;
}

.hidden { display: none !important; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: none; }
  .topbar { left: 0; }
  .content { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .scrim.show { display: block; }
}

@media (max-width: 576px) {
  .content { padding: calc(var(--topbar-h) + 16px) 14px 24px; }
  .topbar { padding: 0 14px; }
  .user-chip span.uname { display: none; }
  .stat-grid, .action-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 18px; }
}

@media print {
  .sidebar, .topbar, .form-actions, .sidebar-toggle { display: none !important; }
  .content { margin: 0; padding: 0; }
  .card-emis { border: none; box-shadow: none; }
}

/* ==========================================================================
   Listing controls - filter bar, sortable headers, pagination
   ========================================================================== */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-item { position: relative; display: flex; align-items: center; }
.filter-item.grow { flex: 1 1 200px; min-width: 180px; }
.filter-item > i {
  position: absolute;
  left: 10px;
  font-size: 12px;
  color: var(--text-faint);
  pointer-events: none;
}
.filter-item > i + .input-emis { padding-left: 30px; }
.filter-bar .input-emis { height: 34px; font-size: 12.5px; }
.filter-item select.input-emis { min-width: 130px; }

/* Sortable column headers */
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.th-sort:hover { color: var(--emis-navy); text-decoration: none; }
.th-sort i { font-size: 10px; opacity: .35; }
.th-sort.active { color: var(--emis-navy); }
.th-sort.active i { opacity: 1; }
.table-emis th.num .th-sort { flex-direction: row-reverse; }

/* Pagination footer */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.pager-count { font-size: 12.5px; color: var(--text-muted); }
.pager-links { display: flex; align-items: center; gap: 4px; }
.pager-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.pager-btn:hover { background: var(--bg); color: var(--emis-navy); text-decoration: none; }
.pager-btn.current {
  background: var(--emis-navy);
  border-color: var(--emis-navy);
  color: #fff;
}
.pager-btn.disabled { opacity: .4; pointer-events: none; }
.pager-gap { padding: 0 4px; color: var(--text-faint); font-size: 12.5px; }

@media (max-width: 640px) {
  .pager { justify-content: center; }
  .filter-item.grow { flex-basis: 100%; }
}

/* ==========================================================================
   Analytics
   ========================================================================== */

.chart-box { position: relative; width: 100%; }
.chart-box canvas { max-width: 100%; }
.chart-sm { height: 240px; }
.chart-md { height: 300px; }
.chart-lg { height: 360px; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
}
.metric {
  background: var(--surface);
  padding: 14px 16px;
}
.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: 600;
}
.metric-value {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  margin-top: 3px;
  line-height: 1.2;
}
.metric-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.metric-delta { font-size: 11.5px; font-weight: 600; margin-top: 2px; }
.metric-delta.up { color: var(--success); }
.metric-delta.down { color: var(--danger); }
.metric-delta.flat { color: var(--text-muted); }

.bar-track {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.bar-fill { height: 100%; background: var(--emis-navy); border-radius: 3px; }
.bar-fill.gold { background: var(--emis-gold); }
.bar-fill.green { background: var(--success); }
.bar-fill.red { background: var(--danger); }
