/* ─── VARIABLES ──────────────────────────────────────────── */
:root {
  --primary:      #1e40af;
  --primary-h:    #1e3a8a;
  --primary-lt:   #dbeafe;
  --sidebar:      #0f172a;
  --sidebar-w:    240px;
  --success:      #16a34a;
  --success-lt:   #dcfce7;
  --danger:       #dc2626;
  --danger-lt:    #fee2e2;
  --warning:      #d97706;
  --warning-lt:   #fef3c7;
  --gray:         #6b7280;
  --border:       #e2e8f0;
  --bg:           #f1f5f9;
  --white:        #ffffff;
  --text:         #0f172a;
  --text-sm:      #475569;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.1),0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px rgba(0,0,0,.06);
  --available:    #22c55e;
  --available-lt: #f0fdf4;
  --booked:       #3b82f6;
  --booked-lt:    #eff6ff;
  --unavail:      #ef4444;
  --unavail-lt:   #fef2f2;
  --notset:       #e2e8f0;
  --notset-txt:   #94a3b8;
}

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ─── UTILITIES ──────────────────────────────────────────── */
.hidden   { display: none !important; }
.text-sm  { font-size: 12px; color: var(--text-sm); }
.flex     { display: flex; }
.items-center   { align-items: center; }
.justify-between{ justify-content: space-between; }

/* ─── BUTTONS ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: opacity .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover  { opacity: .85; }
.btn:active { opacity: .7; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-neutral { background: #f3f4f6; color: var(--text); }
.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ─── LOGIN ──────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 16px;
  background: linear-gradient(135deg, #0f172a 0%, #1e40af 100%);
}
.login-card {
  background: var(--white); border-radius: 12px;
  padding: 40px 36px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo {
  width: 52px; height: 52px; background: var(--primary);
  color: #fff; font-size: 18px; font-weight: 800;
  border-radius: 12px; display: flex; align-items: center;
  justify-content: center; margin-bottom: 20px;
}
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-card > p { color: var(--text-sm); margin-bottom: 24px; font-size: 13px; }
.login-hint {
  margin-top: 20px; padding: 10px 12px;
  background: var(--bg); border-radius: 6px;
  font-size: 12px; color: var(--text-sm); line-height: 1.9;
}
.login-hint strong { color: var(--text); }

/* ─── FORM ELEMENTS ──────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-sm); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; color: var(--text);
  background: var(--white); transition: border-color .15s; outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.error-msg {
  background: var(--danger-lt); color: var(--danger);
  border-radius: 6px; padding: 8px 12px; font-size: 12px; margin-bottom: 12px;
}

/* ─── APP SHELL ──────────────────────────────────────────── */
#app-shell { display: flex; min-height: 100vh; }

/* ─── MOBILE HEADER ──────────────────────────────────────── */
.mobile-header {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  height: 52px; background: var(--sidebar); color: #fff;
  align-items: center; justify-content: space-between;
  padding: 0 16px; z-index: 100;
}
.mobile-title { font-size: 15px; font-weight: 700; }
.icon-btn {
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer; padding: 4px 8px; line-height: 1;
}

/* ─── SIDEBAR ────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); background: var(--sidebar); color: #fff;
  display: flex; flex-direction: column; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-mark {
  width: 34px; height: 34px; background: var(--primary);
  border-radius: 8px; display: flex; align-items: center;
  justify-content: center; font-size: 13px; font-weight: 800; flex-shrink: 0;
}
.logo-text { font-size: 15px; font-weight: 700; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.user-avatar {
  width: 36px; height: 36px; background: var(--primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: #94a3b8; }
.nav-list  { list-style: none; padding: 12px 8px; flex: 1; }
.nav-list li a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 6px; color: #94a3b8; text-decoration: none;
  font-size: 13px; font-weight: 500; transition: background .15s, color .15s;
}
.nav-list li a:hover  { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-list li a.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.btn-logout {
  margin: 8px; padding: 9px 12px; background: transparent;
  border: 1px solid rgba(255,255,255,.12); border-radius: 6px;
  color: #94a3b8; font-size: 12px; cursor: pointer; text-align: left;
  transition: background .15s, color .15s; width: calc(100% - 16px);
}
.btn-logout:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
#sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 98;
}

/* ─── MAIN CONTENT ───────────────────────────────────────── */
#main { flex: 1; padding: 28px; overflow-x: hidden; min-width: 0; }

