/* ===== Design tokens ===== */
:root {
  --primary: #0f6e5c;
  --primary-dark: #0b5647;
  --primary-light: #d9ede7;
  --primary-rgb: 15,110,92;
  --ink: #1c2622;
  --ink-soft: #5c6b65;
  --paper: #f5f6f4;
  --card: #ffffff;
  --border: #e6e4db;
  --danger: #c0392b;
  --danger-light: #fbeaea;
  --warn: #b3791a;
  --warn-light: #fdf3df;
  --success: #1d8a52;
  --success-light: #e5f6ec;
  --info: #2563a8;
  --info-light: #e8f1fb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28,38,34,0.05), 0 6px 18px rgba(28,38,34,0.06);
  --shadow-lg: 0 8px 30px rgba(28,38,34,0.12);
  --sidebar-w: 240px;
  --transition: 160ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --ink: #eef1ef;
  --ink-soft: #9fb0aa;
  --paper: #121815;
  --card: #1a221e;
  --border: #2a352f;
  --primary-light: rgba(var(--primary-rgb),0.18);
  --danger-light: rgba(192,57,43,0.15);
  --warn-light: rgba(179,121,26,0.15);
  --success-light: rgba(29,138,82,0.15);
  --info-light: rgba(37,99,168,0.15);
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 18px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}
h1, h2, h3 {
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 4px;
}
a { color: var(--primary-dark); text-decoration: none; }
[data-theme="dark"] a { color: #7fd6bb; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-soft); }

.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: #eef4f1;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 60;
  transition: transform var(--transition);
}
[data-theme="dark"] .sidebar { background: #0c110f; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 18px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 14px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; background: #fff; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-family: Georgia, serif; font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.brand-mark.large { width: 56px; height: 56px; font-size: 22px; margin: 0 auto 10px; }
.brand-name { font-family: Georgia, serif; font-weight: 700; font-size: 15px; line-height: 1.25; color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; color: #cdd9d4; padding: 10px 12px; border-radius: 8px; font-size: 14px; transition: background var(--transition), color var(--transition); }
.nav a .icon { width: 16px; height: 16px; opacity: 0.85; }
.nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav-section-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #77897f; padding: 14px 12px 4px; }
.sidebar-footer { padding: 14px 18px 0; border-top: 1px solid rgba(255,255,255,0.1); margin-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name { font-size: 13px; color: #fff; font-weight: 600; }
.user-role { font-size: 11px; color: #9fb0aa; }
.logout-link { font-size: 12px; color: #9fb0aa; }
.sidebar-close, .sidebar-toggle { display: none; }

.main-content { flex: 1; padding: 0 34px 34px; min-width: 0; }

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; margin-bottom: 6px; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-date { font-size: 13px; color: var(--ink-soft); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink-soft); display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn .badge-dot {
  position: absolute; top: 5px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--card);
}
.theme-icon-sun, .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun { display: block; }
:root:not([data-theme="dark"]) .theme-icon-moon { display: block; }

/* ===== Page structure ===== */
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 20px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; }
.link-small { font-size: 13px; }
.link-danger { color: var(--danger) !important; background: none; border: none; padding: 0; cursor: pointer; font-size: 13px; }

/* ===== Stat / KPI cards ===== */
.stat-grid, .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); transition: transform var(--transition), box-shadow var(--transition);
  position: relative; overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card.accent { background: var(--primary-light); border-color: var(--primary); }
.stat-label { display: block; font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px; }
.stat-value { font-family: Georgia, serif; font-size: 26px; font-weight: 700; }

/* KPI card v2 - icon + trend, used on redesigned dashboards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.kpi-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: var(--primary-light); color: var(--primary-dark); flex-shrink: 0;
}
.kpi-icon.warn { background: var(--warn-light); color: var(--warn); }
.kpi-icon.danger { background: var(--danger-light); color: var(--danger); }
.kpi-icon.info { background: var(--info-light); color: var(--info); }
.kpi-icon.success { background: var(--success-light); color: var(--success); }
.kpi-value { font-family: Georgia, serif; font-size: 25px; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }
.kpi-trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.kpi-trend .icon { width: 12px; height: 12px; }
.kpi-trend.up { background: var(--success-light); color: var(--success); }
.kpi-trend.down { background: var(--danger-light); color: var(--danger); }
.kpi-trend.flat { background: var(--paper); color: var(--ink-soft); }

/* ===== Charts ===== */
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.chart-card .panel-head { margin-bottom: 16px; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap.h-260 { height: 260px; }
.chart-wrap.h-220 { height: 220px; }
.chart-wrap.h-200 { height: 200px; }
.chart-legend-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.chart-legend-item { display: flex; align-items: center; justify-content: space-between; font-size: 13px; gap: 8px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; flex-shrink: 0; }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--ink-soft); font-size: 13px; }

/* ===== Progress bars (budget vs actual, stock levels) ===== */
.progress-track { background: var(--paper); border: 1px solid var(--border); border-radius: 999px; height: 9px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width 400ms ease; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }
.progress-row { margin-bottom: 14px; }
.progress-row:last-child { margin-bottom: 0; }
.progress-row-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.progress-row-head .name { font-weight: 600; }
.progress-row-head .figs { color: var(--ink-soft); font-size: 12.5px; }

/* ===== Notifications / Alerts panel ===== */
.notif-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.notif-list { max-height: 340px; overflow-y: auto; }
.notif-item { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); align-items: flex-start; transition: background var(--transition); }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--paper); }
.notif-item.dismissed { display: none; }
.notif-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.notif-icon .icon { width: 16px; height: 16px; }
.notif-icon.danger { background: var(--danger-light); color: var(--danger); }
.notif-icon.warn { background: var(--warn-light); color: var(--warn); }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 13.5px; font-weight: 600; }
.notif-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 1px; }
.notif-dismiss { background: none; border: none; color: var(--ink-soft); cursor: pointer; padding: 4px; border-radius: 6px; flex-shrink: 0; }
.notif-dismiss:hover { color: var(--danger); background: var(--danger-light); }
.notif-dismiss .icon { width: 14px; height: 14px; }
.notif-empty { padding: 26px 20px; text-align: center; color: var(--ink-soft); font-size: 13px; }

