:root {
  --brand: #0d9488;
  --brand-2: #14b8a6;
  --brand-dark: #0f5e57;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6edf0;
  --bg: #f3f7f8;
  --soft: #eef7f6;
  --field: #f8fafc;
  --warn-bg: #fff6e5;
  --warn: #b45309;
  --bad-bg: #fff1f1;
  --bad: #dc2626;
  --ok-bg: #e3f5f1;
  --blue-bg: #eaf0ff;
  --blue: #2f5bd3;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 30px rgba(15, 23, 42, 0.06);
  --glow: 0 8px 20px rgba(13, 148, 136, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  background:
    radial-gradient(1100px 560px at 100% -10%, #d6f2ec 0%, transparent 60%),
    radial-gradient(900px 520px at -10% 110%, #e2edff 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* ------------------------------------------------------------ shell */

.shell { display: flex; min-height: 100vh; }
.main-col { flex: 1; min-width: 0; }
main { max-width: 1100px; margin: 0 auto; padding: 28px 28px 90px; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 236px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  border-inline-end: 1px solid var(--line);
}
body.guest .sidebar { display: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 24px; color: var(--ink); text-decoration: none; }
.brand strong { display: block; font-size: 21px; font-weight: 800; line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: 13px; }
.brand-mark {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 21px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--brand-dark));
  box-shadow: var(--glow);
}

#nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
#nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
#nav a svg { width: 21px; height: 21px; flex: none; }
#nav a:hover { background: var(--soft); color: var(--brand-dark); }
#nav a.active { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff; box-shadow: var(--glow); }
#nav a.logout { margin-top: auto; }
#nav .count {
  margin-inline-start: auto;
  min-width: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--bad);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
}
#nav .count:empty { display: none; }
.request { flex-wrap: wrap; }
.request a { color: var(--brand-dark); font-weight: 700; text-decoration: none; }
.request a:hover { text-decoration: underline; }
.request a.receipt { display: inline-block; margin-top: 8px; cursor: zoom-in; }
#receipt-box {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  overflow: hidden;
}
#receipt-box[open] { display: flex; flex-direction: column; }
#receipt-box::backdrop { background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(3px); }
#receipt-box .receipt-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#receipt-box .receipt-head .muted { flex: 1; font-size: 14px; }
#receipt-box .receipt-body { flex: 1; min-height: 0; overflow: auto; background: var(--bg); display: flex; justify-content: center; }
#receipt-box .receipt-body img { display: block; max-width: 100%; height: auto; }
#receipt-box .receipt-foot { padding: 10px 16px; border-top: 1px solid var(--line); text-align: start; }
.request a.receipt img { display: block; max-width: 160px; max-height: 200px; border: 1px solid var(--line); border-radius: 10px; object-fit: contain; background: #fff; }
.request .request-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.request .request-actions input { width: 120px; height: 38px; }
.alert a { color: inherit; }
#nav a.logout:hover { background: var(--bad-bg); color: var(--bad); }

.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 9vh auto 0; text-align: center; }
.login-brand .brand-mark { width: 60px; height: 60px; font-size: 30px; border-radius: 18px; }
.login-brand strong { font-size: 28px; font-weight: 800; }
.card.narrow { max-width: 440px; margin: 22px auto 40px; }

/* ------------------------------------------------------------ dashboard */

