/* ────────────────────────────────────────────────────────────────────────────
   Chemo Agenda – Design System
   ──────────────────────────────────────────────────────────────────────────── */

/* ── CSS Variables ── */
:root {
  --primary:       #1a5276;
  --primary-mid:   #2e86c1;
  --primary-light: #d6eaf8;
  --primary-xlt:   #eaf4fb;
  --chemo-bg:      #fef9e7;
  --chemo-border:  #f39c12;
  --chemo-text:    #7d6608;
  --success:       #27ae60;
  --danger:        #e74c3c;
  --warning:       #f39c12;
  --info:          #2980b9;
  --muted:         #7f8c8d;
  --text:          #2c3e50;
  --text-light:    #5d6d7e;
  --bg:            #f0f4f8;
  --card:          #ffffff;
  --border:        #d5dde6;
  --sidebar-w:     240px;
  --topbar-h:      60px;
  --radius:        8px;
  --shadow:        0 2px 8px rgba(0,0,0,.10);
  --shadow-lg:     0 8px 24px rgba(0,0,0,.15);
  --transition:    .18s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
ul, ol { list-style: none; }

/* ── Layout ── */
#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform var(--transition), width var(--transition);
  z-index: 200;
}
#sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); position: fixed; height: 100vh; }

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.sb-icon  { font-size: 24px; }
.sb-title { font-size: 17px; font-weight: 700; letter-spacing: .3px; }

.sb-nav   { flex: 1; padding: 12px 0; }
.sb-footer{ padding: 12px 0; border-top: 1px solid rgba(255,255,255,.15); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,.82);
  font-size: 14px;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,.18);
  color: #fff;
  border-left-color: #fff;
  font-weight: 600;
}

