/* Naseem e-Consent — tablet-first clinical UI.
   State colours carry meaning everywhere:
   teal = master information, amber = the consent being filled now, slate hatch = archived, red = void. */
:root {
  --ink: #16323a;
  --ink-2: #4a6469;
  --teal: #0e7c7b;
  --teal-wash: #e7f2f1;
  --paper: #fbfcfc;
  --line: #c9d8da;
  --amber: #a86412;
  --amber-wash: #fbf1e1;
  --slate: #62777c;
  --slate-wash: #eef2f3;
  --red: #b42318;
  --red-wash: #fdecea;
  --ok: #1d7a46;
  --radius: 6px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper); line-height: 1.5; }
a { color: var(--teal); }
:focus-visible { outline: 3px solid #f0b429; outline-offset: 2px; }

/* ---------- chrome ---------- */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--ink); color: #fff; }
.topbar .brand { font-weight: 600; letter-spacing: .01em; color: #fff; text-decoration: none; }
.topbar .brand small { font-weight: 400; opacity: .7; margin-inline-start: .4rem; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: #cfe6e5; text-decoration: none; padding: .25rem 0; border-bottom: 2px solid transparent; }
.topbar nav a:hover, .topbar nav a[aria-current] { color: #fff; border-color: #6cc3c1; }
.topbar .who { font-size: .85rem; color: #cfe6e5; display: flex; align-items: center; gap: .75rem; }
.topbar .who form { margin: 0; }
.topbar .who button { background: none; border: 1px solid #5d7c83; color: #fff; padding: .2rem .6rem; border-radius: var(--radius); cursor: pointer; font: inherit; }

main { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
h1 { font-size: 1.6rem; font-weight: 600; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 0 0 .75rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 0; }
.sub { color: var(--ink-2); margin: 0 0 1.5rem; }
.muted { color: var(--ink-2); font-size: .875rem; }
.ar { direction: rtl; text-align: right; font-size: 1rem; }

/* ---------- flash & errors ---------- */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; border-inline-start: 4px solid; }
.flash.ok { background: #e8f5ee; border-color: var(--ok); }
.flash.warn { background: var(--amber-wash); border-color: var(--amber); }
.errors { background: var(--red-wash); border-inline-start: 4px solid var(--red); padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; }
.errors ul { margin: .25rem 0 0; padding-inline-start: 1.25rem; }

/* ---------- forms ---------- */
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .25rem; }
label .ar-l { font-weight: 400; color: var(--ink-2); margin-inline-start: .35rem; }
input[type=text], input[type=date], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: .6rem .7rem; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; min-height: 44px;
}
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 3px rgba(14,124,123,.18); }
.row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 1rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--teal); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1.1rem;
  font: inherit; font-weight: 500; border-radius: var(--radius); border: 1px solid var(--teal); background: #fff; color: var(--teal);
  cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--teal-wash); }
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:hover { background: #0a6564; }
.btn.finalize { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red-wash); }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .875rem; }
.btn[disabled] { opacity: .5; cursor: wait; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }

/* ---------- panels by state ---------- */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.panel.master { border-inline-start: 5px solid var(--teal); }
.panel.current { border-inline-start: 5px solid var(--amber); }
.panel.archived { border-inline-start: 5px solid var(--slate); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; white-space: nowrap; }
.tag.master { background: var(--teal-wash); color: var(--teal); }
.tag.draft { background: var(--amber-wash); color: var(--amber); }
.tag.finalized { background: var(--slate-wash); color: var(--slate); }
.tag.void { background: var(--red-wash); color: var(--red); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .5rem 1.25rem; margin: 0; }
.facts dt { font-size: .75rem; color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 500; }

/* The status band is the signature element: you always know what you're looking at. */
.state-band { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1.5rem; align-items: center;
  padding: .85rem 1.25rem; border-radius: var(--radius); margin-bottom: 1.25rem; font-weight: 500; }
