:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e2e8ec;
  --text: #17232c;
  --muted: #627482;
  /* ESTEEM logotipi ranglari: toʻq koʻk va moviy */
  --primary: #1e2ea0;
  --primary-hover: #17248a;
  --primary-soft: #e8ebfa;
  --danger: #c23b3b;
  --danger-soft: #fbeaea;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --info: #2563a8;
  --info-soft: #e6effa;
  --ok: #1f8a4c;
  --ok-soft: #e4f5ea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 34, 48, .06), 0 4px 16px rgba(16, 34, 48, .05);
  --sidebar: #121946;
  --sidebar-text: #bcc3e6;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
td.mono { white-space: nowrap; }
.hidden { display: none !important; }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 600; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; font-size: 20px; }
.brand small { display: block; color: var(--sidebar-text); font-weight: 400; font-size: 11px; }
.nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); margin-bottom: 2px; text-decoration: none;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .ico { width: 18px; text-align: center; }
.nav .count { margin-left: auto; background: #e5484d; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.userbox { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.userbox b { color: #fff; display: block; }
.userbox .links { margin-top: 8px; display: flex; gap: 12px; }
.userbox a { color: var(--sidebar-text); font-size: 12px; }
.install-btn { margin-top: 10px; width: 100%; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.2); color: #fff; }
.install-btn:hover { background: rgba(255,255,255,.18); }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* ---- Cards / grid ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 16px; align-items: start; }
.split-wide { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 20px; }

/* ---- Forms ---- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; outline: none;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox], input[type=radio] { width: auto; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
.doc-pick { background: var(--primary-soft); border: 1px solid #cdd3f3; border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.doc-pick label { color: var(--primary); font-weight: 600; font-size: 13px; }
.doc-pick select { font-size: 14px; margin-bottom: 4px; }
.doc-select { margin-top: 4px; padding: 4px 6px; font-size: 12px; max-width: 100%; }
.choice-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 12px; margin: 6px 0; }
.choice-grid .check { margin: 0; padding: 4px 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin: 0 14px 6px 0; cursor: pointer; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #efc7c7; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn.block { width: 100%; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { font: inherit; border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; color: var(--muted); border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 600; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.unpaid { background: var(--warn-soft); color: var(--warn); }
.badge.paid { background: var(--info-soft); color: var(--info); }
.badge.in_progress { background: #efe7fb; color: #6b3fb5; }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.flag-high, .flag-low { color: var(--danger); font-weight: 700; }
.lab-form td { vertical-align: middle; }
.lab-form tr.sec td, .lab-res tr.sec td { background: var(--primary-soft); color: var(--primary); font-weight: 600; text-align: center; }
.lab-form td.abnormal input, .lab-form td.abnormal select { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.flag-note { font-size: 11px; color: var(--danger); font-weight: 600; min-height: 0; }
.flag-high, .flag-low { background: var(--danger-soft); }
.badge.lab1 { background: var(--primary-soft); color: var(--primary); }
.badge.lab2 { background: #e2f5f7; color: #0f7f8c; }
.lab-sum td { font-size: 16px; }
.lab-sum th { vertical-align: bottom; }

/* ---- Lists ---- */
.list { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.list-item { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; background: var(--surface); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item.sel { background: var(--primary-soft); }
.list-item .title { font-weight: 600; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.queue-no { display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 0 8px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 18px; }
.queue-item { display: flex; gap: 14px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
.queue-item .info { flex: 1; min-width: 0; }
.queue-item.active { border-color: #c9b5ec; background: #faf7ff; }

.svc-list { max-height: 420px; overflow-y: auto; }
.svc { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.svc:hover { background: var(--primary-soft); }
.svc .price { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cart-item { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.total-line { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; padding-top: 12px; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.visit { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; background: var(--surface); }
.visit-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.result-box { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-top: 6px; font-size: 13px; }
.result-box p { margin: 4px 0; white-space: pre-wrap; }

.bar { height: 8px; border-radius: 4px; background: var(--primary); min-width: 2px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; text-decoration: none; cursor: pointer; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- Modal / toast ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 30, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
#toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: tin .2s ease; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--primary); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---- Logotip ---- */
.brand-box { display: block; margin: 14px 12px 10px; padding: 8px 10px; background: #fff; border-radius: 10px; }
/* logo.webp (2000×667) dan faqat emblema va "ESTEEM Medikal klinikasi" qismi koʻrsatiladi */
.brand-logo {
  display: block; width: 100%; aspect-ratio: 1040 / 370;
  background: url('/logo.webp') no-repeat; background-size: 192.3% auto; background-position: 4.17% 45.45%;
}
.topbar .brand-logo { width: 130px; background-color: #fff; border-radius: 6px; }

/* ---- Login ---- */
.login-page {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding: 32px 16px; background: linear-gradient(180deg, #ffffff 0%, #eef1fa 100%);
}
.login-logo { width: min(940px, 100%); aspect-ratio: 2000 / 430; object-fit: cover; object-position: center 50%; }
.login-page .login { max-width: 380px; width: 100%; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #0f2a33, #0e7c66); }
.login { width: 100%; max-width: 380px; }
.login .brand { color: var(--text); padding: 0 0 18px; }
.demo { margin-top: 14px; font-size: 12px; color: var(--muted); line-height: 1.6; }

.demo-bar {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 45;
  background: var(--warn-soft); color: var(--warn); border: 1px solid #f0d9a8; border-radius: 20px;
  padding: 6px 14px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap;
}
.demo-bar a { color: var(--warn); font-weight: 600; text-decoration: underline; }
@media print { .demo-bar { display: none; } }

/* ---- Tablo ---- */
.tablo { min-height: 100vh; background: #0b1f26; color: #fff; padding: 28px; }
.tablo h1 { font-size: 34px; display: flex; justify-content: space-between; }
.tablo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; margin-top: 22px; }
.tablo-card { background: #12313b; border-radius: 16px; padding: 20px; }
.tablo-card h2 { font-size: 24px; margin-bottom: 4px; }
.tablo-card .room { color: #8fb3bf; font-size: 18px; }
.tablo-now { font-size: 64px; font-weight: 800; color: #45d6a8; margin: 10px 0; line-height: 1; }
.tablo-qr { position: fixed; right: 20px; bottom: 20px; width: 150px; background: #fff; border-radius: 12px; padding: 8px; text-align: center; color: #0b1f26; font-size: 12px; line-height: 1.2; }
.tablo-qr svg { width: 100%; display: block; }
.tablo-wait { font-size: 26px; color: #c9dde3; }

@media print {
  .sidebar, .topbar, .no-print, #toast-root { display: none !important; }
  .main { padding: 0; }
  body, .card, .stat { background: #fff; box-shadow: none; }
}

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split-wide { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .sidebar { position: fixed; left: -240px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--sidebar); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .layout { flex-direction: column; }
  .main { padding: 16px; }
  .g2, .g3, .g4, .form-grid { grid-template-columns: 1fr; }
}
