/* New Techs Lab — interface styles.
 *
 * Written for a clinic, not a showcase. Priorities, in order:
 *   1. A specialist can enter a value without hunting for the field.
 *   2. Status is legible at a glance, in words as well as colour.
 *   3. It works on a phone at the bench, not only on the desk.
 *
 * Colour is never the only carrier of meaning: every status and flag also reads
 * as text, because colour-blind readers and monochrome printouts both exist.
 */

@font-face {
  font-family: 'Amiri';
  src: url('/assets/Amiri-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #f2f5f9;
  --card: #ffffff;
  --ink: #16202f;
  --ink-soft: #3d4a5e;
  --muted: #667891;
  --line: #dfe5ee;
  --line-strong: #c6d0de;

  --brand: #17578f;
  --brand-dark: #10416c;
  --brand-tint: #eaf2fa;

  --danger: #b4362a;
  --danger-tint: #fdeeec;
  --warn: #8a6100;
  --warn-tint: #fff7e6;
  --warn-line: #e6c477;
  --ok: #1d6b36;
  --ok-tint: #e9f6ed;
  --ok-line: #86c79a;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(22, 32, 47, .06), 0 4px 14px rgba(22, 32, 47, .05);
  --gap: 20px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Arabic patient names get a face that renders them properly; Latin text keeps
   the system stack so the interface still looks native. */
.arabic, .patient-name { font-family: 'Amiri', system-ui, sans-serif; }
.patient-name { font-size: 1.06em; }

a { color: var(--brand); text-underline-offset: 2px; }

/* Visible focus everywhere. A lab bench is a place where people tab through
   fields fast, and keyboard users should never lose their place. */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 3px; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  background: var(--brand);
  color: #fff;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08);
}
.topbar .brand {
  font-weight: 700; color: #fff; margin-right: 14px; padding: 14px 0; letter-spacing: -.01em;
}
.topbar a {
  color: #cfe0f0; text-decoration: none; padding: 15px 12px; font-weight: 500;
  border-bottom: 3px solid transparent;
}
.topbar a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topbar a.active { color: #fff; border-bottom-color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .muted { color: #cfe0f0; font-size: 14px; padding: 0 10px; }
.topbar form { margin: 0; }
.topbar button {
  background: none; border: 1px solid rgba(255, 255, 255, .45); color: #fff;
  padding: 6px 13px; border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-size: 14px;
}
.topbar button:hover { background: rgba(255, 255, 255, .16); }

/* -------------------------------------------------------------------- layout */
.wrap { max-width: 1120px; margin: 26px auto 60px; padding: 0 20px; }
.wrap.narrow { max-width: 460px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}

h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 24px 0 12px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); }

