/* web/app.css — staff pages. Restyled to match www.essnutriments.co.za. */
@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800;900&display=swap");

:root {
  --ink: #46423C; --ink-strong: #3A3733; --muted: #A6A39B; --muted-dark: #6A665E;
  --line: #C9C4BB; --line-soft: #E6E2D9; --field: #ADA89E;
  --cream: #EDE9E1; --cream-light: #FBFAF7; --white: #FFFFFF;
  --green: #4E8C3F; --green-ink: #3F7A32; --green-wash: #EAF4E4; --green-line: #C7E0BA;
  --orange: #F2A03D;
  --danger: #B42318; --danger-wash: #FEF3F2; --danger-line: #F4C7C3;
  --warn-bg: #FFF6E0; --warn-line: #F2C66D; --warn-ink: #5A4212;
  --radius: 12px; --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(58,55,51,.04), 0 6px 20px rgba(58,55,51,.05);
  --ring: 0 0 0 3px rgba(78,140,63,.22);
  /* Legacy names: prescription.html uses var(--grey) inline; .fibre uses --blue; --bg kept for anything else. */
  --grey: var(--muted-dark); --bg: var(--cream-light); --blue: #0B7FAB;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 47 40'%3E%3Cpolygon fill='%237BB86A' points='23.5,1 33,6.5 33,17.5 23.5,23 14,17.5 14,6.5'/%3E%3Cpolygon fill='%23F2A03D' points='10.5,17 20,22.5 20,33.5 10.5,39 1,33.5 1,22.5'/%3E%3Cpolygon fill='%23E8746C' points='36.5,17 46,22.5 46,33.5 36.5,39 27,33.5 27,22.5'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 400 15px/1.5 "Nunito", system-ui, sans-serif; color: var(--ink); background: var(--cream-light); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { color: var(--ink-strong); letter-spacing: -.02em; }
h2 { font-size: 24px; font-weight: 900; line-height: 1.2; margin: 0 0 16px; }
a { color: var(--green-ink); font-weight: 700; text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid rgba(242,160,61,.6); outline-offset: 2px; }

/* ---- Header (built by nav.js) ---- */
header { display: flex; align-items: center; gap: 20px; padding: 12px 32px; background: var(--white); border-bottom: 2px solid var(--orange); }
header h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 900; display: flex; align-items: center; gap: 12px; }
header h1::before, .login h1::before { content: ""; width: 36px; height: 31px; flex: none; background: var(--mark) center / contain no-repeat; }
header nav.links { display: flex; gap: 4px; }
header nav.links a { color: var(--ink-strong); font-weight: 700; font-size: 14px; padding: 9px 16px; border-radius: 999px; text-decoration: none; }
header nav.links a:hover { background: var(--cream); }
header nav.links a.active { background: var(--green); color: var(--white); }
header #who { font-size: 13px; color: var(--muted-dark); }
header button { font: inherit; font-size: 13px; font-weight: 700; color: var(--ink-strong); background: var(--white); border: 1.5px solid var(--line); border-radius: 999px; padding: 7px 14px; cursor: pointer; }
header button:hover { border-color: var(--muted-dark); }

/* ---- Layout ---- */
.page { padding: 24px 32px 48px; }
main { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.2fr); gap: 20px; padding: 20px 32px 48px; align-items: start; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  header { flex-wrap: wrap; gap: 10px 16px; padding: 12px 16px; }
  header h1 { flex-basis: 100%; }
  .page, main { padding-left: 16px; padding-right: 16px; }
  nav.tabs { padding-left: 16px; padding-right: 16px; overflow-x: auto; }
}

/* ---- Library tabs ---- */
nav.tabs { display: flex; gap: 4px; padding: 14px 32px 0; background: var(--white); border-bottom: 1px solid var(--line-soft); }
nav.tabs button { font: inherit; font-size: 14px; font-weight: 700; color: var(--muted-dark); border: none; background: none; padding: 10px 14px 12px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
nav.tabs button:hover { color: var(--ink-strong); }
nav.tabs button.active { color: var(--ink-strong); border-bottom-color: var(--green); }
nav.tabs .badge { background: var(--green-wash); color: var(--green-ink); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 800; margin-left: 6px; }
nav.tabs .badge:empty { display: none; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 16px; font: inherit; font-size: 14px; font-weight: 700; line-height: 1.2; color: var(--ink-strong); background: var(--white); border: 1.5px solid var(--line); border-radius: 999px; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--muted-dark); background: var(--cream-light); text-decoration: none; }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--white); font-weight: 800; }
.btn.primary:hover { background: var(--green-ink); border-color: var(--green-ink); }
.btn.danger { color: var(--danger); margin-left: auto; }
.btn.danger:hover { background: var(--danger-wash); border-color: var(--danger-line); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Fields ---- */
.form input, .form select, .form textarea,
.panel input, .panel select, .panel textarea,
.filters input, .filters select,
.login input, dialog input, dialog textarea, dialog select,
.plan textarea, .plan input[type=text], .plan select {
  font: inherit; font-size: 14.5px; font-weight: 500; color: var(--ink); background: var(--white);
  padding: 9px 12px; border: 1.5px solid var(--field); border-radius: 10px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green) !important; box-shadow: var(--ring); }
input[type=checkbox], input[type=radio] { width: auto !important; min-height: 0; margin: 0; accent-color: var(--green); inline-size: 17px; block-size: 17px; flex: none; }
textarea { line-height: 1.5; resize: vertical; }
input[readonly] { background: var(--cream-light); }

/* Staff forms (new patient, prescription, intake edit, plan cover) */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px 18px; max-width: 1100px; }
.form label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted-dark); }
.form input, .form select, .form textarea { width: 100%; margin-top: 6px; }
.form label:has(> input[type=checkbox]) { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: var(--ink); align-self: end; min-height: 42px; }
.form label:has(> input[type=checkbox]) > input { margin-top: 0; }
.form .wide { grid-column: 1 / -1; }
.form > .wide:last-child { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.form fieldset { grid-column: 1 / -1; border: 1px solid var(--line-soft); border-radius: var(--radius-lg); padding: 12px 18px 16px; margin: 0; background: var(--white); }
.form legend { padding: 0 6px; font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-dark); }
.form fieldset label { margin-top: 10px; }
.form fieldset label:has(> input[type=checkbox]), .form fieldset label:has(> input[type=radio]) { display: inline-flex; min-height: 0; margin: 6px 20px 6px 0; }
.form fieldset .form { margin-top: 6px; }

/* Green derived-numbers bar (prescription) */
.derived { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 14px 18px; background: var(--green-wash); border: 1px solid var(--green-line); border-radius: var(--radius-lg); font-size: 14px; color: #2E4527; }
.derived:empty { display: none; }
.derived b { color: var(--green-ink); font-weight: 800; }
.derived .btn { min-height: 30px; padding: 4px 12px; font-size: 13px; }

/* ---- Tables ---- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.filters input[type=search] { flex: 1; min-width: 180px; }
table.list { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; background: var(--white); border: 1px solid var(--line-soft); border-radius: var(--radius-lg); overflow: hidden; }
table.list th { text-align: left; padding: 11px 14px; background: var(--cream-light); border-bottom: 1px solid var(--line-soft); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted-dark); }
table.list td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.list tbody tr:last-child td { border-bottom: none; }
table.list tr { cursor: pointer; }
table.list tbody tr:hover td { background: #F7F5F0; }
table.list tr.selected td { background: var(--green-wash); }
table.list td:last-child { white-space: nowrap; }
table.list .btn { min-height: 32px; padding: 5px 12px; font-size: 13px; }
.ok { color: var(--green-ink); font-weight: 800; }
span.ok { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--green-wash); font-size: 12.5px; }
.fibre { color: var(--blue); }

/* ---- Cards, plan editor ---- */
.plan { display: grid; grid-template-columns: 1fr; gap: 20px; max-width: 1200px; }
.card, .plan section.card, .page section.card { border: 1px solid var(--line-soft); border-radius: var(--radius-lg); padding: 18px 22px 20px; background: var(--white); box-shadow: var(--shadow); }
.plan section.card h3, .page section.card h3 { margin: 0 0 12px; font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-dark); }
.card h3 .muted { letter-spacing: 0; text-transform: none; font-weight: 600; }
.plan textarea { width: 100%; min-height: 90px; }
.plan textarea.lines, .panel textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.plan textarea.lines { min-height: 90px; }
.plan input[type=text] { width: 100%; }
.plan section.card > label { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 14px; font-weight: 600; }
.plan section.card > label.wide { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted-dark); margin-top: 14px; }
.plan section.card > label.wide textarea { margin-top: 6px; }
.plan .row { display: flex; gap: 8px; align-items: center; }
.plan [data-part="tables"] > .row { padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.blocks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.block { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px; background: var(--cream-light); }
.block .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.block .row input { flex: 1; font-weight: 700; }
.block .btn.danger, .section-item .btn.danger, [data-part="tables"] .btn.danger { min-height: 34px; padding: 4px 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; position: sticky; top: 0; z-index: 5; margin-bottom: 20px; padding: 12px 0; background: rgba(251,250,247,.94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line-soft); }
.toolbar h2 { font-size: 22px; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--radius-lg); padding: 12px 16px; font-size: 14px; line-height: 1.55; color: var(--warn-ink); }
.warn b { color: #7A4E07; }
.section-item { border-top: 1px dashed var(--line); padding-top: 12px; margin-top: 12px; }
.section-item .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.section-item .row select { width: auto; }
.section-item .row input { flex: 1; font-weight: 700; }

/* ---- Library side panel ---- */
.panel { border: 1px solid var(--line-soft); border-radius: var(--radius-lg); padding: 20px 22px; background: var(--white); box-shadow: var(--shadow); position: sticky; top: 16px; }
.panel label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted-dark); margin-top: 12px; }
.panel label:first-child { margin-top: 0; }
.panel input, .panel select, .panel textarea { width: 100%; margin-top: 6px; }
.panel label:has(> input[type=checkbox]) { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink); }
.panel label:has(> input[type=checkbox]) > input { margin-top: 0; }
.panel textarea { min-height: 140px; }
.panel .actions, dialog .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ---- Text states ---- */
.muted { color: var(--muted-dark); font-size: 12.5px; font-weight: 500; }
.status { font-size: 13px; color: var(--muted-dark); margin-top: 8px; min-height: 18px; }
.error { color: var(--danger); font-size: 13.5px; font-weight: 700; margin-top: 10px; }

/* ---- Sign-in ---- */
.login { max-width: 400px; margin: 10vh auto 40px; padding: 32px 32px 28px; background: var(--white); border: 1px solid var(--line-soft); border-radius: 20px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 24px; font-weight: 900; display: flex; align-items: center; gap: 12px; }
.login p { margin: 0 0 8px; color: var(--muted-dark); font-size: 14px; }
.login label { display: block; margin-top: 16px; font-size: 12.5px; font-weight: 700; color: var(--muted-dark); }
.login input { width: 100%; margin-top: 6px; padding: 11px 14px; font-size: 15px; }
.login .btn { width: 100%; margin-top: 22px; min-height: 46px; font-size: 15px; }

/* ---- Dialogs (invite, library picker) ---- */
dialog { border: none; border-radius: 20px; padding: 24px 28px; max-width: 560px; width: 90%; color: var(--ink); box-shadow: 0 24px 60px rgba(46,44,41,.28); }
dialog::backdrop { background: rgba(46,44,41,.45); }
dialog h3 { margin: 0 0 6px; font-size: 19px; font-weight: 900; }
dialog label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted-dark); margin-top: 10px; }
dialog input, dialog textarea { width: 100%; margin: 6px 0 8px; }
dialog select[size] { padding: 6px; }

/* ---- Intake summary / patient details ---- */
.summary { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; font-size: 14px; margin: 0; }
.summary dt { font-weight: 700; color: var(--muted-dark); }
.summary dd { margin: 0; white-space: pre-line; color: var(--ink); }
.summary dd.muted { font-size: 14px; font-style: italic; }
@media (max-width: 600px) { .summary { grid-template-columns: 1fr; gap: 2px; } .summary dd { margin-bottom: 8px; } }