/* ===== Timeline (recent sales / activity) ===== */
.timeline-list { display: flex; flex-direction: column; }
.timeline-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 34px; height: 34px; border-radius: 9px; background: var(--primary-light); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.timeline-dot .icon { width: 15px; height: 15px; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-sub { font-size: 12px; color: var(--ink-soft); }
.timeline-amount { font-weight: 700; font-family: Georgia, serif; font-size: 14.5px; white-space: nowrap; }

/* ===== Quick actions ===== */
.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 22px; }
.quick-action {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  color: var(--ink);
}
.quick-action:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); text-decoration: none; color: var(--ink); }
.quick-action .kpi-icon { margin-bottom: 2px; }
.quick-action-label { font-size: 13.5px; font-weight: 700; }
.quick-action-sub { font-size: 11.5px; color: var(--ink-soft); }

/* ===== Tables ===== */
.data-table, .mini-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .mini-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--ink-soft); border-bottom: 2px solid var(--border); padding: 8px 10px;
}
.data-table td, .mini-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td, .mini-table tr:hover td { background: var(--paper); }
.row-actions { white-space: nowrap; display: flex; gap: 10px; }
.text-warn { color: var(--warn); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-success { color: var(--success); font-weight: 600; }

/* ===== Forms ===== */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 12px; }
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--card); color: var(--ink); width: 100%;
}
input[type=color] { padding: 3px; height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
input[readonly] { background: var(--paper); color: var(--ink-soft); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid-1 { display: flex; flex-direction: column; }
.span-2 { grid-column: 1 / -1; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; min-width: 180px; }
.filter-form label { margin-bottom: 0; }
.page-head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 600; padding: 10px 16px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn .icon { width: 15px; height: 15px; }
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--ink); color: var(--paper); }
[data-theme="dark"] .btn-secondary { color: #121815; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--border); }
.btn-block { width: 100%; margin-top: 4px; }
.btn-excel { background: #1d7a4c; color: #fff; }
.btn-excel:hover { background: #145c38; }

.total-box {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--primary-light); border: 1px solid var(--primary); border-radius: 8px;
  padding: 12px 16px; margin: 6px 0 14px; font-size: 15px;
}
.total-box strong { font-family: Georgia, serif; font-size: 20px; color: var(--primary-dark); }

.alert { padding: 10px 14px; border-radius: 7px; font-size: 13px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #eecccc; }
.alert-success { background: var(--success-light); color: var(--primary-dark); border: 1px solid #cbe6da; }

.period-tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.period-tabs a { padding: 7px 14px; border-radius: 6px; font-size: 13px; color: var(--ink-soft); }
.period-tabs a.active { background: var(--primary); color: #fff; }

/* ===== Modal (medicine add/edit) ===== */
.modal { display: none; position: fixed; inset: 0; background: rgba(20,26,24,0.45); align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal.open { display: flex; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 24px 26px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-close { font-size: 22px; color: var(--ink-soft); line-height: 1; background: none; border: none; cursor: pointer; }

.preview-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.preview-thumb { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; background: var(--paper); }
.preview-thumb.wide { width: 90px; height: 44px; object-fit: cover; }
.inline-check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.inline-check input { width: auto; }

/* ===== Tables that may run wide (SMS/history/logs) ===== */
.table-scroll, .table-responsive { overflow-x: auto; }
.table-scroll table { min-width: 720px; }

/* ===== Badges & pills ===== */
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; background: var(--primary-light); color: var(--primary-dark); margin: 2px 4px 2px 0; white-space: nowrap;
}
.badge-primary { background: var(--primary); color: #fff; }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warn { background: var(--warn-light); color: var(--warn); }
.badge-success { background: var(--success-light); color: var(--success); }
.role-pill {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; background: var(--ink); color: var(--paper);
}

/* ===== Permission checkbox grid (Settings > Roles) ===== */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin: 14px 0; }
.perm-group { background: var(--paper); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.perm-group-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); font-weight: 700; margin-bottom: 8px; }
.perm-group .inline-check { margin-bottom: 8px; font-size: 13px; }
.perm-group .inline-check:last-child { margin-bottom: 0; }

/* ===== Inline SMS-alert bar on Reports ===== */
.alert-sms-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 18px; box-shadow: var(--shadow);
}

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 28px 16px; color: var(--ink-soft); }
.empty-state .icon { width: 30px; height: 30px; margin-bottom: 8px; opacity: 0.55; }
.empty-state p { margin: 0; font-size: 13.5px; }

/* ===== Login page ===== */
.login-body { margin: 0; background: var(--paper); }
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--primary-dark), var(--ink));
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 14px; padding: 36px 34px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-logo { width: 56px; height: 56px; object-fit: contain; margin-bottom: 10px; }
.login-brand h1 { font-size: 21px; margin-bottom: 2px; }
.login-form label { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--ink-soft); text-align: center; margin-top: 16px; }

/* ===== Mobile sidebar / responsive ===== */
@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 55; }
  .sidebar-overlay.open { display: block; }
  .main-content { padding: 0 16px 24px; }
  .topbar { padding: 12px 0; }
}

/* ===== Redesign polish ===== */
.main-content { animation: fadeIn 220ms ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
#notifDropdown { box-shadow: var(--shadow-lg) !important; }
.kpi-card, .chart-card, .stat-card { animation: fadeIn 260ms ease; }

/* ===== Print styles ===== */
@media print {
  .sidebar, .page-head-actions, .filter-bar, .btn, .row-actions, .alert-sms-bar, .topbar-actions { display: none !important; }
  .main-content { padding: 0; }
  .panel { box-shadow: none; border: none; }
}