/* -------------------------------------------------------------------- forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--ink-soft); }

input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input::placeholder { color: #9aa7ba; }
input[readonly], select[disabled] {
  background: #f4f6fa; color: var(--muted); cursor: default; border-color: var(--line);
}
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 170px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--brand); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--brand-tint); border-color: var(--brand); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #93291f; }
.btn.small { padding: 5px 11px; font-size: 13px; }

/* ------------------------------------------------------------------- tables */
.table-scroll { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; border-bottom-color: var(--line-strong);
}
tbody tr:hover { background: #f8fafd; }
tbody tr:last-child td { border-bottom: none; }

/* ------------------------------------------------------------------ notices */
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px;
  border: 1px solid; font-weight: 500;
}
.flash.success { background: var(--ok-tint); border-color: var(--ok-line); color: var(--ok); }
.flash.error   { background: var(--danger-tint); border-color: #e5a89f; color: var(--danger); }

.notice {
  background: var(--warn-tint); border: 1px solid var(--warn-line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: var(--gap);
}
.notice h3 { color: var(--warn); }

.pill {
  display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 20px;
  background: #eef2f8; color: var(--muted); font-weight: 600;
}
.pill.warn { background: var(--warn-tint); color: var(--warn); border: 1px solid var(--warn-line); }

/* ------------------------------------------------- status and abnormal flags */
.status {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 10px; border-radius: 20px; text-transform: uppercase;
  border: 1px solid transparent; white-space: nowrap;
}
.status-filled, .status-edited, .status-queued { background: var(--warn-tint); border-color: var(--warn-line); color: var(--warn); }
.status-approved, .status-sent { background: var(--ok-tint); border-color: var(--ok-line); color: var(--ok); }
.status-rejected, .status-failed { background: var(--danger-tint); border-color: #e5a89f; color: var(--danger); }
.status-printed, .status-pending, .status-skipped { background: #eef2f8; border-color: var(--line-strong); color: var(--ink-soft); }

.flag {
  display: inline-block; margin-left: 7px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; padding: 2px 8px; border-radius: 4px; border: 1px solid;
}
.flag-high     { background: var(--danger-tint); border-color: #e5a89f; color: var(--danger); }
.flag-low      { background: #eaf1fd; border-color: #9cb6e8; color: #1a3fa3; }
.flag-abnormal { background: var(--warn-tint); border-color: var(--warn-line); color: var(--warn); }

/* ------------------------------------------------------------- patient panel */
.patient-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px 26px; }
.patient-grid span { display: block; }
.patient-grid .k {
  font-size: 11.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .05em; font-weight: 700; margin-bottom: 2px;
}
.patient-grid .v { font-weight: 600; font-size: 15px; }

/* --------------------------------------------------------------- result rows */
.test-table td:nth-child(1) { width: 40%; }
.test-table td:nth-child(2) { width: 24%; }
.test-table td:nth-child(3) { width: 36%; color: var(--muted); font-size: 13px; }
.test-table tr.package-head td { background: var(--brand-tint); font-weight: 700; color: var(--brand-dark); }
.test-table .sub-name { padding-left: 26px; }
.test-table input { padding: 8px 10px; font-weight: 600; }
.value-cell { white-space: nowrap; }
.no-range { color: var(--warn); font-style: italic; }

.quick { display: block; margin-top: 6px; white-space: normal; }
.quick-btn {
  font: inherit; font-size: 11px; font-weight: 600; padding: 3px 9px; margin: 0 4px 4px 0;
  border: 1px solid var(--line-strong); border-radius: 20px; background: #fff;
  color: var(--muted); cursor: pointer;
}
.quick-btn:hover { background: var(--brand-tint); color: var(--brand); border-color: var(--brand); }

/* ------------------------------------------------------------------ worklist */
.tabs {
  display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 18px;
  border-bottom: 1px solid var(--line-strong);
}
.tab {
  padding: 10px 16px; border-radius: var(--radius) var(--radius) 0 0; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: 14px;
  border: 1px solid transparent; border-bottom: none; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); background: #e7edf6; }
.tab.active { background: var(--card); border-color: var(--line-strong); border-bottom-color: var(--card); color: var(--ink); }
.tab-count {
  display: inline-block; margin-left: 7px; font-size: 11px; padding: 1px 7px;
  border-radius: 20px; background: var(--brand); color: #fff; font-weight: 700;
}
.overdue { color: var(--danger); font-weight: 600; }

.history-table td { font-size: 13px; }
.history-table .when { white-space: nowrap; color: var(--muted); }

/* --------------------------------------------------------------------- misc */
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 14px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* Deliberately NOT sticky. A bottom-sticky bar renders above the content that
   precedes it, which hid the last test rows. */
.save-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: var(--gap); box-shadow: var(--shadow);
}

pre {
  background: #f6f8fc; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; margin: 0; font-size: 13px;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* -------------------------------------------------------------- small screens */
@media (max-width: 720px) {
  .wrap { margin-top: 16px; padding: 0 14px; }
  .card { padding: 16px; border-radius: 8px; }
  h1 { font-size: 20px; }

  .topbar { padding: 0 14px; }
  .topbar .brand { margin-right: 8px; padding: 12px 0; }
  .topbar a { padding: 12px 9px; font-size: 14px; }

  /* Wide tables scroll inside their card rather than pushing the whole page sideways. */
  .table-scroll { margin: 0 -16px; padding: 0 16px; }
  .table-scroll table { min-width: 560px; }

  .row > * { min-width: 100%; }
  .row > .shrink { min-width: 0; }
  .test-table td:nth-child(3) { font-size: 12px; }
}

/* A notice that carries bad news, rather than a caution. */
.notice.danger { background: var(--danger-tint); border-color: #e5a89f; }
.notice.danger h3 { color: var(--danger); }