/* ─── PAGE HEADER ────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header p  { font-size: 13px; color: var(--text-sm); margin-top: 2px; }

/* ─── STATS GRID ─────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; font-weight: 600; color: var(--text-sm); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 30px; font-weight: 700; margin: 6px 0 2px; color: var(--text); }
.stat-sub   { font-size: 12px; color: var(--text-sm); }
.stat-card.blue  .stat-value { color: var(--primary); }
.stat-card.green .stat-value { color: var(--success); }
.stat-card.red   .stat-value { color: var(--danger); }

/* ─── CARD ───────────────────────────────────────────────── */
.card {
  background: var(--white); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-title {
  font-size: 14px; font-weight: 700; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ─── DATA TABLE ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  background: var(--bg); padding: 9px 12px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-sm); border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody td { padding: 10px 12px; vertical-align: middle; }
.table-actions { display: flex; gap: 6px; align-items: center; }

/* ─── BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-scheduled  { background: var(--primary-lt); color: var(--primary); }
.badge-completed  { background: var(--success-lt); color: var(--success); }
.badge-cancelled  { background: #f3f4f6;           color: var(--gray); }
.badge-billed     { background: var(--warning-lt); color: var(--warning); }
.badge-paid       { background: var(--success-lt); color: var(--success); }
.badge-active     { background: var(--success-lt); color: var(--success); }
.badge-inactive   { background: #f3f4f6;           color: var(--gray); }

/* ─── CALENDAR ───────────────────────────────────────────── */
.cal-toolbar {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.cal-week-nav { display: flex; align-items: center; gap: 8px; }
.cal-week-label { font-size: 14px; font-weight: 600; min-width: 175px; text-align: center; }
.cal-wrap { overflow-x: auto; }
table.cal-table {
  width: 100%; border-collapse: collapse; font-size: 12px; min-width: 560px;
}
.cal-table th {
  background: var(--bg); padding: 8px 6px; text-align: center;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); white-space: nowrap;
}
.cal-day-num { display: block; font-size: 11px; font-weight: 400; color: var(--text-sm); margin-top: 2px; }
.cal-table td { border: 1px solid var(--border); padding: 3px; vertical-align: top; }
.cal-slot-label {
  text-align: center; white-space: nowrap; font-size: 11px;
  color: var(--text-sm); font-weight: 600; padding: 6px 8px !important;
  background: var(--bg); min-width: 68px;
}
.cal-cell { min-width: 88px; min-height: 42px; padding: 3px !important; }

/* Dot mode (all kines) */
.kine-dot {
  display: inline-flex; width: 30px; height: 30px; border-radius: 50%;
  align-items: center; justify-content: center; font-size: 11px;
  font-weight: 700; color: #fff; cursor: pointer; margin: 2px;
  transition: transform .1s;
}
.kine-dot:hover { transform: scale(1.15); }
.kine-dot.available   { background: var(--available); }
.kine-dot.booked      { background: var(--booked); }
.kine-dot.unavailable { background: var(--unavail); }
.kine-dot.notset      { background: var(--notset); color: var(--notset-txt); }

/* Block mode (single kine) */
.cal-block {
  display: block; min-height: 42px; border-radius: 4px;
  padding: 5px 7px; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.cal-block:hover { opacity: .82; }
.cal-block.available   { background: var(--available-lt); color: #15803d; border: 1px solid #86efac; }
.cal-block.booked      { background: var(--booked-lt);    color: #1d4ed8; border: 1px solid #93c5fd; }
.cal-block.unavailable { background: var(--unavail-lt);   color: #b91c1c; border: 1px solid #fca5a5; }
.cal-block.notset      { background: var(--bg); color: var(--notset-txt); border: 1px dashed var(--border); }

.cal-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-sm); }
.legend-dot  { width: 12px; height: 12px; border-radius: 50%; }
.legend-dot.available   { background: var(--available); }
.legend-dot.booked      { background: var(--booked); }
.legend-dot.unavailable { background: var(--unavail); }
.legend-dot.notset      { background: var(--notset); border: 1px solid var(--border); }

/* ─── AVAILABILITY GRID ──────────────────────────────────── */
.avail-wrap { overflow-x: auto; }
table.avail-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 480px; }
.avail-table th {
  background: var(--bg); padding: 8px 6px; text-align: center;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border);
}
.avail-table td { border: 1px solid var(--border); padding: 3px; text-align: center; }
.avail-btn {
  width: 100%; min-height: 38px; border: none; border-radius: 4px;
  font-size: 11px; font-weight: 600; cursor: pointer; transition: opacity .15s;
}
.avail-btn:hover    { opacity: .8; }
.avail-btn.available   { background: var(--available-lt); color: #15803d; }
.avail-btn.unavailable { background: var(--unavail-lt);   color: #b91c1c; }
.avail-btn.booked      { background: var(--booked-lt);    color: #1d4ed8; cursor: default; }
.avail-btn.notset      { background: var(--bg); color: var(--notset-txt); }

/* ─── MODAL ──────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 200; display: flex; align-items: center;
  justify-content: center; padding: 16px;
}
#modal-box {
  background: var(--white); border-radius: 12px; padding: 24px;
  width: 100%; max-width: 520px; max-height: 92vh;
  overflow-y: auto; position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 16px; background: none;
  border: none; font-size: 18px; cursor: pointer; color: var(--gray); line-height: 1;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 18px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ─── TOAST ──────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 16px; border-radius: 8px; font-size: 13px;
  font-weight: 500; color: #fff; box-shadow: var(--shadow-md);
  animation: slideIn .2s ease; max-width: 320px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ─── SESSION CARDS (kine) ───────────────────────────────── */
.session-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  transition: box-shadow .15s;
}
.session-card:hover { box-shadow: var(--shadow); }
.session-card-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px;
}
.session-patient { font-size: 14px; font-weight: 700; }
.session-meta    { font-size: 12px; color: var(--text-sm); margin-top: 3px; }
.session-note {
  margin-top: 10px; padding: 8px 10px; background: var(--bg);
  border-radius: 5px; font-size: 12px; color: var(--text-sm); font-style: italic;
}
.session-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── FINANCIALS ─────────────────────────────────────────── */
.fin-toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.fin-total   { font-size: 22px; font-weight: 700; color: var(--primary); margin: 4px 0; }
.fin-patient-block { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }

/* ─── TABS ───────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 9px 20px; border: none; background: none; font-size: 13px;
  font-weight: 600; color: var(--text-sm); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── EMPTY STATE ────────────────────────────────────────── */
.empty-state { text-align: center; padding: 44px 24px; color: var(--text-sm); }
.empty-icon  { font-size: 38px; margin-bottom: 12px; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; }

/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  #app-shell { padding-top: 52px; }
  #sidebar {
    position: fixed; top: 52px; left: 0; bottom: 0; z-index: 99;
    transform: translateX(-100%); transition: transform .25s ease;
    width: 260px; height: calc(100vh - 52px); min-height: unset;
  }
  #sidebar.open { transform: translateX(0); }
  #main { padding: 14px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header h1 { font-size: 17px; }
}
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  #modal-box  { padding: 16px; }
  .cal-week-label { min-width: 120px; font-size: 12px; }
}
