/* ============================================================================
   HomeoClinic — page & component styles
   ----------------------------------------------------------------------------
   Design tokens and primitives live in theme.css, which loads first.
   This file holds layout and page-specific components only.

   The legacy aliases below map the old variable names onto the new tokens, so
   the thirteen pages that reference --accent / --warn / --radius keep working
   untouched. Prefer the token names directly in new code.
   ========================================================================== */

:root {
  --accent:      var(--primary);
  --accent-soft: var(--primary-soft);
  --accent-ink:  var(--primary-ink);
  --warn:        var(--amber);
  --warn-soft:   var(--amber-soft);
  --radius:      var(--r-md);
  --shadow:      var(--sh-sm);
}

html { -webkit-text-size-adjust: 100%; }

/* ---------- Sidebar layout ---------- */
body.with-sidebar { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: var(--sp-5) var(--sp-3);
}
.brand {
  font-size: var(--fs-xl); font-weight: var(--fw-bold); color: var(--ink);
  letter-spacing: -.02em; padding: var(--sp-1) var(--sp-3) var(--sp-4); display: block;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--primary); }

/* Active clinic — visible on every page for every role; the pinned roles
   (receptionist, pharmacist) get a static badge, the switching roles
   (doctor, accountant, admin) get a select that posts to switch_clinic.php. */
.clinic-box { padding: 0 var(--sp-3) var(--sp-4); }
.clinic-label {
  font-size: var(--fs-2xs); font-weight: var(--fw-bold); text-transform: uppercase;
  letter-spacing: .09em; color: var(--muted); margin-bottom: var(--sp-1);
}
.clinic-name {
  display: block; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm);
  background: var(--primary-soft); color: var(--primary-ink);
  font-size: var(--fs-sm); font-weight: var(--fw-semi);
}
.clinic-select {
  padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.clinic-noscript-submit { margin-top: var(--sp-2); }

.sidenav { flex: 1; overflow-y: auto; }
.nav-section {
  font-size: var(--fs-2xs); font-weight: var(--fw-bold); text-transform: uppercase;
  letter-spacing: .09em; color: var(--muted); padding: var(--sp-4) var(--sp-3) var(--sp-2);
}
.sidenav a {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); border-radius: var(--r-sm);
  color: var(--ink-soft); font-weight: var(--fw-med); font-size: var(--fs-md);
  margin-bottom: 2px; transition: background var(--t-fast), color var(--t-fast);
}
.sidenav a:hover { background: var(--surface-alt); color: var(--ink); text-decoration: none; }
.sidenav a.active {
  background: var(--primary-soft); color: var(--primary-ink); font-weight: var(--fw-semi);
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-ico { width: 20px; text-align: center; font-size: var(--fs-md); }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff; min-width: 20px; height: 20px;
  border-radius: var(--r-pill); font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  display: flex; align-items: center; justify-content: center; padding: 0 6px;
  animation: nav-badge-pulse 1.6s infinite;
}
@keyframes nav-badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179,38,30,.55); }
  50% { box-shadow: 0 0 0 5px rgba(179,38,30,0); }
}
.sidenav a.nav-alert { color: var(--danger); }
.sidenav a.nav-alert .nav-ico { animation: nav-alert-shake 2.4s infinite; }
@keyframes nav-alert-shake {
  0%, 85%, 100% { transform: rotate(0); }
  87% { transform: rotate(-12deg); } 89% { transform: rotate(10deg); }
  91% { transform: rotate(-8deg); } 93% { transform: rotate(6deg); } 95% { transform: rotate(0); }
}

.userbox { border-top: 1px solid var(--line); padding: var(--sp-4) var(--sp-3) var(--sp-1); margin-top: var(--sp-3); }
.userbox .uname { font-weight: var(--fw-semi); font-size: var(--fs-md); }
.userbox .urole { color: var(--muted); font-size: var(--fs-xs); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 1240px; margin: 0 auto; padding: var(--sp-7) var(--sp-7) var(--sp-8); flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: var(--fs-xs); padding: var(--sp-5); }

