@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface2: #eef0f2;
  --border: #d0d5db;
  --border-strong: #b0b8c1;
  --text: #1c2330;
  --text-muted: #5a6574;
  --text-light: #8a95a3;
  --primary: #1a56a0;
  --primary-hover: #144388;
  --primary-light: #e8f0fb;
  --danger: #c0392b;
  --danger-hover: #a93226;
  --danger-light: #fdf0ee;
  --success: #1e7e34;
  --success-light: #eaf6ec;
  --warning: #b45309;
  --warning-light: #fef3e2;
  --info: #0d6eaa;
  --info-light: #e7f3fb;
  --sidebar-w: 240px;
  --header-h: 58px;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 4px rgba(0,0,0,.10);
  --shadow-md: 0 3px 10px rgba(0,0,0,.12);
  --transition: 0.15s ease;
  --bg-off: #f9fafb;
}

[data-theme="dark"] {
  --bg: #12161e;
  --surface: #1c2130;
  --surface2: #242a3a;
  --border: #2e3650;
  --border-strong: #3d4a62;
  --text: #dde3ec;
  --text-muted: #8b97aa;
  --text-light: #6a7690;
  --primary: #4e8fd4;
  --primary-hover: #3d7ac2;
  --primary-light: #1a2a45;
  --danger: #e05a4a;
  --danger-hover: #c9463a;
  --danger-light: #2a1a18;
  --success: #3da85a;
  --success-light: #0f2018;
  --warning: #e09030;
  --warning-light: #261900;
  --info: #3a9dd8;
  --info-light: #0d2035;
  --shadow: 0 1px 4px rgba(0,0,0,.35);
  --shadow-md: 0 3px 10px rgba(0,0,0,.45);
  --bg-off: #161b27;
}

html { height: 100%; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); text-decoration: underline; }
img { max-width: 100%; display: block; }
h1,h2,h3,h4,h5 { color: var(--text); font-weight: 600; line-height: 1.35; }

input, select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  box-sizing: border-box;
}
input[type="date"] {
  padding: 0 10px;
}
textarea {
  width: 100%;
  min-height: 72px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  box-sizing: border-box;
  resize: vertical;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 160, .14);
}
input:read-only { background: var(--surface2); color: var(--text-muted); cursor: not-allowed; }
label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 5px;
}
select option { background: var(--surface); color: var(--text); }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
legend { font-weight: 600; font-size: 14px; padding: 0 6px; color: var(--text); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 9px 13px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
table td {
  padding: 10px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table tr:last-child td { border-bottom: none; }
table tbody tr:hover td { background: var(--surface2); }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.data-table th { background: var(--surface2); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  text-decoration: none;
  white-space: nowrap;
  box-sizing: border-box;
  vertical-align: middle;
  line-height: normal;
}
button:active, .btn:active { opacity: .88; }

.btn-primary, button[type="submit"] {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover, button[type="submit"]:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #fff;
  text-decoration: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--surface2);
  text-decoration: none;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover { opacity: .88; color: #fff; text-decoration: none; }

.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: var(--surface2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body,
.card > form,
.card-filter,
.filter-card {
  padding: 16px 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--text); }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }

.search-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.search-field {
  flex: 1;
  max-width: 520px;
  min-width: 240px;
}
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.search-input-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}
.search-input-wrap input {
  padding-left: 36px;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-neutral { background: var(--surface2); color: var(--text-muted); }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
  border-left: 4px solid;
}
.alert-error { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--success-light); color: var(--success); border-color: var(--success); }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: #0b111e;
  border-right: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  min-height: var(--header-h);
}
.sidebar-brand img { width: 32px; height: 32px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }
.sidebar-brand-icon {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.2);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand-icon svg { color: #fff; }
.sidebar-brand-text { flex: 1; min-width: 0; }
.sidebar-clinic-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-sub { font-size: 11px; color: rgba(255,255,255,.65); }

.sidebar-close {
  display: none;
  background: rgba(255,255,255,.1);
  border: none;
  cursor: pointer;
  padding: 5px;
  color: #fff;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}
.sidebar-close:hover { background: rgba(255,255,255,.22); }

.sidebar-nav { flex: 1; padding: 10px 8px; }
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: rgba(255,255,255,.5);
  padding: 10px 10px 4px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.82);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  margin-bottom: 2px;
}
.sidebar-link svg { flex-shrink: 0; }
.sidebar-link:hover { background: rgba(255,255,255,.13); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255,255,255,.22); color: #fff; font-weight: 700; }
.sidebar-link.logout-link { color: rgba(255,200,200,.85); }
.sidebar-link.logout-link:hover { background: rgba(255,100,100,.2); color: #fff; }
.sidebar-bottom { padding: 8px 8px 14px; border-top: 1px solid rgba(255,255,255,.15); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.sidebar-avatar {
  width: 30px; height: 30px;
  background: rgba(255,255,255,.25);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: rgba(255,255,255,.6); }

.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 2px solid var(--primary);
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text);
  border-radius: var(--radius-sm);
}
.topbar-hamburger:hover { background: var(--surface2); }
.topbar-title { font-size: 15px; font-weight: 700; color: var(--text); flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-user-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.theme-toggle {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.theme-toggle:hover { background: var(--surface2); color: var(--text); }

.page-content { flex: 1; padding: 22px 24px; }

.page-header {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.page-header-text h2 { font-size: 20px; font-weight: 700; color: var(--text); }
.page-header-text p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon-blue { background: var(--primary-light); color: var(--primary); }
.stat-icon-green { background: var(--success-light); color: var(--success); }
.stat-icon-orange { background: var(--warning-light); color: var(--warning); }
.stat-icon-red { background: var(--danger-light); color: var(--danger); }
.stat-value { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.page-footer {
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
}

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }

@keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.login-page-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 36px 36px 30px;
  box-shadow: var(--shadow-md);
  animation: slideUp .28s ease;
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-logo-icon {
  width: 42px; height: 42px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.login-logo-icon svg { color: #fff; }
.login-app-name { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2; }
.login-app-sub { font-size: 11px; color: var(--text-muted); }
.login-heading { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 22px; }
.form-group { margin-bottom: 14px; }
.login-accounts { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.login-accounts summary { font-size: 13px; font-weight: 600; color: var(--primary); cursor: pointer; list-style: none; }
.login-accounts summary::-webkit-details-marker { display: none; }
.login-accounts-table { margin-top: 10px; }
.login-theme-btn { position: fixed; top: 14px; right: 14px; }

.form-section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.form-section:last-child { border-bottom: none; }
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 14px; align-items: flex-end; }
.form-group { margin-bottom: 14px; }

.actions-col { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.empty-state { text-align: center; padding: 44px 24px; color: var(--text-muted); }
.empty-state p { font-size: 14px; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); animation: slideIn .2s ease; }
  .sidebar-close { display: flex !important; }
  .main-area { margin-left: 0; }
  .topbar-hamburger { display: flex !important; }
  .page-content { padding: 14px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .login-card { padding: 26px 20px; }
  .topbar { padding: 0 14px; }
  .topbar-user-label { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
}