/* ── Main wrapper ── */
#main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ── */
#topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  z-index: 100;
  flex-shrink: 0;
}
#menu-btn {
  font-size: 20px;
  color: var(--text-light);
  padding: 4px 6px;
  border-radius: 4px;
  transition: background var(--transition);
}
#menu-btn:hover { background: var(--bg); }
#page-title { font-size: 17px; font-weight: 700; color: var(--primary); flex: 1; }
#topbar-right { display: flex; align-items: center; gap: 12px; }
.today-lbl { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ── Main content ── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Loading overlay ── */
#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary-mid);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ── Stat cards row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}
.stat-card .stat-val { font-size: 32px; font-weight: 800; color: var(--primary); }
.stat-card .stat-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-card.accent .stat-val  { color: var(--chemo-border); }
.stat-card.success .stat-val { color: var(--success); }
.stat-card.info .stat-val    { color: var(--info); }

/* ── Filter bar ── */
.filter-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.filter-group input,
.filter-group select {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  min-width: 130px;
  transition: border-color var(--transition);
}
.filter-group input:focus,
.filter-group select:focus { outline: none; border-color: var(--primary-mid); background: #fff; }
.filter-actions { display: flex; gap: 8px; align-items: flex-end; }

/* ── Table ── */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.table-hd-title { font-weight: 700; font-size: 14px; color: var(--primary); }
.table-count { font-size: 12px; color: var(--muted); margin-left: 8px; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--primary-xlt);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 2px solid var(--primary-light);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--primary-xlt); }
tbody tr.chemo-row { background: var(--chemo-bg); }
tbody tr.chemo-row:hover { background: #fef3cc; }
td {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}
.td-actions { display: flex; gap: 6px; align-items: center; }
.no-data { padding: 40px; text-align: center; color: var(--muted); font-size: 15px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--primary-mid); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover  { filter: brightness(1.1); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline   { background: transparent; color: var(--primary-mid); border: 1px solid var(--primary-mid); }
.btn-outline:hover { background: var(--primary-light); }
.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 5px 8px; }
.btn-ghost { color: var(--muted); padding: 4px 8px; }
.btn-ghost:hover { color: var(--primary-mid); background: var(--primary-xlt); }
.btn-edit   { color: var(--primary-mid); }
.btn-edit:hover  { background: var(--primary-light); color: var(--primary); }
.btn-del    { color: var(--danger); }
.btn-del:hover   { background: #fdecea; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #fff3cd; color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-teal   { background: #d1fae5; color: #065f46; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 18px;
}
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-light); }
.form-group input,
.form-group select,
.form-group textarea {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary-mid); box-shadow: 0 0 0 2px rgba(46,134,193,.15); }
.form-group textarea { resize: vertical; min-height: 70px; }
.form-section { margin-bottom: 20px; }
.form-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--primary); margin-bottom: 12px;
  padding-bottom: 6px; border-bottom: 2px solid var(--primary-light);
}
.form-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Chemo section (conditional) ── */
.chemo-section {
  background: var(--chemo-bg);
  border: 1px solid var(--chemo-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.chemo-section .form-section-title { color: var(--chemo-text); }

/* ── Medications section in agenda form ── */
.med-assign-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.med-assign-hd {
  background: var(--primary-xlt);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.med-assign-hd span { font-weight: 700; font-size: 12px; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; }
.med-list { padding: 8px 0; min-height: 40px; }
.med-row {
  display: grid;
  grid-template-columns: 26px 1fr auto auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.med-row:last-child { border-bottom: none; }
.med-row:hover { background: var(--primary-xlt); }
.med-row .med-num { color: var(--muted); font-weight: 700; }
.med-row .med-name { font-weight: 600; color: var(--text); }
.med-row .med-dose { color: var(--text-light); }
.med-row .med-route { }
.med-row .med-status { }
.med-empty { padding: 16px 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* Inline add-med form */
.add-med-form {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}
.add-med-form .form-grid { gap: 8px; }

/* ── Modal ── */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 25, 47, .55);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  z-index: 1000;
  overflow-y: auto;
}
.backdrop.hidden { display: none; }

.modal-box {
  background: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  overflow: hidden;
  animation: modalIn .18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-16px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  background: var(--primary-xlt);
}
.modal-hd h2 { font-size: 16px; font-weight: 700; color: var(--primary); }
.modal-close {
  font-size: 16px; width: 28px; height: 28px;
  border-radius: 50%; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { overflow-y: auto; padding: 22px; flex: 1; }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  background: var(--bg);
}
.modal-foot.hidden { display: none; }

/* ── Detail view (read-only in modal) ── */
.detail-section { margin-bottom: 20px; }
.detail-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--primary);
  margin-bottom: 10px; padding-bottom: 5px;
  border-bottom: 2px solid var(--primary-light);
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px 18px;
}
.detail-field { display: flex; flex-direction: column; gap: 2px; }
.detail-field .lbl { font-size: 11px; color: var(--muted); }
.detail-field .val { font-size: 13px; color: var(--text); font-weight: 500; }
.detail-field .val.big { font-size: 15px; font-weight: 700; color: var(--primary); }

/* Medication detail table */
.med-detail-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.med-detail-table th { background: var(--primary-xlt); color: var(--primary); padding: 7px 10px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.med-detail-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.med-detail-table tr:last-child td { border-bottom: none; }
.med-detail-table tr:hover td { background: var(--primary-xlt); }

/* ── Confirm dialog ── */
.confirm-box {
  background: var(--card);
  border-radius: 10px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease;
}
.confirm-icon { font-size: 40px; margin-bottom: 12px; }
.confirm-box p { font-size: 15px; color: var(--text); margin-bottom: 22px; line-height: 1.5; }
.confirm-btns { display: flex; gap: 10px; justify-content: center; }

/* ── Toasts ── */
#toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 7px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease;
  min-width: 240px;
  max-width: 380px;
  border-left: 4px solid var(--primary-mid);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ── Utilities ── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.gap-8    { gap: 8px; }
.gap-12   { gap: 12px; }
.ml-auto  { margin-left: auto; }
.mt-12    { margin-top: 12px; }
.mt-16    { margin-top: 16px; }
.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.text-small  { font-size: 12px; }
.text-bold   { font-weight: 700; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.check-green { color: var(--success); font-weight: 700; }
.cross-red   { color: var(--danger); }

/* ── Page header row ── */
.page-hd {
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.page-hd h2 { font-size: 18px; font-weight: 800; color: var(--primary); }

/* ── Inline status select ── */
.status-select {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #app-shell { height: 100dvh; overflow: visible; }
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100dvh;
    width: 82vw;
    max-width: 320px;
    min-width: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 16px rgba(0,0,0,.2);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.collapsed { transform: translateX(-100%); }
  #main-wrapper { margin-left: 0 !important; width: 100%; min-width: 0; }
  #content {
    padding: 16px;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open::after {
    content: '';
    position: fixed;
    top: var(--topbar-h);
    left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.45);
    z-index: 150;
    pointer-events: auto;
  }
  .form-grid.cols-2,
  .form-grid.cols-3 { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-group input,
  .filter-group select { min-width: 100%; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  #topbar { padding: 0 14px; }
  table { font-size: 13px; }
  .table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap table { min-width: 640px; }
}

/* ── Login Screen ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a4a8a 0%, #2563eb 60%, #3b82f6 100%);
  padding: 24px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 48px 40px 36px;
  width: 100%;
  max-width: 420px;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.login-title { font-size: 26px; font-weight: 900; color: var(--primary); margin: 0; }
.login-sub { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.login-form .form-group { margin-bottom: 16px; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--text); display: block; margin-bottom: 6px; }
.login-form input {
  width: 100%; padding: 10px 14px; font-size: 14px;
  border: 1.5px solid var(--border); border-radius: 8px; outline: none;
  transition: border-color .2s;
}
.login-form input:focus { border-color: var(--primary); }
.btn-full { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }
.login-msg { font-size: 13px; min-height: 20px; margin-bottom: 8px; border-radius: 6px; padding: 0; }
.login-msg.error { color: #dc2626; background: #fef2f2; padding: 8px 12px; }
.login-msg.success { color: #16a34a; background: #f0fdf4; padding: 8px 12px; }
.login-footer { text-align: center; font-size: 11px; color: var(--muted); margin: 20px 0 0; }

/* ── Sidebar user info + logout ── */
.sb-user-info {
  font-size: 12px; font-weight: 700; color: var(--primary-light);
  padding: 8px 20px 4px; letter-spacing: .02em;
}
.btn-logout {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; font-size: 13px; font-weight: 600;
  color: #dc2626; background: none; border: none; cursor: pointer;
  width: 100%; text-align: left; text-decoration: none;
  transition: background .15s;
}
.btn-logout:hover { background: #fef2f2; border-radius: 6px; }

/* ── Hidden utility ── */
.hidden { display: none !important; }

/* ── Language selector (topbar) ── */
.lang-selector {
  background: #fff;
  border: 1px solid var(--border, #d6d9dd);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary, #1a5276);
  cursor: pointer;
  margin-right: 8px;
}
.lang-selector:focus { outline: 2px solid var(--primary-mid, #2e86c1); outline-offset: 1px; }