@media (max-width: 900px) {
  body.with-sidebar { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 50;
    flex-direction: row; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
    padding: var(--sp-2) var(--sp-4); border-right: none;
    border-bottom: 1px solid var(--line); box-shadow: var(--sh-xs);
  }
  .brand { padding: var(--sp-1) var(--sp-2); font-size: var(--fs-lg); }
  .clinic-box { padding: 0; order: 1; }
  .clinic-label { display: none; }
  .clinic-name { padding: var(--sp-1) var(--sp-2); }
  .clinic-select { padding: var(--sp-1) var(--sp-2); }
  .clinic-noscript-submit { margin-top: 0; margin-left: var(--sp-1); display: inline-flex !important; }
  .sidenav { display: flex; flex: 1; gap: 2px; overflow-x: auto; }
  .nav-section { display: none; }
  .sidenav a { white-space: nowrap; padding: 7px var(--sp-3); }
  .sidenav a.active { box-shadow: none; }
  .userbox { border-top: none; padding: 0 var(--sp-2); margin: 0; }
  .userbox .urole { display: none; }
  .userbox .btn { display: inline-block !important; margin-top: 2px !important; }
  .page { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
}

/* ---------- Login ---------- */
.login-shell {
  display: grid;
  grid-template-columns: 44% 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

/* -- panel -- */
.login-art {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: var(--sp-fit-lg) var(--sp-fit-lg) 0;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-ink) 74%);
  color: var(--on-primary);
}
.art-rings { position: absolute; inset: 0; width: 100%; height: 100%; }

.art-inner {
  position: relative;
  display: flex; flex-direction: column;
  gap: var(--sp-fit);
  flex: 1 1 auto; min-height: 0;
}

.art-plate {
  align-self: flex-start;
  display: inline-flex;
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--sh-sm);
}
.art-plate img { display: block; width: 148px; height: auto; border-radius: var(--r-xs); }

.art-eyebrow {
  margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semi);
  letter-spacing: .02em; color: var(--on-primary-soft);
}
.art-head {
  margin: 0; max-width: 16ch;
  font-size: var(--fs-3xl); font-weight: var(--fw-semi);
  line-height: var(--lh-tight); letter-spacing: -.015em;
}
.art-sub {
  margin: 0; max-width: 46ch;
  font-size: var(--fs-md); line-height: var(--lh-body);
  color: var(--on-primary-soft);
}

.art-mods {
  margin: 0; padding: var(--sp-fit) 0 0; list-style: none;
  border-top: 1px solid var(--on-primary-line);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: var(--sp-4) var(--sp-5);
}
.art-mods li { display: grid; grid-template-columns: 20px 1fr; gap: var(--sp-3); align-items: start; }
.art-mods svg { width: 20px; height: 20px; margin-top: 2px; opacity: .82; }
.m-name { display: block; font-size: var(--fs-sm); font-weight: var(--fw-semi); line-height: var(--lh-tight); }
.m-desc { display: block; margin-top: 2px; font-size: var(--fs-xs); line-height: var(--lh-tight);
          color: var(--on-primary-soft); }

.art-date {
  margin: auto 0 0; padding-top: var(--sp-fit);
  font-size: var(--fs-xs); font-weight: var(--fw-semi);
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--on-primary-soft);
}

.art-band {
  position: relative; display: block;
  width: calc(100% + 2 * var(--sp-fit-lg));
  margin: var(--sp-fit) calc(-1 * var(--sp-fit-lg)) 0;
  height: clamp(84px, 12vh, 118px);
}
.art-band .vl { transform-box: fill-box; transform-origin: 50% 100%; }

/* -- form -- */
.login-main {
  display: flex;
  align-items: center;
  align-items: safe center;      /* dropped by old browsers, which fall back to the line above */
  justify-content: center;
  padding: var(--sp-fit-lg) var(--sp-7);
  background: var(--surface);
}
.login-form { width: 100%; max-width: 384px; }
.login-form h1 { margin: 0 0 var(--sp-1); }
.login-lede    { margin: 0 0 var(--sp-fit); font-size: var(--fs-sm); color: var(--ink-soft); }
.login-form .flash { margin-bottom: var(--sp-fit); }
.login-form .field { margin-bottom: var(--sp-4); }
.login-form input[aria-invalid="true"] { border-color: var(--danger); }

