@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
  --blue: #1e88e5;
  --blue-dark: #1565c0;
  --blue-light: #e3f2fd;
  --blue-border: #bbdefb;
  --green: #43a047;
  --green-light: #e8f5e9;
  --green-dark: #2e7d32;
  --red: #e53935;
  --red-light: #ffebee;
  --red-dark: #c62828;
  --orange: #ff9800;
  --orange-light: #fff3e0;
  --orange-dark: #e65100;
  --purple: #8e24aa;
  --purple-light: #f3e5f5;
  --purple-dark: #6a1b9a;
  --gray-50: #f8f9fa;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #1a1a2e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── FLASH MESSAGES ─────────────────────────────────────────────────── */
.flash-container { padding: 0 20px; margin-top: 8px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.flash.success { background: var(--green-light); color: var(--green-dark); border: 1px solid #c8e6c9; }
.flash.danger  { background: var(--red-light);   color: var(--red-dark);   border: 1px solid #ffcdd2; }
.flash.info    { background: var(--blue-light);  color: var(--blue-dark);  border: 1px solid var(--blue-border); }
.flash.warning { background: var(--orange-light);color: var(--orange-dark);border: 1px solid #ffe0b2; }

/* ─── LOGIN PAGE ─────────────────────────────────────────────────────── */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #1565c0 0%, #1e88e5 50%, #42a5f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .icon {
  width: 56px;
  height: 56px;
  background: var(--blue-light);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 12px;
}
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--gray-900); }
.login-logo p  { font-size: 13px; color: var(--gray-500); margin-top: 3px; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
.form-control:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30,136,229,.15);
}
.form-control.is-invalid { border-color: var(--red); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); text-decoration: none; color: #fff; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: var(--green-dark); text-decoration: none; color: #fff; }
.btn-danger  { background: var(--red);  color: #fff; border-color: var(--red); }
.btn-danger:hover  { background: var(--red-dark); text-decoration: none; color: #fff; }
.btn-outline {
  background: #fff;
  color: var(--gray-700);
  border-color: var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-block { width: 100%; }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ─── APP LAYOUT ─────────────────────────────────────────────────────── */
.app-layout { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 20px;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  z-index: 50;
  position: sticky;
  top: 0;
}
.topbar-brand { font-size: 16px; font-weight: 700; color: var(--gray-900); display: flex; align-items: center; gap: 8px; }
.topbar-brand span { font-size: 20px; }
.topbar-nav { display: flex; gap: 2px; flex: 1; }
.topbar-nav a {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  transition: background .15s;
}
.topbar-nav a:hover { background: var(--gray-100); text-decoration: none; }
.topbar-nav a.active { background: var(--blue-light); color: var(--blue-dark); }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.role-badge.admin  { background: var(--purple-light); color: var(--purple-dark); }
.role-badge.doctor { background: var(--blue-light);   color: var(--blue-dark); }
.user-name { font-size: 13px; font-weight: 500; color: var(--gray-700); }

.content-wrapper { flex: 1; padding: 20px; }

/* ─── CARDS ──────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-header h2 { font-size: 15px; font-weight: 700; }
.card-body { padding: 18px; }

/* ─── STAT CARDS ─────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; color: var(--gray-900); }
.stat-card .sub   { font-size: 11px; color: var(--gray-500); margin-top: 2px; }
.stat-card.blue   { border-left: 3px solid var(--blue); }
.stat-card.green  { border-left: 3px solid var(--green); }
.stat-card.orange { border-left: 3px solid var(--orange); }
.stat-card.red    { border-left: 3px solid var(--red); }

/* ─── TABLE ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-500); padding: 8px 12px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); text-align: left; }
td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--gray-100); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* ─── BADGES ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}
.badge-blue   { background: var(--blue-light);   color: var(--blue-dark); }
.badge-green  { background: var(--green-light);  color: var(--green-dark); }
.badge-red    { background: var(--red-light);    color: var(--red-dark); }
.badge-orange { background: var(--orange-light); color: var(--orange-dark); }
.badge-purple { background: var(--purple-light); color: var(--purple-dark); }
.badge-gray   { background: var(--gray-100);     color: var(--gray-500); }

/* ─── PATIENT TYPE DOTS ──────────────────────────────────────────────── */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.psych  { background: var(--green); }
.dot.online { background: var(--blue); }
.dot.pary   { background: var(--red); }

/* ─── CALENDAR LAYOUT ────────────────────────────────────────────────── */
.cal-layout {
  display: flex;
  height: calc(100vh - 54px);
  overflow: hidden;
}

.cal-sidebar {
  width: 300px;
  background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.cal-sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-200);
}
.cal-sidebar-head h2 { font-size: 13px; font-weight: 700; }
.cal-search {
  width: 100%;
  padding: 6px 9px;
  border-radius: 6px;
  border: 1px solid var(--gray-300);
  font-size: 12px;
  outline: none;
  margin-top: 7px;
  font-family: inherit;
}
.cal-search:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(30,136,229,.12); }
.filter-row { display: flex; gap: 3px; margin-top: 6px; flex-wrap: wrap; }
.fbtn {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--gray-300);
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.fbtn.on { background: var(--blue); color: #fff; border-color: var(--blue); }

.plist { flex: 1; overflow-y: auto; padding: 6px 8px; }
.pcard {
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--gray-200);
  margin-bottom: 4px;
  cursor: pointer;
  transition: all .15s;
  font-size: 11px;
}
.pcard:hover { border-color: #90caf9; background: #f8fbff; }
.pcard.active { border-color: var(--blue); background: var(--blue-light); box-shadow: 0 0 0 2px rgba(30,136,229,.2); }
@keyframes flash { 0%{box-shadow:0 0 0 5px rgba(30,136,229,.4)} 100%{box-shadow:0 0 0 2px rgba(30,136,229,.2)} }
.pcard.flash { animation: flash .5s ease-out; }
.pcard.ending { border-left: 3px solid var(--orange); }
.pcard.ended  { border-left: 3px solid var(--red); opacity: .65; }
.pcard.conflict-card { border-left: 3px solid var(--red-dark); background: #fff8f8; }
.pcard.therapy-ended { border-left: 3px solid #9e9e9e; opacity: .55; background: #fafafa; }
.pcard .pname { font-weight: 600; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.pcard .pmeta { color: var(--gray-500); margin-top: 2px; font-size: 10px; }
.pcard .controls { margin-top: 6px; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pcard select, .pcard input[type=number] {
  font-size: 10px; padding: 2px 4px; border-radius: 4px;
  border: 1px solid var(--gray-300); font-family: inherit; outline: none;
}
.pcard select:focus, .pcard input[type=number]:focus { border-color: var(--blue); }
.sessions-input { width: 42px !important; text-align: center; }
.btn-sm-card {
  font-size: 9px; padding: 2px 7px; border-radius: 4px;
  border: 1px solid var(--blue); background: var(--blue-light);
  color: var(--blue-dark); cursor: pointer; font-weight: 600;
  font-family: inherit; white-space: nowrap;
}
.btn-sm-card.danger { border-color: var(--red); background: var(--red-light); color: var(--red-dark); }
.sess-badge {
  font-size: 9px; padding: 1px 5px; border-radius: 10px; font-weight: 600;
}
.sess-badge.ok  { background: var(--green-light); color: var(--green-dark); }
.sess-badge.low { background: var(--orange-light); color: var(--orange-dark); }
.sess-badge.out { background: var(--red-light); color: var(--red-dark); }

/* ─── CALENDAR MAIN ──────────────────────────────────────────────────── */
.cal-main { flex: 1; overflow: auto; padding: 14px; }

.cal-nav {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.cal-nav button {
  padding: 5px 12px; border-radius: 6px; border: 1px solid var(--gray-300);
  background: #fff; cursor: pointer; font-weight: 600; font-size: 12px;
  font-family: inherit; transition: background .15s;
}
.cal-nav button:hover { background: var(--gray-100); }
.cal-nav .label { font-size: 16px; font-weight: 700; min-width: 160px; text-align: center; }
.view-toggle { display: flex; border: 1px solid var(--gray-300); border-radius: 6px; overflow: hidden; }
.view-toggle button {
  padding: 5px 13px; border: none; background: #fff;
  cursor: pointer; font-size: 12px; font-weight: 600; font-family: inherit;
}
.view-toggle button.on { background: var(--blue); color: #fff; }

.day-bar {
  display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; align-items: center;
}
.day-bar-label { font-size: 11px; color: var(--gray-500); font-weight: 600; }
.day-chip {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--gray-300); border-radius: 6px;
  padding: 3px 8px; font-size: 11px; cursor: pointer;
  background: var(--gray-100); transition: all .15s;
}
.day-chip.on { background: var(--blue-light); border-color: var(--blue); }
.day-chip select {
  font-size: 10px; border: 1px solid #bbb; border-radius: 3px;
  padding: 1px 2px; width: 50px; font-family: inherit;
}

/* Month Grid */
.cal-grid { display: grid; gap: 5px; }
.cal-header { font-size: 11px; font-weight: 700; color: var(--gray-500); text-align: center; padding: 4px 0; }
.cal-day {
  background: #fff; border-radius: 8px; border: 1px solid var(--gray-200);
  min-height: 80px; padding: 5px; transition: border-color .15s;
}
.cal-day.today { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(30,136,229,.12); }
.cal-day.outside { opacity: .25; }
.cal-day.non-work { background: var(--gray-50); border-style: dashed; }
.cal-day .day-num {
  font-size: 10px; font-weight: 700; color: var(--gray-500);
  margin-bottom: 3px; display: flex; justify-content: space-between; align-items: center;
}
.cal-day .day-hr { font-size: 8px; color: #bbb; }
.cal-day .day-sum { font-size: 8px; color: var(--gray-500); text-align: right; margin-top: 2px; }

/* Week Grid */
.week-grid {
  display: grid; gap: 0; border: 1px solid var(--gray-200);
  border-radius: 10px; overflow: hidden; background: #fff;
}
.week-time {
  font-size: 10px; color: var(--gray-500); font-weight: 600;
  padding: 4px 6px; border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: flex-start; justify-content: flex-end;
  min-height: 36px; background: var(--gray-50);
}
.week-col-head {
  font-size: 12px; font-weight: 700; padding: 8px;
  text-align: center; border-bottom: 1px solid var(--gray-200); background: var(--gray-50);
}
.week-cell {
  border-bottom: 1px solid var(--gray-100); border-left: 1px solid var(--gray-100);
  padding: 2px 3px; min-height: 36px; position: relative;
}
.week-cell.non-work { background: var(--gray-50); }
.week-corner { background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }

/* Slots */
.slot {
  font-size: 9px; padding: 2px 4px; border-radius: 3px;
  margin-bottom: 1px; display: flex; align-items: center; gap: 3px;
  cursor: default; line-height: 1.2; transition: all .15s;
}
.slot .slot-time { font-weight: 600; color: var(--gray-500); width: 26px; flex-shrink: 0; font-size: 8px; }
.slot .slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.slot .slot-dur  { font-size: 7px; color: var(--gray-500); flex-shrink: 0; }
.slot.empty  { color: var(--gray-300); }
.slot.filled { border: 1px solid; cursor: pointer; }
.slot.filled.psych  { background: var(--green-light);  border-color: #c8e6c9; color: var(--green-dark); }
.slot.filled.online { background: var(--blue-light);   border-color: var(--blue-border); color: var(--blue-dark); }
.slot.filled.pary   { background: #fce4ec; border-color: #f8bbd0; color: var(--red-dark); }
.slot.filled.highlight { box-shadow: 0 0 0 2px var(--orange); border-color: var(--orange); z-index: 1; position: relative; font-weight: 700; }
.slot.target { background: #fff8e1; border: 1px dashed var(--orange); cursor: cell; color: #f57c00; }
.slot .remove-x { display: none; cursor: pointer; color: var(--red-dark); font-weight: 700; margin-left: auto; flex-shrink: 0; font-size: 11px; }
.slot.filled:hover .remove-x { display: inline; }
.slot.filled.completed { opacity: .55; }
.slot.filled.cancelled { opacity: .35; text-decoration: line-through; }

.week-grid .slot { font-size: 10px; padding: 3px 5px; border-radius: 4px; }
.week-grid .slot .slot-time { display: none; }
.week-grid .slot .slot-name { font-size: 11px; }

.legend {
  display: flex; gap: 12px; justify-content: center;
  margin-top: 12px; font-size: 10px; color: var(--gray-500); flex-wrap: wrap;
}
.legend span { display: flex; align-items: center; gap: 3px; }

/* ─── FORM STYLES ────────────────────────────────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 600px) { .form-row, .form-row.cols-3 { grid-template-columns: 1fr; } }

select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ─── MISC ───────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header .sub { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); }
.empty-state .icon { font-size: 36px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

.chip {
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: var(--gray-100); font-weight: 500; display: inline-block;
}

.divider { height: 1px; background: var(--gray-200); margin: 16px 0; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.status-dot.scheduled { background: var(--blue); }
.status-dot.completed { background: var(--green); }
.status-dot.cancelled { background: var(--gray-300); }

/* ─── APPOINTMENT MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: #fff; border-radius: 12px; padding: 22px;
  width: 90%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.modal-box h3 { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.modal-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }
