:root {
  --side: #16202c; --side-text: #b7c0cc; --accent: #1b4f8a; --accent-dark: #143c6a;
  --bg: #f2f4f7; --line: #d5dae1; --text: #18202a; --muted: #687383;
  --red: #a4161a; --red-bg: #fdecec; --green: #23663a; --amber: #8a5a00;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* layout */
.side { width: 240px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 20px; color: #fff; font-weight: 600; font-size: 15px; line-height: 1.25; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--side-text); }
.brand.dark { color: var(--text); padding: 0 0 18px; }
.brand.dark small { color: var(--muted); }
.mark { width: 34px; height: 34px; flex: none; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 18px; border-radius: 3px; }
.side nav { display: flex; flex-direction: column; border-top: 1px solid #263242; padding-top: 8px; }
.side nav a { color: var(--side-text); padding: 9px 18px; border-left: 3px solid transparent; }
.side nav a:hover { background: #1d2938; color: #fff; text-decoration: none; }
.side nav a.on { color: #fff; background: #1f2d3e; border-left-color: #4d8fd6; }
.me { margin-top: auto; padding: 14px 18px; border-top: 1px solid #263242; font-size: 13px; }
.me b { display: block; color: #fff; font-weight: 600; }
.me span { display: block; margin-bottom: 6px; }
.me .link { color: #8fb6e3; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; gap: 12px; align-items: center; padding: 12px 28px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; }
.search { flex: 1; display: flex; max-width: 640px; }
.search input { flex: 1; border-radius: 3px 0 0 3px; }
.search button { border-radius: 0 3px 3px 0; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 0 16px; cursor: pointer; font: inherit; }
.top .btn { margin-left: auto; }
.content { padding: 24px 28px 48px; max-width: 1400px; }

/* controls */
input, select, textarea { font: inherit; color: inherit; border: 1px solid #b9c1cc; border-radius: 3px; padding: 7px 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 3px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--accent); border-color: #b9c1cc; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.wide { width: 100%; padding: 9px; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }
.danger { color: var(--red); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin-left: 10px; }

/* forms */
.card { background: #fff; border: 1px solid var(--line); border-radius: 3px; padding: 20px 22px; }
form.std { max-width: 720px; }
form.std > div:not(.actions) { margin-bottom: 14px; }
form.std label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
form.std .helptext, form.std [id$=_helptext] { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
form.std ul.errorlist { list-style: none; margin: 0 0 4px; padding: 0; color: var(--red); font-size: 13px; }
form.std ul.errorlist.nonfield { background: var(--red-bg); border: 1px solid #f0b8b8; padding: 8px 12px; margin-bottom: 14px; }
form.std div:has(> input[type=checkbox]) { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
form.std div:has(> input[type=checkbox]) label { margin: 0; order: 2; }
form.std div:has(> input[type=checkbox]) .helptext { order: 3; width: 100%; margin: 0; }
form.std .actions { padding-top: 6px; }

/* messages */
.msg { padding: 10px 14px; border: 1px solid; border-radius: 3px; margin-bottom: 16px; }
.msg.success { background: #ecf6ef; border-color: #b6dcc1; color: var(--green); }
.msg.error { background: var(--red-bg); border-color: #f0b8b8; color: var(--red); }

/* tables */
.grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); }
.grid th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f7f8fa; }
.grid th, .grid td { padding: 9px 12px; border-bottom: 1px solid #e6e9ee; vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: #f8fafc; }
.grid.compact td:not(:first-child), .grid.compact th:not(:first-child) { text-align: center; }
tr.cancelled td, tr.no_show td { color: var(--muted); }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 2px; background: #e8edf3; color: #344256; }
.tag.red { background: var(--red-bg); color: var(--red); font-weight: 600; }
.st { font-size: 12px; font-weight: 600; }
.st.scheduled { color: var(--accent); }
.st.done { color: var(--green); }
.st.no_show { color: var(--amber); }
.st.cancelled { color: var(--muted); }

/* patient */
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.head h1 { margin-bottom: 2px; }
.meta { margin: 0; color: var(--muted); }
.allergy { background: var(--red-bg); border: 1px solid #f0b8b8; border-left: 4px solid var(--red); color: var(--red); padding: 10px 14px; margin-bottom: 10px; }
.allergy.none { background: #fff; border-color: var(--line); border-left-color: #b9c1cc; color: var(--muted); }
.note { background: #fff; border: 1px solid var(--line); border-left: 4px solid #b9c1cc; padding: 10px 14px; margin-bottom: 10px; }
details.visit { background: #fff; border: 1px solid var(--line); margin-bottom: -1px; }
details.visit summary { padding: 9px 12px; cursor: pointer; }
details.visit[open] summary { border-bottom: 1px solid #e6e9ee; background: #f7f8fa; }
details.visit dl { margin: 0; padding: 6px 14px 0; display: grid; grid-template-columns: 170px 1fr; gap: 4px 14px; }
details.visit dt { font-weight: 600; color: var(--muted); }
details.visit dd { margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; white-space: nowrap; padding: 8px 14px 10px; font-size: 13px; }
details.add { margin-top: 12px; }
details.add summary { list-style: none; }
details.add summary::-webkit-details-marker { display: none; }
details.add form { margin-top: 10px; }

/* visit */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 440px); gap: 24px; align-items: start; }
.split form.std { max-width: none; }
.split aside h2:first-child { margin-top: 0; }
.split aside details.visit dl { grid-template-columns: 1fr; }
.doc { background: #fff; border: 1px solid var(--line); padding: 8px 12px; margin-bottom: -1px; }

/* schedule */
.daynav { display: flex; gap: 6px; align-items: center; }
.daynav input { width: auto; }
.cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; align-items: start; }
.col { background: #fff; border: 1px solid var(--line); }
.col-head { padding: 10px 12px; border-bottom: 2px solid var(--accent); }
.col-head span { display: block; color: var(--muted); font-size: 12px; }
.col > .muted { padding: 10px 12px; margin: 0; }
.slot { padding: 9px 12px; border-bottom: 1px solid #e6e9ee; border-left: 3px solid var(--accent); }
.slot.done { border-left-color: var(--green); }
.slot.no_show { border-left-color: var(--amber); }
.slot .time { font-weight: 600; display: flex; justify-content: space-between; }
.slot .row-actions { padding: 4px 0 0; }

/* help */
.help { max-width: 860px; }
.help h2:first-of-type { margin-top: 18px; }
.help li { margin-bottom: 4px; }
.toc { display: flex; flex-wrap: wrap; gap: 6px 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }

/* login */
body.login { align-items: center; justify-content: center; background: var(--side); }
.login-box { width: 380px; background: #fff; padding: 30px 32px; border-radius: 3px; }
.login-box h1 { font-size: 18px; border-top: 1px solid var(--line); padding-top: 18px; }
.login-box .hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }

/* print */
body.print { display: block; background: #fff; }
.noprint { padding: 12px; text-align: center; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet { max-width: 720px; margin: 0 auto; padding: 32px 24px; font-size: 14px; }
.sheet header { border-bottom: 2px solid var(--text); padding-bottom: 10px; margin-bottom: 22px; }
.sheet h1 { text-align: center; font-size: 18px; text-transform: uppercase; letter-spacing: .05em; }
.sheet .info { border-collapse: collapse; margin-bottom: 14px; }
.sheet .info th { text-align: left; font-weight: 400; color: var(--muted); padding: 2px 24px 2px 0; }
.sheet h3 { font-size: 14px; margin: 16px 0 4px; }
.sheet p { margin: 0; }
.sign { margin-top: 48px; text-align: right; }
@media print {
  .noprint { display: none; }
  .sheet { padding: 0; max-width: none; }
  @page { margin: 18mm; }
}

@media (max-width: 900px) {
  body { flex-direction: column; }
  .side { width: auto; height: auto; position: static; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .split { grid-template-columns: 1fr; }
  .top, .content { padding-left: 14px; padding-right: 14px; }
}
