/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg:        #F7F8FA;
  --surface:   #FFFFFF;
  --border:    #E4E7ED;
  --fg:        #1A1F2E;
  --fg-2:      #5A6273;
  --accent:    #1B5E8C;
  --accent-lt: #E8F1F8;
  --accent-dk: #144875;
  --green:     #1A7A4A;
  --green-lt:  #E6F4ED;
  --amber:     #9A5E00;
  --amber-lt:  #FDF3E3;
  --red:       #B0281A;
  --red-lt:    #FDECEA;
  --radius:    8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0F1117;
    --surface:   #1A1F2E;
    --border:    #2D3348;
    --fg:        #E8EAF0;
    --fg-2:      #8B90A0;
    --accent:    #3A8FC7;
    --accent-lt: #1B2A3A;
    --accent-dk: #5AAEE0;
    --green:     #2DA866;
    --green-lt:  #0D2018;
    --amber:     #D4890A;
    --amber-lt:  #2A1E00;
    --red:       #E05445;
    --red-lt:    #2A0A08;
  }
}

:root[data-theme="dark"] {
  --bg:        #0F1117;
  --surface:   #1A1F2E;
  --border:    #2D3348;
  --fg:        #E8EAF0;
  --fg-2:      #8B90A0;
  --accent:    #3A8FC7;
  --accent-lt: #1B2A3A;
  --accent-dk: #5AAEE0;
  --green:     #2DA866;
  --green-lt:  #0D2018;
  --amber:     #D4890A;
  --amber-lt:  #2A1E00;
  --red:       #E05445;
  --red-lt:    #2A0A08;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Layout ──────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ── Header ──────────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-brand { display: flex; align-items: center; gap: 8px; }

.brand-logo {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.brand-name { font-weight: 700; font-size: 18px; color: var(--accent); }

.header-nav { display: flex; gap: 4px; flex: 1; }
.nav-link { padding: 6px 14px; border-radius: 6px; color: var(--fg-2); font-size: 14px; transition: background .15s; }
.nav-link:hover, .nav-link.active { background: var(--accent-lt); color: var(--accent); text-decoration: none; }

.header-user { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.user-name { font-size: 14px; color: var(--fg-2); }
.user-role-badge {
  font-size: 11px; font-weight: 600;
  background: var(--accent-lt); color: var(--accent);
  padding: 2px 8px; border-radius: 20px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 500;
  border: none; cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-dk); }
.btn-success  { background: var(--green); color: #fff; }
.btn-success:hover  { background: color-mix(in srgb, var(--green) 85%, #000); }
.btn-warning  { background: var(--amber); color: #fff; }
.btn-warning:hover  { background: color-mix(in srgb, var(--amber) 85%, #000); }
.btn-danger   { background: var(--red); color: #fff; }
.btn-danger:hover   { background: color-mix(in srgb, var(--red) 85%, #000); }
.btn-outline  { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover  { background: var(--accent-lt); }
.btn-ghost    { background: transparent; color: var(--fg-2); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--bg); }

.btn-sm  { padding: 5px 12px; font-size: 13px; }
.btn-xs  { padding: 3px 8px; font-size: 12px; }
.btn-lg  { padding: 12px 28px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 14px; font-weight: 500; color: var(--fg-2); }

input[type="text"], input[type="password"], input[type="date"], input[type="file"],
select, textarea {
  font-family: inherit; font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--fg);
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

.radio-group { display: flex; gap: 24px; flex-wrap: wrap; }
.radio-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--fg); cursor: pointer; }
.radio-label input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.form-textarea { resize: vertical; min-height: 64px; }

.input-sm { padding: 4px 8px; font-size: 13px; }

/* ── Login ───────────────────────────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-md);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.logo-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 20px; font-weight: 700;
  margin-bottom: 12px;
}
.login-title { font-size: 26px; font-weight: 700; color: var(--accent); }
.login-subtitle { font-size: 14px; color: var(--fg-2); margin-top: 4px; line-height: 1.5; }
.login-form { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 14px; margin-bottom: 12px; }
.alert-error { background: var(--red-lt); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 25%, transparent); }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 20px; border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 15px; font-weight: 500; color: var(--fg-2);
  border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--fg); }

.tab-content.hidden { display: none; }

/* ── Prescription Form ───────────────────────────────────────── */
.rx-form { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.section-title { font-size: 16px; font-weight: 600; margin: 0 0 14px; color: var(--fg); }
.form-actions { margin-top: 24px; }

.drug-row {
  display: grid;
  grid-template-columns: 2fr 1.5fr 1.2fr auto;
  gap: 10px; align-items: start;
  padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}
@media (max-width: 700px) {
  .drug-row { grid-template-columns: 1fr; }
}
.drug-row:first-child { padding-top: 0; }

.drug-autocomplete-wrap { position: relative; }
.autocomplete-results {
  position: absolute; top: 100%; right: 0; left: 0; z-index: 200;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  max-height: 220px; overflow-y: auto;
}
.autocomplete-item {
  padding: 10px 14px; cursor: pointer; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center;
  transition: background .1s;
}
.autocomplete-item:hover, .autocomplete-item.active { background: var(--accent-lt); }
.autocomplete-item.focused { background: var(--accent-lt); }

.btn-remove-drug {
  background: none; border: 1px solid var(--border); color: var(--fg-2);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  align-self: center;
}
.btn-remove-drug:hover { background: var(--red-lt); color: var(--red); border-color: var(--red); }

#addDrugBtn { margin-top: 10px; }

/* ── Success Card ────────────────────────────────────────────── */
.success-card {
  background: var(--surface); border: 2px solid var(--green);
  border-radius: 16px; padding: 32px; text-align: center; margin-bottom: 24px;
  animation: fadeIn .3s ease;
}
.success-icon {
  width: 56px; height: 56px; background: var(--green-lt); border-radius: 50%;
  font-size: 28px; color: var(--green);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
}
.success-label { font-size: 18px; font-weight: 600; color: var(--green); margin-bottom: 12px; }
.order-number-display {
  font-size: 32px; font-weight: 700; color: var(--accent);
  letter-spacing: 2px; background: var(--accent-lt);
  padding: 10px 24px; border-radius: 8px; display: inline-block; margin: 8px 0;
}
.success-hint { font-size: 14px; color: var(--fg-2); margin: 8px 0 16px; }
.success-actions { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--fg-2); cursor: pointer; }

/* ── Stats Tiles ─────────────────────────────────────────────── */
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.stats-row-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 600px) {
  .stats-row, .stats-row-4 { grid-template-columns: repeat(2, 1fr); }
}

.stat-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  text-align: center; transition: box-shadow .15s;
}
.stat-tile:hover { box-shadow: var(--shadow-md); }

.stat-value { font-size: 36px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 13px; color: var(--fg-2); margin-top: 6px; }

.stat-pending  .stat-value { color: var(--amber); }
.stat-dispensed .stat-value { color: var(--green); }
.stat-partial  .stat-value { color: var(--accent); }
.stat-not-dispensed .stat-value { color: var(--red); }

/* ── Queue ───────────────────────────────────────────────────── */
.queue-list { display: flex; flex-direction: column; gap: 14px; }

.rx-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow-sm); transition: box-shadow .15s;
}
.rx-card:hover { box-shadow: var(--shadow-md); }
.rx-card-done { opacity: .75; }

.rx-card-header {
  background: var(--accent-lt); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.order-badge {
  font-family: monospace; font-weight: 700; font-size: 14px;
  color: var(--accent); background: #fff; border: 1px solid var(--accent);
  padding: 2px 10px; border-radius: 6px;
}
.rx-time { font-size: 12px; color: var(--fg-2); margin-right: auto; }

.rx-card-body { padding: 14px 16px; }
.rx-meta { display: flex; flex-wrap: wrap; gap: 10px 24px; font-size: 14px; margin-bottom: 10px; }
.rx-meta span { color: var(--fg-2); }
.rx-meta strong { color: var(--fg); }

.drug-list { padding-right: 16px; font-size: 14px; }
.drug-list li { padding: 3px 0; color: var(--fg); }
.drug-list li span { color: var(--fg-2); }

.partial-reason-badge {
  margin-top: 8px; padding: 6px 12px;
  background: var(--amber-lt); color: var(--amber);
  border-radius: 6px; font-size: 13px;
}
.dispensed-meta { font-size: 12px; color: var(--fg-2); margin-top: 8px; }

.rx-card-actions {
  padding: 10px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ── Status Badges ───────────────────────────────────────────── */
.status-badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.status-pending  { background: var(--amber-lt); color: var(--amber); }
.status-dispensed { background: var(--green-lt); color: var(--green); }
.status-partial  { background: var(--accent-lt); color: var(--accent); }

.stock-badge {
  font-size: 11px; padding: 2px 6px; border-radius: 12px; font-weight: 600;
}
.stock-ok  { background: var(--green-lt); color: var(--green); }
.stock-low { background: var(--amber-lt); color: var(--amber); }
.stock-out { background: var(--red-lt); color: var(--red); }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 11px 14px; text-align: right; }
.data-table th { background: var(--accent-lt); color: var(--accent); font-weight: 600; border-bottom: 2px solid var(--border); }
.data-table tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: color-mix(in srgb, var(--bg) 50%, transparent); }
.empty-cell { text-align: center; color: var(--fg-2); padding: 24px !important; }
.mono { font-family: monospace; font-size: 13px; }
.date-cell { font-size: 13px; color: var(--fg-2); }

/* ── Progress Bar ────────────────────────────────────────────── */
.progress-bar-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 20px; padding: 2px;
}
.progress-bar-wrap span { font-size: 12px; white-space: nowrap; color: var(--fg-2); }
.progress-bar {
  height: 8px; background: var(--accent); border-radius: 20px;
  min-width: 4px; max-width: 100%; transition: width .3s;
}

/* ── Toggle Switch ───────────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 22px; cursor: pointer; transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  bottom: 3px; right: 3px; transition: transform .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--green); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(-16px); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: 16px; padding: 28px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow-md);
  animation: slideUp .2s ease;
}
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
.modal-hint { font-size: 13px; color: var(--fg-2); margin-bottom: 12px; }
.modal-textarea { resize: vertical; min-height: 80px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Toast ───────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; left: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 2000;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; max-width: 340px;
  box-shadow: var(--shadow-md);
  animation: slideUp .2s ease;
}
.toast-success { background: var(--green-lt); color: var(--green); border: 1px solid var(--green); }
.toast-error   { background: var(--red-lt);   color: var(--red);   border: 1px solid var(--red); }
.toast-warning { background: var(--amber-lt); color: var(--amber); border: 1px solid var(--amber); }
.toast-info    { background: var(--accent-lt);color: var(--accent);border: 1px solid var(--accent); }

/* ── Export Row ──────────────────────────────────────────────── */
.export-row { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.export-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.export-form input[type="date"] { width: auto; }

/* ── Tab Badge ───────────────────────────────────────────────── */
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; font-size: 11px; font-weight: 700; line-height: 1;
  background: var(--accent-lt); color: var(--accent);
  margin-right: 4px; vertical-align: middle;
}
.tab-btn.active .tab-badge { background: var(--accent); color: #fff; }

/* ── History Filter Bar ──────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.filter-date-input { width: auto; }
.filter-sep { color: var(--fg-2); font-size: 13px; }

/* ── Clickable Stat Tile ─────────────────────────────────────── */
.stat-tile-clickable { cursor: pointer; }
.stat-tile-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Page Header ─────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-title  { font-size: 22px; font-weight: 700; }
.page-actions { display: flex; gap: 8px; }

/* ── Date Filter ─────────────────────────────────────────────── */
.date-filter-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-filter-form input[type="date"] { width: auto; }
.date-filter-form span { color: var(--fg-2); }

/* ── File Input ──────────────────────────────────────────────── */
.file-input { margin-bottom: 12px; }

/* ── Error Pages ─────────────────────────────────────────────── */
.error-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.error-card { text-align: center; padding: 40px; }
.error-code { font-size: 80px; font-weight: 700; color: var(--accent); line-height: 1; }
.error-msg  { font-size: 20px; color: var(--fg-2); margin: 12px 0 20px; }
.error-detail { font-size: 13px; color: var(--fg-2); font-family: monospace; margin-bottom: 16px; }

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--fg-2); padding: 40px; font-size: 15px; }

/* ── Misc ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── User Management ─────────────────────────────────────────── */
.filters-row {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px;
}
.filter-input  { flex: 1; min-width: 180px; }
.filter-select { width: auto; min-width: 130px; }

.modal-lg { max-width: 600px; }

.role-badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.role-admin      { background: var(--accent-lt); color: var(--accent); }
.role-doctor     { background: var(--green-lt);  color: var(--green); }
.role-pharmacist { background: var(--amber-lt);  color: var(--amber); }

.status-active   { background: var(--green-lt); color: var(--green); }
.status-disabled { background: var(--red-lt);   color: var(--red); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Notification ────────────────────────────────────────────── */
.notify-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-lt);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--accent-dk);
}
.notify-bar-hint { color: var(--fg-2); font-size: 13px; }

@keyframes rxPulse {
  0%   { box-shadow: 0 0 0 0 rgba(27,94,140,.5), var(--shadow-sm); }
  60%  { box-shadow: 0 0 0 12px rgba(27,94,140,0), var(--shadow-md); }
  100% { box-shadow: 0 0 0 0 rgba(27,94,140,0), var(--shadow-sm); }
}
.rx-card-new {
  border: 2px solid var(--accent) !important;
  animation: rxPulse 1.1s ease-out 3;
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