.pw { position: relative; }
.pw input { padding-right: 68px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  padding: 4px 8px; border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--primary-ink);
  font: inherit; font-size: var(--fs-xs); font-weight: var(--fw-semi); cursor: pointer;
}
.pw-toggle:hover { background: var(--surface-alt); }
.caps-hint { margin: var(--sp-1) 0 0; font-size: var(--fs-xs); font-weight: var(--fw-semi); color: var(--ink-soft); }

.login-form .btn { margin-top: var(--sp-2); }
.login-progress {
  margin-top: var(--sp-2); height: 2px; overflow: hidden;
  border-radius: var(--r-pill); background: var(--primary-soft);
}
.login-progress i { display: block; height: 100%; width: 100%; background: var(--primary); }

.login-help { margin: var(--sp-fit) 0 0; font-size: var(--fs-sm); color: var(--ink-soft); }
.login-foot {
  margin: var(--sp-4) 0 0; padding-top: var(--sp-3);
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs); color: var(--ink-soft);
}

/* -- motion: opt-in only -- */
@keyframes riseIn { to { opacity: 1; transform: none; } }
@keyframes fadeIn { to { opacity: 1; } }
@keyframes fillUp { to { opacity: 1; transform: none; } }
@keyframes dropIn { to { opacity: .30; transform: none; } }
@keyframes sweep  { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

@media (prefers-reduced-motion: no-preference) {
  .art-plate, .art-eyebrow, .art-head, .art-sub, .art-mods li, .art-date,
  .login-form .flash {
    opacity: 0; transform: translateY(8px);
    animation: riseIn .32s cubic-bezier(.2,.7,.2,1) forwards;
  }
  .art-plate   { animation-delay: .04s }
  .art-eyebrow { animation-delay: .08s }
  .art-head    { animation-delay: .12s }
  .art-sub     { animation-delay: .16s }
  .art-mods li:nth-child(1) { animation-delay: .20s }
  .art-mods li:nth-child(2) { animation-delay: .24s }
  .art-mods li:nth-child(3) { animation-delay: .28s }
  .art-mods li:nth-child(4) { animation-delay: .32s }
  .art-mods li:nth-child(5) { animation-delay: .36s }
  .art-mods li:nth-child(6) { animation-delay: .40s }
  .art-date    { animation-delay: .46s }
  .login-form .flash { animation-duration: .2s; animation-delay: 0s }

  .art-drop {
    transform-box: fill-box; transform-origin: 50% 100%;
    opacity: 0; transform: translateY(-14px);
    animation: dropIn .5s cubic-bezier(.4,0,.6,1) .10s forwards;
  }

  .art-band .vl {
    opacity: 0; transform: scaleY(.3);
    animation: fillUp .46s cubic-bezier(.2,.7,.2,1) forwards;
  }
  .vl1 { animation-delay: .30s } .vl2 { animation-delay: .37s }
  .vl3 { animation-delay: .44s } .vl4 { animation-delay: .51s }
  .vl5 { animation-delay: .58s }

  .login-form { opacity: 0; animation: fadeIn .28s ease-out .06s forwards; }

  .login-progress i { width: 40%; animation: sweep 1.1s ease-in-out infinite; }
}

/* -- breakpoints -- */
@media (max-width: 1279px) {
  .login-shell { grid-template-columns: 42% 1fr; }
  .art-head    { font-size: var(--fs-2xl); }
}
@media (max-width: 1023px) {
  .login-shell { grid-template-columns: 38% 1fr; }
  .art-sub     { display: none; }
  .login-main  { padding-left: var(--sp-6); padding-right: var(--sp-6); }
}
@media (max-width: 899px) {
  .login-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-art   { flex-direction: row; align-items: center; padding: var(--sp-4) var(--sp-6); }
  .art-inner   { flex-direction: row; align-items: center; flex-wrap: wrap;
                 gap: var(--sp-3) var(--sp-5); flex: 1 1 auto; }
  .art-head, .art-date, .art-band { display: none; }
  .art-plate img { width: 118px; }
  .art-mods    { border-top: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); }
  .art-mods li { display: block; }
  .art-mods svg, .m-desc { display: none; }
  .m-name      { font-size: var(--fs-xs); font-weight: var(--fw-med); color: var(--on-primary-soft); }
  .login-main  { align-items: flex-start; padding: var(--sp-fit-lg) var(--sp-6) var(--sp-7); }
  .login-form  { max-width: 420px; }
}
@media (max-width: 599px) {
  .login-art   { padding: var(--sp-3) var(--sp-4); }
  .art-mods    { display: none; }
  .art-plate   { padding: var(--sp-1); }
  .art-plate img { width: 104px; }
  .art-eyebrow { font-size: var(--fs-xs); }
  .login-main  { padding: var(--sp-fit-lg) var(--sp-5) var(--sp-6); }
  .login-form h1 { font-size: var(--fs-xl); }
}
@media (max-width: 379px) {
  .login-main { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}

/* Tier C — short viewports */
@media (max-height: 700px) {
  .login-lede { display: none; }
}
@media (max-height: 700px) and (max-width: 899px) {
  .art-mods { display: none; }
}
@media (max-height: 700px) and (min-width: 900px) {
  .art-head { font-size: var(--fs-2xl); }
  .m-desc   { display: none; }
  .art-band { height: 84px; }
}
/* Tier D — landscape phones, keyboard raised */
@media (max-height: 560px) {
  .login-art   { padding: var(--sp-2) var(--sp-4); }
  .art-eyebrow { display: none; }
  .art-plate img { width: 92px; }
  .login-help  { display: none; }
  .login-form .field { margin-bottom: var(--sp-3); }
  .login-foot  { margin-top: var(--sp-3); font-size: var(--fs-2xs); }
}

/* ---------- Page furniture ---------- */
.card { margin-bottom: var(--sp-5); }
.card h2 { margin: 0 0 var(--sp-4); font-size: var(--fs-lg); }

.page-title {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-4); border-bottom: 1px solid var(--line);
}
.page-title h1 { margin: 0; font-size: var(--fs-2xl); letter-spacing: -.02em; }