.hero { margin: 0 0 18px; }
.hero .hello { margin: 0; color: var(--brand); font-weight: 700; }
.hero h1 { margin: 0; font-size: 30px; font-weight: 800; line-height: 1.3; }
.hero .today { margin: 2px 0 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.stat-icon { flex: none; width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; }
.stat-icon svg { width: 23px; height: 23px; }
.stat-num { display: block; font-size: 26px; font-weight: 800; line-height: 1.15; white-space: nowrap; }
.stat-num small { font-size: 14px; font-weight: 600; color: var(--muted); }
.stat-label { display: block; color: var(--muted); font-size: 13px; }
.stat.teal .stat-icon { background: var(--ok-bg); color: var(--brand); }
.stat.slate .stat-icon { background: #eef2f6; color: #475569; }
.stat.amber .stat-icon { background: var(--warn-bg); color: #d97706; }
.stat.blue .stat-icon { background: var(--blue-bg); color: var(--blue); }
.stat.red .stat-icon { background: var(--bad-bg); color: var(--bad); }
.stat.red .stat-num { color: var(--bad); }

.progress { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--brand-2), var(--brand)); border-radius: 99px; }

/* ------------------------------------------------------------ cards and forms */

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 19px; font-weight: 700; }
.card h3 { margin: 0 0 10px; font-size: 16px; color: var(--brand-dark); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
details.card > summary { cursor: pointer; font-weight: 700; color: var(--brand-dark); font-size: 17px; }
details.card[open] > summary { margin-bottom: 14px; }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cols > .card { margin-bottom: 0; }
.cols + .card, .cols + details { margin-top: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.field { margin-bottom: 12px; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }

input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 10px 13px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: var(--field);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input:not([type="checkbox"]), select { height: 46px; padding-block: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.16);
}
input::placeholder, textarea::placeholder { color: #a0aec0; }
[dir="ltr"] { text-align: left; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }

button, .button {
  font: inherit;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 6px 14px rgba(13, 148, 136, 0.22);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s, box-shadow 0.15s, filter 0.15s, background 0.15s;
}
button svg, .button svg { width: 18px; height: 18px; }
button:hover, .button:hover { filter: brightness(1.05); transform: translateY(-1px); }
button:disabled { background: #e2e8f0; color: #94a3b8; box-shadow: none; cursor: not-allowed; transform: none; }
.secondary { background: var(--soft) !important; color: var(--brand-dark) !important; box-shadow: none !important; }
.danger { background: var(--bad-bg) !important; color: var(--bad) !important; box-shadow: none !important; }
.whatsapp { background: #e8f8ee !important; color: #128c4a !important; box-shadow: none !important; }
.small { padding: 6px 12px; font-size: 14px; }
.big { width: 100%; padding: 14px; font-size: 17px; border-radius: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.chips button { padding: 4px 12px; font-size: 14px; }

.page-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
button.back {
  background: #fff;
  color: var(--brand-dark);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 6px 16px;
  font-size: 15px;
  border-radius: 99px;
}
.page-title { color: var(--muted); font-size: 15px; }

.muted { color: var(--muted); font-size: 14px; }
.nowrap { white-space: nowrap; }
.error { color: var(--bad); font-size: 14px; margin: 8px 0 0; }

.badge {
  font-size: 12.5px;
  font-weight: 700;
  padding: 3px 11px;
  border-radius: 99px;
  background: #eef2f6;
  color: #475569;
  white-space: nowrap;
  display: inline-block;
  line-height: 1.6;
}
.badge.ok { background: var(--ok-bg); color: var(--brand-dark); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

/* ------------------------------------------------------------ clinics table */

.search { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
table.data th { font-size: 13px; color: var(--muted); font-weight: 600; text-align: start; padding: 0 10px 8px; white-space: nowrap; }
table.data td { padding: 12px 10px; border-top: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr { cursor: pointer; transition: background 0.15s; }
table.data tbody tr:hover { background: var(--soft); }
table.data td strong { display: block; }
table.data .num-cell { font-weight: 800; white-space: nowrap; }
table.data .num-cell.low { color: var(--bad); }
table.plain tbody tr { cursor: default; }
table.plain tbody tr:hover { background: none; }
table.plain input:not([type="checkbox"]) { height: 40px; min-width: 70px; max-width: 110px; }
table.plain td { padding-inline: 6px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li > a { color: var(--ink); text-decoration: none; }
.list li > a:hover strong { color: var(--brand-dark); }
.list .amount { font-weight: 800; white-space: nowrap; }
.list .amount.plus { color: var(--brand-dark); }
.list .amount.minus { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }

/* ------------------------------------------------------------ clinic page */

.clinic-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.clinic-head .who { flex: 1; min-width: 200px; }
.clinic-head h2 { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clinic-head .actions { margin-top: 0; }
.clinic-head .who a { color: var(--brand-dark); font-weight: 600; text-decoration: none; }
.clinic-head .who a:hover { text-decoration: underline; }
.avatar {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand-dark));
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: var(--glow);
}
.alert { border-radius: 14px; padding: 10px 16px; margin-bottom: 16px; font-weight: 700; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #10b981; margin-inline-end: 6px; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }
.key-box { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.key-box code {
  flex: 1;
  min-width: 0;
  background: #fff;
  color: var(--ink);
  border: 1px dashed #f0c27a;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  word-break: break-all;
  user-select: all;
}

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); }

/* ------------------------------------------------------------ tablet and phone */

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .cols { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: auto;
    width: 100%;
    z-index: 20;
    flex-direction: row;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-inline-end: 0;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
  }
  .sidebar .brand { display: none; }
  #nav { flex-direction: row; justify-content: space-around; }
  #nav a { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 12px; }
  #nav a.logout { margin-top: 0; }
  main { padding: 18px 14px 110px; }
  .hero h1 { font-size: 24px; }
  .stat { padding: 12px; }
  .stat-icon { width: 40px; height: 40px; border-radius: 13px; }
  .stat-num { font-size: 21px; }
  .card { padding: 16px; border-radius: 18px; }
  #toast { bottom: 90px; }
  table.data.clinics thead { display: none; }
  table.data.clinics, table.data.clinics tbody, table.data.clinics tr, table.data.clinics td { display: block; }
  table.data.clinics tr { border-top: 1px solid var(--line); padding: 10px 0; }
  table.data.clinics td { border: 0; padding: 2px 4px; }
  table.data.clinics td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; font-weight: 400; }
}