.state-band.draft { background: var(--amber-wash); color: #6b3f07; }
.state-band.finalized { color: #fff; background: repeating-linear-gradient(135deg, #5b6f74 0 14px, #62777c 14px 28px); }
.state-band.void { background: var(--red); color: #fff; }
.state-band .no { font-size: 1.2rem; font-weight: 600; letter-spacing: .02em; }
.state-band .meta { font-size: .875rem; opacity: .92; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th { text-align: start; font-size: .8rem; font-weight: 600; color: var(--ink-2); padding: .5rem .75rem; border-bottom: 2px solid var(--line); }
table.list td:first-child { white-space: nowrap; }
table.list td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.void td { color: var(--ink-2); text-decoration: line-through; text-decoration-color: rgba(180,35,24,.4); }
table.list tr.void td:last-child, table.list tr.void td .tag { text-decoration: none; }

/* ---------- consent sections ---------- */
.sec { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .9rem; }
.sec-head { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; }
.sec-num { flex: 0 0 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; font-weight: 600;
  background: var(--slate-wash); color: var(--slate); }
.sec-title { flex: 1; }
.sec-title .ar { font-size: .9rem; color: var(--ink-2); display: block; text-align: left; }
.sec-body { padding: 0 1rem 1rem; }
.sec-text { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; font-size: .92rem; color: #28464e; margin-bottom: 1rem; }
.sec-text p { margin: 0; }
.sec.off .sec-body { display: none; }
.sec.off { background: transparent; border-style: dashed; }
.sec.off .sec-title { color: var(--ink-2); }
.sec.on { border-inline-start: 5px solid var(--amber); }
.sec.on .sec-num { background: var(--amber); color: #fff; }
.sec.master-sec { border-inline-start: 5px solid var(--teal); }
.sec.master-sec .sec-num { background: var(--teal); color: #fff; }
.req-note { font-size: .78rem; color: var(--amber); font-weight: 500; }
.initials input { max-width: 140px; text-transform: uppercase; text-align: center; letter-spacing: .1em; }

.works { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .5rem; }
.works label { border: 1px solid var(--line); border-radius: var(--radius); padding: .55rem .7rem; background: #fff; margin: 0; }
.works label:has(input:checked) { border-color: var(--teal); background: var(--teal-wash); }
.works .ar { font-size: .85rem; color: var(--ink-2); display: block; text-align: left; }

/* ---------- signature pads ---------- */
.sig-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }
.pad { border: 2px dashed var(--line); border-radius: var(--radius); background: #fff; position: relative; }
.pad canvas { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }
.pad::after { content: "Sign here"; position: absolute; left: 1rem; bottom: .5rem; font-size: .75rem; color: #9fb3b6; pointer-events: none; }
.pad.signed { border-style: solid; border-color: var(--teal); }
.pad.signed::after { content: ""; }
.pad.small canvas { height: 130px; }
.sec-sign { margin-top: .5rem; max-width: 560px; }
.pad-tools { display: flex; justify-content: space-between; align-items: center; margin-top: .35rem; }
.sig-img { max-height: 90px; max-width: 100%; }
.seal-img { max-height: 90px; }

/* ---------- archive view ---------- */
.readonly .sec { border-inline-start: 5px solid var(--slate); }
.answer { background: var(--slate-wash); border-radius: var(--radius); padding: .5rem .75rem; font-size: .9rem; margin-top: .5rem; }
.answer b { font-weight: 600; }

/* ---------- misc ---------- */
.narrow { max-width: 440px; margin: 3rem auto; }
.hash { font-family: ui-monospace, Consolas, monospace; font-size: .75rem; word-break: break-all; color: var(--ink-2); }
.ok-text { color: var(--ok); font-weight: 600; }
.bad-text { color: var(--red); font-weight: 600; }
details summary { cursor: pointer; font-weight: 500; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(251,252,252,.96); border-top: 1px solid var(--line);
  padding: .9rem 0; margin-top: 1.5rem; z-index: 5; }

dialog { border: none; border-radius: var(--radius); padding: 1.5rem; max-width: 480px; box-shadow: 0 12px 40px rgba(22,50,58,.3); }
dialog::backdrop { background: rgba(22,50,58,.45); }

@media (max-width: 720px) {
  .sec-text { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; }
  main { padding: 1rem .85rem 4rem; }
}
@media print {
  .topbar, .actions, .sticky-actions, .no-print { display: none !important; }
  .state-band.finalized { color: var(--ink); background: none; border: 2px solid var(--slate); }
}