.grid { display: grid; gap: var(--sp-4); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }

.stat { text-align: left; padding: var(--sp-4) var(--sp-5); }
.stat .num { font-size: var(--fs-3xl); font-weight: var(--fw-bold); letter-spacing: -.03em; line-height: 1.15; }
.stat .lbl { color: var(--muted); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .07em; font-weight: var(--fw-semi); margin-top: 2px; }

.flash { margin-bottom: var(--sp-4); }

.badge-grade1 { background: var(--surface-sunken); color: var(--ink-soft); }
.badge-grade2 { background: var(--info-soft); color: var(--info-ink); }
.badge-grade3 { background: var(--primary); color: #fff; }

/* ---------- Forms ---------- */
textarea { min-height: 120px; resize: vertical; line-height: var(--lh-body); }
.frow { display: grid; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.frow-2 { grid-template-columns: 1fr 1fr; }
.frow-3 { grid-template-columns: repeat(3, 1fr); }
.frow-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 800px) { .frow-2, .frow-3, .frow-4 { grid-template-columns: 1fr; } }

/* ---------- Quick-select chips (guided questionnaire) ---------- */
.chip-group { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  padding: 8px var(--sp-4); border-radius: var(--r-pill);
  border: 1px solid var(--line-strong); background: var(--surface);
  cursor: pointer; user-select: none;
  font-size: var(--fs-md); font-weight: var(--fw-med); color: var(--ink-soft);
  transition: all var(--t-fast);
}
.chip:hover { border-color: var(--primary); color: var(--primary-ink); background: var(--primary-soft); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.qblock { padding: var(--sp-4) 0; border-bottom: 1px solid var(--line); }
.qblock:last-child { border-bottom: none; }
.qblock .qlabel { font-weight: var(--fw-semi); font-size: var(--fs-md); margin-bottom: var(--sp-3); }

/* ---------- Book View (dual-pane chronological history) ---------- */
.bookview {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--sh-sm); overflow: hidden; position: relative;
}
.bookview::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 1px; background: linear-gradient(var(--line), var(--line-strong), var(--line));
}
.book-head {
  padding: var(--sp-3) var(--sp-6); font-weight: var(--fw-bold); font-size: var(--fs-2xs);
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  background: var(--surface-alt); border-bottom: 1px solid var(--line);
}
.visit-row { display: contents; }
.visit-cell { padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--line); }
.visit-row:last-child .visit-cell { border-bottom: none; }
.visit-date {
  display: inline-block; font-weight: var(--fw-bold); font-size: var(--fs-xs);
  background: var(--primary-soft); color: var(--primary-ink);
  padding: 3px var(--sp-3); border-radius: var(--r-pill); margin-bottom: var(--sp-3);
}
.rx-item { padding: var(--sp-2) 0 var(--sp-2) var(--sp-3); border-left: 3px solid var(--primary); margin-bottom: var(--sp-2); }
.rx-item .rx-name { font-weight: var(--fw-semi); }
.rx-item .rx-meta { color: var(--muted); font-size: var(--fs-sm); }
.finding-txt { white-space: pre-wrap; font-size: var(--fs-md); }
.qsummary { margin-top: var(--sp-3); display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.qsummary .tag {
  background: var(--surface-sunken); color: var(--ink-soft); border-radius: var(--r-xs);
  padding: 2px var(--sp-2); font-size: var(--fs-xs); font-weight: var(--fw-med);
}
@media (max-width: 760px) {
  .bookview { grid-template-columns: 1fr; }
  .bookview::before { display: none; }
  .visit-row { display: block; border-bottom: 3px solid var(--line); }
  .book-head.right { display: none; }
}

/* ---------- Repertory ---------- */
.autocomplete { position: relative; }
.ac-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--sh-md); max-height: 320px; overflow-y: auto;
}
.ac-item { padding: var(--sp-3) var(--sp-4); cursor: pointer; border-bottom: 1px solid var(--surface-alt); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.sel { background: var(--primary-soft); }
.ac-item .ch { color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; }

.rubric-chips { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-4); }
.rubric-chip {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
  background: var(--surface-alt); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: var(--sp-3) var(--sp-4);
}
.rubric-chip .x { cursor: pointer; color: var(--danger); font-weight: var(--fw-bold); padding: 2px var(--sp-2); }

