/* Empire Clinic — Istoma look (AdminLTE 2 "skin-yellow"), rebuilt without the framework. */
:root {
  --header: #f39c12; --logo: #e08e0b; --header-text: #fff;
  --side: #222d32; --side-dark: #1a2226; --side-active: #1e282c; --side-text: #b8c7ce; --side-sub: #2c3b41;
  --bg: #ecf0f5; --box: #fff; --line: #f4f4f4; --border: #d2d6de; --text: #333; --muted: #666;
  --green: #00a65a; --green-d: #008d4c; --red: #dd4b39; --orange: #f39c12; --aqua: #00c0ef; --blue: #3c8dbc;
  --yellow: #f0ad4e; --purple: #605ca8; --gray: #d2d6de;
  --side-w: 230px; --head-h: 50px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.42857; }
a { color: var(--blue); text-decoration: none; cursor: pointer; }
a:hover { color: #72afd2; }
h1, h2, h3, h4 { font-weight: 400; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.main-header { position: fixed; top: 0; left: 0; right: 0; height: var(--head-h); display: flex; z-index: 30; background: var(--header); }
.logo { width: var(--side-w); flex: none; background: var(--logo); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 300; letter-spacing: .2px; transition: width .2s; overflow: hidden; white-space: nowrap; }
.logo b { font-weight: 700; }
.navbar { flex: 1; display: flex; align-items: center; color: #fff; }
.navbar .toggle { width: 50px; height: var(--head-h); border: 0; background: none; color: #fff; font-size: 16px; cursor: pointer; }
.navbar .toggle:hover { background: rgba(0,0,0,.1); }
.navbar .spacer { flex: 1; }
.nav-icon { position: relative; height: var(--head-h); padding: 0 14px; display: flex; align-items: center; color: #fff; font-size: 15px; }
.nav-icon:hover { background: rgba(0,0,0,.1); color: #fff; }
.nav-icon .label { position: absolute; top: 9px; right: 6px; font-size: 9px; line-height: .9; padding: 2px 3px; border-radius: .25em; background: var(--red); font-weight: 700; }
.user-menu { position: relative; height: var(--head-h); }
.user-menu > a { height: 100%; padding: 0 15px; display: flex; align-items: center; gap: 6px; color: #fff; border-left: 1px solid rgba(255,255,255,.25); }
.user-menu > a:hover { background: rgba(0,0,0,.1); }
.dropdown { position: absolute; right: 0; top: var(--head-h); min-width: 230px; background: #fff; border: 1px solid #ddd; box-shadow: 0 6px 12px rgba(0,0,0,.175); border-radius: 0 0 4px 4px; z-index: 40; }
.dropdown .who { background: var(--header); color: #fff; padding: 14px 15px; }
.dropdown .who small { display: block; opacity: .85; }
.dropdown a { display: block; padding: 9px 15px; color: var(--text); border-top: 1px solid var(--line); }
.dropdown a:hover { background: #f5f5f5; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.main-sidebar { position: fixed; top: var(--head-h); bottom: 0; left: 0; width: var(--side-w); background: var(--side); overflow-y: auto; z-index: 20; transition: transform .2s; }
.sidebar-form { margin: 10px; display: flex; border-radius: 3px; overflow: hidden; }
.sidebar-form input { flex: 1; min-width: 0; border: 0; padding: 7px 10px; background: #fff; outline: 0; height: 34px; }
.sidebar-form button { border: 0; background: #fff; width: 38px; color: #999; cursor: pointer; }
.sidebar-menu { list-style: none; margin: 0; padding: 0; }
.sidebar-menu .header { color: #4b646f; background: var(--side-dark); padding: 10px 15px; font-size: 12px; }
.sidebar-menu > li > a { display: flex; align-items: center; gap: 10px; padding: 12px 15px 12px 15px; color: var(--side-text); border-left: 3px solid transparent; }
.sidebar-menu > li > a i { width: 20px; text-align: center; }
.sidebar-menu > li > a:hover, .sidebar-menu > li.active > a { color: #fff; background: var(--side-active); border-left-color: var(--header); }
.sidebar-menu > li > a .soon { margin-left: auto; font-size: 10px; background: #4b646f; color: #fff; border-radius: 3px; padding: 1px 5px; }
.sidebar-menu > li.disabled > a { opacity: .55; cursor: default; }
.sidebar-menu > li.disabled > a:hover { background: none; border-left-color: transparent; color: var(--side-text); }

/* ── Content ────────────────────────────────────────────────────────────── */
.content-wrapper { margin-left: var(--side-w); padding-top: var(--head-h); min-height: 100%; transition: margin .2s; }
.content { padding: 15px; max-width: 1600px; }
.content-header { padding: 15px 15px 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.content-header h1 { font-size: 24px; }
.content-header .actions { margin-left: auto; display: flex; gap: 8px; }
.logo .mini { display: none; }
@media (min-width: 768px) {  /* collapsed = AdminLTE "mini" sidebar: icons only */
  body.sidebar-collapse .main-sidebar { width: 50px; overflow: visible; }
  body.sidebar-collapse .content-wrapper { margin-left: 50px; }
  body.sidebar-collapse .logo { width: 50px; }
  body.sidebar-collapse .logo > span { display: none; }
  body.sidebar-collapse .logo .mini { display: inline; }
  body.sidebar-collapse .sidebar-form, body.sidebar-collapse .sidebar-menu .header,
  body.sidebar-collapse .sidebar-menu .t, body.sidebar-collapse .sidebar-menu .soon { display: none; }
  body.sidebar-collapse .sidebar-menu > li > a { justify-content: center; padding: 12px 0; }
}
@media (max-width: 767px) {
  .main-sidebar { transform: translateX(-100%); }
  .content-wrapper { margin-left: 0; }
  .logo { width: auto; padding: 0 12px; }
  body.sidebar-open .main-sidebar { transform: none; }
}

/* ── Boxes / cards ──────────────────────────────────────────────────────── */
.box { background: var(--box); border-top: 3px solid var(--border); border-radius: 3px; box-shadow: 0 1px 1px rgba(0,0,0,.1); margin-bottom: 15px; }
.box.box-warning { border-top-color: var(--orange); }
.box.box-success { border-top-color: var(--green); }
.box.box-primary { border-top-color: var(--blue); }
.box.flat { border-top: 0; }
.box-header { padding: 10px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.box-header .box-title { font-size: 18px; }
.box-header .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.box-body { padding: 10px; }
.box-footer { padding: 10px; border-top: 1px solid var(--line); background: #fff; display: flex; align-items: center; gap: 10px; }

/* ── Buttons, inputs ────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 12px; border-radius: 3px; border: 1px solid transparent; cursor: pointer; font-size: 14px; line-height: 1.42857; white-space: nowrap; background: #f4f4f4; border-color: #ddd; color: #444; }
.btn:hover { background: #e7e7e7; }
.btn:disabled { opacity: .65; cursor: not-allowed; }
.btn-success { background: var(--green); border-color: var(--green-d); color: #fff; }
.btn-success:hover { background: var(--green-d); }
.btn-primary { background: var(--blue); border-color: #367fa9; color: #fff; }
.btn-primary:hover { background: #367fa9; }
.btn-danger { background: var(--red); border-color: #d73925; color: #fff; }
.btn-warning { background: var(--orange); border-color: #e08e0b; color: #fff; }
.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-link { background: none; border-color: transparent; color: var(--blue); }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-block { width: 100%; }
.form-control { display: block; width: 100%; height: 34px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 0; background: #fff; outline: 0; box-shadow: none; }
.form-control:focus { border-color: var(--blue); }
textarea.form-control { height: auto; min-height: 70px; resize: vertical; }
select.form-control { padding: 6px 8px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.error-text { color: var(--red); font-size: 13px; margin-top: 6px; }

/* ── Badges / labels ────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 7px; font-size: 11px; font-weight: 700; line-height: 1.5; color: #fff; border-radius: 3px; background: #777; white-space: nowrap; vertical-align: middle; }
.bg-success { background: var(--green) !important; } .bg-danger { background: var(--red) !important; }
.bg-warning { background: var(--orange) !important; } .bg-info { background: var(--aqua) !important; }
.bg-primary { background: var(--blue) !important; } .bg-purple { background: var(--purple) !important; }
.bg-gray { background: var(--gray) !important; color: #444 !important; } .bg-yellow { background: #f0e130 !important; color: #444 !important; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #e8f3fb; color: #2a6fa0; border: 1px solid #c9e2f4; margin-left: 4px; font-weight: 600; }

/* ── Info boxes (dashboard tiles) ───────────────────────────────────────── */
.info-box { display: flex; background: #fff; min-height: 70px; box-shadow: 0 1px 1px rgba(0,0,0,.1); border-radius: 2px; }
.info-box-icon { width: 70px; display: flex; align-items: center; justify-content: center; font-size: 30px; color: #fff; flex: none; }
.info-box-content { padding: 6px 10px; }
.info-box-text { text-transform: uppercase; font-size: 13px; color: var(--blue); }
.info-box-number { font-weight: 700; font-size: 18px; color: var(--blue); }

/* ── Tables / grid ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
.table thead th { border-bottom: 2px solid var(--line); border-top: 0; font-weight: 700; white-space: nowrap; position: sticky; top: 0; background: #fff; }
.table th.right, .table td.right { text-align: right; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--blue); }
.table th .sort { color: #bbb; margin-left: 4px; font-size: 11px; }
.table th.sorted .sort { color: var(--blue); }
.table-hover tbody tr { cursor: pointer; }
.table-hover tbody tr:hover { background: #f5f5f5; }
.table td.pname { font-weight: 600; color: var(--blue); }
.grid-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); }
.grid-toolbar .form-control { width: auto; }
.grid-toolbar .search { flex: 1 1 280px; position: relative; }
.grid-toolbar .search input { width: 100%; padding-left: 32px; }
.grid-toolbar .search i { position: absolute; left: 11px; top: 10px; color: #aaa; }
.pager { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); }

/* ── Tabs (Istoma "nav-tabs-custom") ────────────────────────────────────── */
.nav-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); background: #fff; padding: 0 5px; overflow-x: auto; }
.nav-tabs a { padding: 12px 14px; color: #444; border-top: 3px solid transparent; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.nav-tabs a:hover { color: #999; }
.nav-tabs a.active { border-top-color: var(--blue); color: #444; background: #fff; font-weight: 600; }
.nav-tabs a .badge { font-size: 10px; }

/* ── Patient header (Istoma profile box, tidied) ───────────────────────── */
.profile { display: grid; grid-template-columns: 220px 1fr 1fr; gap: 0; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.1); }
.profile .who { padding: 18px 10px; text-align: center; border-right: 1px solid var(--line); }
.avatar { width: 90px; height: 90px; border-radius: 50%; margin: 0 auto 8px; display: flex; align-items: center; justify-content: center; font-size: 32px; color: #fff; background: #8bc34a; border: 3px solid #d2d6de; }
.avatar.f { background: #e083b0; } .avatar.m { background: #5b9bd5; }
.profile .name { font-size: 21px; color: #444; }
.profile .age { font-weight: 700; margin-top: 2px; }
.profile .col { padding: 10px 15px; }
.profile .col + .col { border-left: 1px solid var(--line); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--muted); }
.kv b { text-align: right; }
.warn { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; margin: 6px 0; border-radius: 3px; font-size: 13px; }
.warn.red { background: #fdecea; color: #a94442; }
.warn.amber { background: #fcf8e3; color: #8a6d3b; }
.warn.ok { background: #eaf7ef; color: #2e7d4f; }
@media (max-width: 1000px) { .profile { grid-template-columns: 1fr; } .profile .col + .col, .profile .who { border: 0; border-top: 1px solid var(--line); } }

/* ── Visits timeline ────────────────────────────────────────────────────── */
.timeline { position: relative; margin: 0; padding: 0 0 0 0; list-style: none; }
.timeline::before { content: ''; position: absolute; top: 0; bottom: 0; left: 31px; width: 4px; background: #ddd; border-radius: 2px; }
.timeline > li { position: relative; margin: 0 0 15px 0; padding-left: 60px; }
.timeline > li > .dot { position: absolute; left: 18px; top: 10px; width: 30px; height: 30px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.timeline > li.month { padding-left: 0; }
.timeline > li.month span { position: relative; display: inline-block; background: var(--red); color: #fff; padding: 4px 10px; border-radius: 4px; font-weight: 600; font-size: 13px; }
.tl-item { background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.1); border-radius: 3px; }
.tl-item .tl-head { padding: 9px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tl-item .tl-head .date { font-weight: 700; }
.tl-item .tl-head .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.tl-item .tl-body { padding: 10px 12px; display: grid; gap: 8px; }
.tl-sec label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.tl-sec div { white-space: pre-wrap; word-break: break-word; }
.price { font-weight: 700; color: var(--green-d); }
mark { background: #fff3a8; padding: 0 1px; }

/* ── Documents ──────────────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 15px; padding: 3px 11px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip.attention { border-color: var(--orange); }
.chip .n { opacity: .7; margin-left: 3px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.doc { background: #fff; border: 1px solid #e3e3e3; border-radius: 4px; overflow: hidden; display: flex; flex-direction: column; }
.doc .thumb { height: 110px; background: #f7f7f7; display: flex; align-items: center; justify-content: center; font-size: 42px; color: #c0392b; cursor: pointer; border-bottom: 1px solid #eee; }
.doc .thumb.img { color: #2980b9; }
.doc .meta { padding: 8px; font-size: 13px; display: grid; gap: 4px; }
.doc .meta .lbl { font-weight: 600; word-break: break-word; }
.doc.unsorted { border-color: var(--orange); }
.dropzone { border: 2px dashed var(--border); border-radius: 4px; padding: 16px; text-align: center; color: var(--muted); background: #fafafa; }
.dropzone.over { border-color: var(--green); background: #eefaf3; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.modal { background: #fff; width: 100%; max-width: 620px; border-radius: 3px; box-shadow: 0 5px 15px rgba(0,0,0,.4); }
.modal.wide { max-width: 1100px; }
.modal-header { padding: 14px 15px; border-bottom: 1px solid #e5e5e5; display: flex; align-items: center; gap: 10px; }
.modal-header h4 { font-size: 18px; flex: 1; }
.modal-header .x { border: 0; background: none; font-size: 22px; line-height: 1; color: #999; cursor: pointer; }
.modal-body { padding: 15px; }
.modal-footer { padding: 12px 15px; border-top: 1px solid #e5e5e5; display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: -40px; background: #fff; border-radius: 0 0 3px 3px; z-index: 2; }
.viewer { display: grid; grid-template-columns: 1fr 260px; min-height: 70vh; }
.viewer .frame { background: #525659; display: flex; align-items: center; justify-content: center; }
.viewer .frame iframe { width: 100%; height: 78vh; border: 0; }
.viewer .frame img { max-width: 100%; max-height: 78vh; }
.viewer .side { padding: 15px; border-left: 1px solid #eee; display: flex; flex-direction: column; gap: 10px; }
.type-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.type-buttons button { text-align: left; }
.type-buttons button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
@media (max-width: 800px) { .viewer { grid-template-columns: 1fr; } }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toasts { position: fixed; right: 15px; bottom: 15px; z-index: 200; display: grid; gap: 8px; }
.toast { padding: 10px 14px; border-radius: 3px; color: #fff; background: #333; box-shadow: 0 3px 8px rgba(0,0,0,.25); max-width: 360px; }
.toast.ok { background: var(--green); } .toast.err { background: var(--red); }

/* ── Login (Istoma style) ───────────────────────────────────────────────── */
body.login { background: #d2d6de; display: flex; align-items: flex-start; justify-content: center; }
.login-box { width: 326px; margin: 9% auto 0; background: #fff; padding: 22px 18px; text-align: center; }
.login-box .brand { font-size: 30px; font-weight: 300; color: #b48a3c; letter-spacing: 2px; }
.login-box .brand b { font-weight: 700; }
.login-box .clinic { font-weight: 700; color: #555; margin: 6px 0 18px; }
.login-box .field { position: relative; margin-bottom: 15px; }
.login-box .field input { padding-right: 34px; height: 36px; }
.login-box .field i { position: absolute; right: 11px; top: 11px; color: #777; }
.login-box .btn-success { width: 100%; height: 36px; }
.login-foot { position: fixed; bottom: 18px; left: 0; right: 0; text-align: center; font-size: 13px; }

.name-note { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 600; color: #a94442; background: #fdecea; border-radius: 3px; padding: 0 5px; vertical-align: middle; }

/* ── Forms: required marks, inline errors, focus ───────────────────────── */
.req { color: var(--red); font-weight: 700; }
.has-error .form-control { border-color: var(--red); background: #fffafa; }
.field-error { color: #a94442; font-size: 12.5px; margin-top: 4px; }
.modal-body > .field-error { padding: 8px 10px; background: #fdecea; border-radius: 3px; }
.btn:focus-visible, a:focus-visible, .chip:focus-visible, .seg button:focus-visible { outline: 2px solid #72afd2; outline-offset: 2px; }
.btn:disabled { pointer-events: none; }

/* ── Grid toolbar extras ───────────────────────────────────────────────── */
.grid-toolbar .search .clear { position: absolute; right: 6px; top: 5px; border: 0; background: none; font-size: 20px; line-height: 1; color: #aaa; cursor: pointer; padding: 0 6px; }
.grid-toolbar .search input { padding-right: 30px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; cursor: pointer; border-left: 1px solid var(--border); height: 32px; }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--blue); color: #fff; }
a.pname { font-weight: 600; color: var(--blue); }
@media (max-width: 700px) { .hide-sm { display: none; } }

/* ── Patient header paperwork checklist ────────────────────────────────── */
.check { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 10px; margin-left: 4px; }
.check.yes { background: #eaf7ef; color: #2e7d4f; }
.check.no { background: #f4f4f4; color: #888; }

/* ── Documents toolbar + whole-tab drop target ─────────────────────────── */
.doc-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.show-touch { display: none; }
@media (hover: none) and (pointer: coarse) { .show-touch { display: inline-flex; } }
#tabBody.drop-over { outline: 3px dashed var(--green); outline-offset: -6px; background: #eefaf3; }

#recentBtn { padding: 0 16px; }
#recentDrop { min-width: 260px; max-height: 70vh; overflow-y: auto; }

/* ── Agenda (day view) ─────────────────────────────────────────────────── */
.agenda-bar { display: flex; align-items: center; gap: 10px; padding: 10px 15px; flex-wrap: wrap; background: var(--bg); position: sticky; top: var(--head-h); z-index: 15; }
.agenda-bar .spacer { flex: 1; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 3px 0 0 3px; } .btn-group .btn:last-child { border-radius: 0 3px 3px 0; }
.date-pick { position: relative; font-size: 15px; cursor: pointer; }
.date-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.sync-pill { font-size: 12px; color: #2e7d4f; background: #eaf7ef; border-radius: 12px; padding: 3px 10px; white-space: nowrap; }
.sync-pill.stale { color: #8a6d3b; background: #fcf8e3; }
.agenda-menu { height: auto; }
.agenda-menu .dropdown { top: 38px; max-height: 70vh; overflow-y: auto; }
.doc-opt { display: flex; align-items: center; gap: 8px; padding: 6px 15px; border-top: 1px solid var(--line); cursor: pointer; font-weight: 400; }
.doc-opt:hover { background: #f5f5f5; }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); flex: none; }
.toggle-small { font-size: 13px; display: inline-flex; gap: 5px; align-items: center; font-weight: 400; }

.agenda-wrap { margin: 0 15px 15px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.1); overflow: auto; overscroll-behavior: contain; max-height: calc(100vh - var(--head-h) - 72px); position: relative; }
.ag-grid { display: flex; position: relative; min-width: max-content; }
.ag-col { flex: 1 0 150px; min-width: 150px; border-left: 1px solid #ddd; }
.ag-gutter { flex: 0 0 52px; position: sticky; left: 0; z-index: 6; background: #fff; }
.ag-head { height: 34px; position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px;
  font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid #ccc; }
.ag-corner { background: #fff; z-index: 7; }
.ag-count { font-size: 11px; background: rgba(255,255,255,.75); color: #333; border-radius: 9px; padding: 0 6px; }
.ag-body { position: relative; }
.ag-row { position: absolute; left: 0; right: 0; border-top: 1px dotted #e3e3e3; }
.ag-row.hour { border-top: 1px solid #c9c9c9; }
.ag-time { position: absolute; right: 6px; margin-top: 1px; font-size: 11px; color: #999; line-height: 1.2; }
.ag-time.hour { font-size: 13px; font-weight: 700; color: #444; }
.ag-off { position: absolute; left: 0; right: 0; background: #e6e6e6; }
.ag-leave { position: absolute; left: 0; right: 0; background: #e6e600; opacity: .85; display: flex; align-items: flex-start; justify-content: center; }
.ag-block { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(45deg, #f1f1f1, #f1f1f1 6px, #e2e2e2 6px, #e2e2e2 12px); display: flex; align-items: flex-start; justify-content: center; }
.ag-leave span, .ag-block span { font-size: 12px; font-weight: 600; color: #555; margin-top: 4px; }
.ag-card { position: absolute; border: 1px solid rgba(0,0,0,.18); border-left: 4px solid #999; border-radius: 3px; padding: 1px 4px; font-size: 12px; line-height: 1.3;
  overflow: hidden; cursor: pointer; z-index: 2; box-shadow: 0 1px 1px rgba(0,0,0,.08); color: #222; }
.ag-card:hover { z-index: 4; box-shadow: 0 2px 8px rgba(0,0,0,.25); overflow: visible; min-height: fit-content; }
.ag-card .cline { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-card .ctime { font-weight: 700; margin-right: 3px; }
.ag-card .cmeta { color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-card .ccomm { color: #6b5b00; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: italic; }
.ag-card .ctag { color: #2a6fa0; font-weight: 600; }
.ag-card.compact { font-size: 11px; padding-top: 0; }
.ag-card.st-cancelled { text-decoration: line-through; opacity: .7; }
.ag-card i { margin-right: 2px; }
.ic-ok { color: #00a65a; } .ic-q { color: #b8860b; } .ic-dep { color: #2e7d4f; } .ic-warn { color: #dd4b39; }
.tagnew { display: inline-block; font-size: 10px; font-weight: 700; background: #f39c12; color: #fff; border-radius: 3px; padding: 0 3px; margin-right: 2px; }
.ag-now { position: absolute; left: 52px; right: 0; height: 2px; background: #dd4b39; z-index: 3; pointer-events: none; }
.ag-now::before { content: ''; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: #dd4b39; }
.hist-row { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
@media (max-width: 767px) { .ag-col { flex-basis: 130px; min-width: 130px; } .agenda-wrap { margin: 0; } }

/* ── Agenda editing (step 3) ───────────────────────────────────────────── */
.practice-bar { margin: 0 15px 8px; padding: 8px 12px; background: #f3eefe; border: 1px dashed #8e7cc3; border-radius: 3px; font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ag-card.practice { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.55) 0 6px, rgba(255,255,255,0) 6px 12px) !important; outline: 1px dashed #605ca8; }
.ag-card.practice .cline::after { content: 'PRACTICE'; margin-left: 4px; font-size: 9px; font-weight: 700; color: #605ca8; letter-spacing: .5px; }
.ag-card.editable { cursor: grab; touch-action: none; } /* a touch drag moves the card, not the page */
.ag-card.dragging { opacity: .35; }
.ag-card.ghost { opacity: .9; z-index: 9; box-shadow: 0 6px 16px rgba(0,0,0,.35); pointer-events: none; }
body.no-select, body.no-select * { user-select: none !important; cursor: grabbing !important; }
.ag-body { cursor: default; }
.ag-card .creason { font-size: 11px; color: #555; }
.ag-card .card-tools { display: none; position: absolute; top: 1px; right: 1px; background: rgba(255,255,255,.95); border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.ag-card:hover .card-tools { display: flex; }
.card-tools button { border: 0; background: none; padding: 2px 5px; cursor: pointer; color: #444; font-size: 12px; }
.card-tools button:hover { background: #e8f3fb; color: var(--blue); }
.resize-handle { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; cursor: ns-resize; }
.ag-card:hover .resize-handle { background: linear-gradient(transparent, rgba(0,0,0,.15)); }
.clash-list { margin: 4px 0; padding-left: 18px; }
.clash-list li { margin: 2px 0; list-style: none; margin-left: -18px; }
.clash-list i { color: #c87f0a; margin-right: 4px; }
.search-wrap { position: relative; } .search-wrap i { position: absolute; left: 11px; top: 10px; color: #aaa; } .search-wrap input { padding-left: 32px; }
.pat-results { border: 1px solid #e3e3e3; border-top: 0; max-height: 220px; overflow-y: auto; }
.pat-row { padding: 7px 10px; cursor: pointer; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.pat-row:hover { background: #e8f3fb; }
.pat-chosen { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: #eaf7ef; border-radius: 3px; flex-wrap: wrap; }
.len-other { width: 80px; display: inline-block; height: 28px; padding: 2px 8px; }
.slot-finder { margin: -4px 0 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.status-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

/* ── Step 4: week view, time off, doctors & hours ──────────────────────── */
.ag-head a[data-day] { color: inherit; cursor: pointer; text-decoration: underline dotted; }
.ag-head.today { box-shadow: inset 0 -3px 0 #dd4b39; }
.ag-block.to-edit, .ag-leave.to-edit { cursor: pointer; z-index: 1; }
.ag-block.to-edit:hover, .ag-leave.to-edit:hover { outline: 2px solid #605ca8; }
.ag-block.practice, .ag-leave.practice { outline: 1px dashed #605ca8; }
.color-in { width: 42px; height: 28px; padding: 0; border: 1px solid #ccc; background: none; cursor: pointer; }
.hours-line { display: grid; grid-template-columns: 44px 120px 12px 120px auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.hours-line .wd { font-weight: 700; }
tr.muted td { color: #999; }

/* ── Step 5: summary bar + close the day ───────────────────────────────── */
.summary-bar { margin: 0 15px 8px; padding: 7px 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.1); display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; font-size: 13px; }
.summary-bar .spacer { flex: 1; }
.sum-main { margin-right: 4px; }
.sum-chip { border-radius: 10px; padding: 1px 8px; background: #f4f4f4; white-space: nowrap; }
.sum-chip.ok { background: #e3f6ea; color: #1e6b3d; } .sum-chip.q { background: #f6f3c8; color: #6b6200; } .sum-chip.arr { background: #fdebd0; color: #8a5300; }
.sum-chip.chair { background: #ece6ff; color: #4b3f99; } .sum-chip.done { background: #dff7df; color: #1e6b1e; } .sum-chip.miss { background: #fde3e0; color: #a12b1d; } .sum-chip.canc { background: #eee; color: #777; }
.sum-recep { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.sum-recep a { cursor: pointer; }
.sum-next { cursor: pointer; white-space: nowrap; }
.warn-text { color: #a12b1d; }
.sum-past { color: #a12b1d; cursor: pointer; white-space: nowrap; }
.close-sec { margin-bottom: 14px; }
.close-head { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 2px solid var(--line); }
.close-head .btn { margin-left: auto; }

/* Sidebar: Agenda sub-menu */
.sidebar-menu > li { position: relative; }
.sidebar-sub { list-style: none; margin: 0; padding: 4px 0; background: #2c3b41; display: none; }
.sidebar-menu > li.active > .sidebar-sub { display: block; }
.sidebar-sub a { display: block; padding: 7px 15px 7px 48px; color: #8aa4af; font-size: 13px; }
.sidebar-sub a:hover, .sidebar-sub li.active a { color: #fff; }
.sidebar-sub li.active a { font-weight: 600; }
@media (min-width: 768px) {
  body.sidebar-collapse .sidebar-menu > li.active > .sidebar-sub { display: none; }
  body.sidebar-collapse .sidebar-menu > li:hover > .sidebar-sub { display: block; position: absolute; left: 50px; top: 0; width: 170px; z-index: 50; box-shadow: 2px 2px 6px rgba(0,0,0,.3); }
  body.sidebar-collapse .sidebar-sub a { padding-left: 15px; }
}
/* Chairs view: cards in the doctor's colour */
.ag-card.by-doc.on-dark, .ag-card.by-doc.on-dark .cmeta, .ag-card.by-doc.on-dark .ccomm, .ag-card.by-doc.on-dark .creason, .ag-card.by-doc.on-dark .ctag, .ag-card.by-doc.on-dark .ctime { color: #fff; }
/* a long list of doctors must not widen the column */
.ag-col { min-width: 150px; width: 0; }
.ag-head { display: flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; min-width: 0; }
.ag-who { flex: 0 1 auto; min-width: 0; font-weight: 400; font-size: 11px; opacity: .9; overflow: hidden; text-overflow: ellipsis; }
.ag-card.by-doc.on-dark .ic-ok, .ag-card.by-doc.on-dark .ic-q, .ag-card.by-doc.on-dark .ic-warn, .ag-card.by-doc.on-dark .ic-dep { color: #fff; }
/* Monthly */
.mon-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.mon-head { background: var(--green); color: #fff; text-align: center; padding: 7px 4px; font-weight: 600; font-size: 13px; }
.mon-cell { background: #fff; min-height: 104px; padding: 7px 9px; display: flex; flex-direction: column; gap: 2px; color: inherit; }
a.mon-cell:hover { background: #fdf6e7; }
.mon-cell.blank { background: #f4f5f7; }
.mon-cell.past { background: #fafafa; }
.mon-cell.today { box-shadow: inset 0 0 0 2px var(--header); }
.mon-day { font-size: 19px; line-height: 1.2; }
.mon-booked { font-size: 13px; }
.mon-unconf { font-size: 12px; color: #b26a00; }
.mon-bar { height: 6px; background: #eceff1; border-radius: 3px; overflow: hidden; margin-top: auto; }
.mon-bar i { display: block; height: 100%; }
.mon-bar i.high { background: var(--green); } .mon-bar i.mid { background: var(--blue); } .mon-bar i.low { background: var(--orange); }
.mon-pct { font-size: 12px; font-weight: 600; }
.mon-pct.high { color: #008d4c; } .mon-pct.mid { color: #2e6da4; } .mon-pct.low { color: #b26a00; }
@media (max-width: 767px) { .mon-cell { min-height: 74px; padding: 4px; } .mon-head { font-size: 11px; } .mon-unconf { display: none; } }
/* List */
.list-status { padding: 0 12px 10px; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: #fdf6e7; border-top: 1px solid var(--line); }
.list-table td { vertical-align: top; }
.list-table tbody tr[data-id] { cursor: pointer; }
.list-table .tick { width: 30px; cursor: default; }
.list-table thead th { position: sticky; top: 0; background: #fff; z-index: 3; box-shadow: inset 0 -1px 0 var(--line); }
.list-table .row-cancelled td { color: #888; }
.list-comment { max-width: 280px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.list-cont { min-width: 170px; }
.ct { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 3px; color: #fff; margin: 0 2px 2px 0; white-space: nowrap; }
.ct.ok { background: var(--blue); } .ct.lost { background: var(--red); } .ct.next { background: var(--green); } .ct.none { background: #e9ecef; color: #555; }

.note-edited { font-size: 12px; color: #b26a00; font-style: italic; }

/* Patients reports */
.report-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 15px; }
.report-tiles .info-box { min-height: 60px; }
.report-tiles .info-box-icon { width: 54px; font-size: 22px; }
.report-tiles .info-box-text { font-size: 12px; }
.quick-acts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }

.list-info { max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-email { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Prescriptions */
.rx-card { border: 1px solid var(--line); border-radius: 3px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.rx-card.voided { background: #f9f9f9; }
.rx-card.voided .rx-diag, .rx-card.voided .rx-items { text-decoration: line-through; color: #888; }
.rx-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.rx-head .tools { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.rx-diag { margin-top: 6px; font-weight: 600; }
.rx-items { margin: 6px 0; padding-left: 18px; }
.rx-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 8px; }
.rx-row .form-group { margin-bottom: 4px; }
.rx-name, .rx-how { flex: 1 1 210px; min-width: 0; }
.rx-sm { flex: 0 1 100px; min-width: 0; }
.rx-xs { flex: 0 1 80px; min-width: 0; }
.rx-del { margin-bottom: 4px; }
/* Shifts */
.sh-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.sh-bar .tools { margin-left: auto; }
.sh-grid th, .sh-grid td { vertical-align: top; min-width: 104px; }
.sh-grid tbody th { font-weight: 600; white-space: nowrap; }
.sh-grid .today { background: #fff8e6; }
.sh-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.sh-item { display: block; width: 100%; border: 1px solid #b7d7c4; background: #e8f5ee; border-radius: 3px; padding: 3px 5px; margin-bottom: 3px; text-align: left; font-size: 12px; cursor: pointer; }
.sh-item span { display: block; color: #555; font-size: 11px; }
.sh-item.ro { background: #f1f3f5; border-color: #d8dde2; }
.sh-item.pr { border-style: dashed; }
.sh-warn { color: var(--red); font-size: 11px; font-weight: 600; margin-bottom: 3px; }
.sh-add { display: block; width: 100%; border: 1px dashed transparent; background: none; color: #aaa; font-size: 11px; padding: 2px; cursor: pointer; }
.sh-grid td:hover .sh-add, .sh-add:focus { border-color: #ccc; color: #666; }
.sh-days { display: flex; flex-wrap: wrap; gap: 10px; }
#printArea { display: none; }
@media print {
  @page { size: A4; margin: 16mm; }
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing { background: #fff; }
  body.printing #printArea { display: block; color: #000; font-size: 14px; }
  .px-logo { display: block; max-width: 100%; max-height: 130px; margin-bottom: 10px; }
  .px-void { border: 2px solid #000; text-align: center; font-weight: 700; font-size: 18px; padding: 6px; margin-bottom: 14px; }
  .px-top { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 10px; }
  .px-clinic { font-size: 19px; font-weight: 700; }
  .px-no { text-align: right; }
  .px-pat { margin: 16px 0; }
  .px-pat div { display: flex; gap: 10px; padding: 2px 0; }
  .px-pat span { width: 110px; flex: none; }
  .px-items { margin: 18px 0; padding-left: 22px; }
  .px-items li { margin-bottom: 12px; }
  .px-info { margin-top: 12px; white-space: pre-wrap; }
  .px-sign { margin-top: 70px; display: flex; justify-content: flex-end; flex-direction: column; align-items: flex-end; }
  .px-line { border-top: 1px solid #000; margin-top: 44px; padding-top: 4px; width: 240px; text-align: center; }
}