.score-grid { overflow-x: auto; border-radius: var(--r-sm); border: 1px solid var(--line); }
.score-grid table { border-collapse: collapse; font-size: var(--fs-sm); min-width: 100%; }
.score-grid th, .score-grid td { border: 1px solid var(--line); padding: var(--sp-2) var(--sp-3); text-align: center; }
.score-grid th.rub { text-align: left; min-width: 260px; font-weight: var(--fw-med); }
.score-grid thead th { background: var(--surface-alt); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.score-grid .g3 { background: var(--primary); color: #fff; font-weight: var(--fw-bold); }
.score-grid .g2 { background: var(--primary-soft); font-weight: var(--fw-semi); color: var(--primary-ink); }
.score-grid .g1 { background: var(--surface-alt); }
.score-grid tfoot td { font-weight: var(--fw-bold); background: var(--surface-alt); }
.score-grid .top-remedy { background: var(--amber-soft); }

/* ---------- Utility ---------- */
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.right { text-align: right; }
.flex { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
details.disclosure {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  margin-bottom: var(--sp-3); background: var(--surface);
}
details.disclosure summary { padding: var(--sp-3) var(--sp-4); cursor: pointer; font-weight: var(--fw-semi); font-size: var(--fs-md); }
details.disclosure .body { padding: 0 var(--sp-4) var(--sp-4); }

/* ---------- Print (invoice) ---------- */
@media print {
  .topbar, .sidebar, .footer, .no-print { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; }
}
