/*
 * eSignup — mobile first. Phones are the base layout; wider screens add columns and the admin sidebar.
 * Tenant colours come from the data-theme attribute on <body> (see Tenant).
 */

:root {
  --primary: #2b26ed;
  --primary-ink: #ffffff;
  --accent: #3fa9f5;
  --ink: #1b1f2a;
  --muted: #5d6677;
  --line: #dde1e9;
  --surface: #ffffff;
  --page: #f3f5f9;
  --ok: #1a7f37;
  --ok-bg: #e7f6ec;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --bad: #b3261e;
  --bad-bg: #fde9e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 14px rgb(16 24 40 / 6%);
  --tap: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body[data-theme="callall"] { --primary: #2792d0; }
body[data-theme="koramed"] { --primary: #00387a; --accent: #3fa9f5; }
body[data-theme="acf"] { --primary: #00387a; --accent: #3fa9f5; }

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
}

a { color: var(--primary); }
img { max-width: 100%; height: auto; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Page frame ---------------------------------------------------------------------------------------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-weight: 600; }
.topbar .brand img { height: 36px; width: auto; }
.topbar nav { display: flex; gap: .5rem; align-items: center; }

.page { max-width: 44rem; margin: 0 auto; padding: 1rem 1rem 5rem; }
.page.wide { max-width: 72rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 1rem 2rem; }

/* ---- Cards -------------------------------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }

/* ---- Flash messages ---------------------------------------------------------------------------------------------- */
.flash { border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.flash.notice { background: var(--ok-bg); color: var(--ok); border-color: #b9e4c6; }
.flash.alert { background: var(--bad-bg); color: var(--bad); border-color: #f3b9b3; }
.flash.warning { background: var(--warn-bg); color: var(--warn); border-color: #f1d89a; }
.errors ul { margin: .4rem 0 0 1.1rem; padding: 0; }

/* ---- Forms ------------------------------------------------------------------------------------------------------ */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
label .optional { font-weight: 400; color: var(--muted); }
.field { margin-bottom: 1rem; }
.field .hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.grid-2 { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }

input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: .65rem .8rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #b9c0cd;
  border-radius: 10px;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.2rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent);
  outline-offset: 1px;
  border-color: var(--primary);
}
input.otp { font-size: 2rem; letter-spacing: .6rem; text-align: center; }
.field.invalid input, .field.invalid select { border-color: var(--bad); }
.field .error { color: var(--bad); font-size: .85rem; margin-top: .25rem; }

.check { display: flex; gap: .7rem; align-items: flex-start; min-height: var(--tap); padding: .4rem 0; font-weight: 400; }
.check input { width: 1.4rem; height: 1.4rem; margin-top: .15rem; flex: none; accent-color: var(--primary); }

fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 700; font-size: 1.1rem; padding: 0; margin-bottom: .8rem; }

/* ---- Buttons ----------------------------------------------------------------------------------------------------- */
.btn, button, input[type="submit"] {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: var(--tap);
  padding: .6rem 1.2rem;
  border-radius: 10px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn.secondary, button.secondary { background: #fff; color: var(--primary); }
.btn.danger, button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost, button.ghost { background: transparent; color: var(--primary); border-color: transparent; }
.btn.small, button.small { min-height: 36px; padding: .3rem .8rem; font-size: .875rem; }
.btn.block, button.block { width: 100%; }
.btn[disabled], button[disabled] { opacity: .55; cursor: not-allowed; }
.inline-form { display: inline; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---- Badges ------------------------------------------------------------------------------------------------------ */
.badge { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e8ebf2; color: #39425a; }
.badge.NEW { background: #e4ecff; color: #1d3f9c; }
.badge.REG { background: var(--ok-bg); color: var(--ok); }
.badge.CAN, .badge.ERR { background: var(--bad-bg); color: var(--bad); }
.badge.REP, .badge.EXP, .badge.EXD, .badge.ACC { background: var(--warn-bg); color: var(--warn); }
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.inactive { background: #eceff4; color: #6b7487; }

/* ---- Wizard (application form) --------------------------------------------------------------------------------------- */
.progress { display: flex; gap: .35rem; margin-bottom: 1rem; }
.progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress span.done { background: var(--primary); }
.step-title { color: var(--muted); font-size: .85rem; margin-bottom: .2rem; }
[data-wizard-target="step"][hidden] { display: none; }
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--page) 70%, transparent);
  padding: .8rem 0 .6rem;
  margin-top: 1rem;
  display: flex;
  gap: .75rem;
}
.sticky-actions > * { flex: 1; }

/* ---- Photo upload ------------------------------------------------------------------------------------------------------ */
.upload { border: 2px dashed #b9c0cd; border-radius: var(--radius); padding: .9rem; background: #fafbfd; }
.upload.filled { border-style: solid; border-color: var(--ok); background: var(--ok-bg); }
.upload .preview { display: block; max-height: 160px; margin: .6rem auto 0; border-radius: 8px; }
.upload .status { font-size: .85rem; color: var(--muted); min-height: 1.2rem; }
.upload input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* ---- Lists / tables (cards on a phone, a table on a desktop) ---------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters > .field { flex: 1 1 12rem; margin: 0; }
.filters > div:empty { display: none; }
.filters > input[type="submit"] { flex: 0 0 auto; }
.table { width: 100%; border-collapse: collapse; }
.table thead { display: none; }
.table tr { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .7rem; }
.table td { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; text-align: right; }
.table td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left; }
.table td.actions-cell { justify-content: flex-end; flex-wrap: wrap; gap: .5rem; }
.table td.actions-cell::before { content: none; }
.table td.wrap { word-break: break-word; }
pre.log { white-space: pre-wrap; word-break: break-all; background: #0f1420; color: #d7e0f5; padding: .8rem; border-radius: 10px; max-height: 24rem; overflow: auto; font-size: .8rem; }

.pagination { display: flex; gap: .5rem; align-items: center; justify-content: center; margin: 1rem 0; flex-wrap: wrap; }

dl.details { display: grid; grid-template-columns: 1fr; gap: .1rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); font-size: .85rem; margin-top: .6rem; }
dl.details dd { margin: 0; word-break: break-word; }

/* ---- Tiles (dashboards) ---------------------------------------------------------------------------------------------- */
.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(2, 1fr); margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); display: block; }
.tile strong { display: block; font-size: 1.8rem; line-height: 1.1; color: var(--primary); }
.tile.action { display: flex; flex-direction: column; justify-content: space-between; min-height: 6rem; font-weight: 600; }
.tile.action .icon { font-size: 1.6rem; }

/* ---- Admin shell ---------------------------------------------------------------------------------------------------------- */
/* ---- Menu bar (BA portal): a horizontal strip that scrolls sideways on a phone ---------------------------------------- */
.menu-bar { position: relative; background: #f3f5f9; border-bottom: 1px solid var(--line); overflow: hidden; }
.menu-bar ul { list-style: none; margin: 0; padding: 0; display: flex; white-space: nowrap; }
.menu-bar li a { display: block; padding: .75rem 1rem; text-decoration: none; color: var(--ink); font-weight: 600; min-height: var(--tap); }
.menu-bar li a[aria-current="page"] { background: color-mix(in srgb, var(--primary) 12%, white); color: var(--primary); box-shadow: inset 0 -3px 0 var(--primary); }

/* Waffle: when the items do not fit across the page (menu_controller.js adds .collapsed) they become a dropdown. */
.menu-bar .waffle { display: flex; align-items: center; gap: .7rem; width: 100%; justify-content: flex-start; background: transparent; border: 0; border-radius: 0;
  color: var(--ink); padding: .5rem 1rem; font-weight: 700; }
.menu-bar .waffle:hover { background: color-mix(in srgb, var(--primary) 8%, white); }
.waffle-icon { display: grid; grid-template-columns: repeat(3, 5px); gap: 3px; }
.waffle-icon i { width: 5px; height: 5px; border-radius: 1px; background: currentColor; }
.menu-bar.collapsed { overflow: visible; }
.menu-bar.collapsed ul { display: none; position: absolute; z-index: 30; left: 0; right: 0; top: 100%; flex-direction: column; white-space: normal;
  background: var(--surface); border: 1px solid var(--line); border-top: 0; box-shadow: 0 8px 18px rgb(16 24 40 / 14%); }
.menu-bar.collapsed.open ul { display: flex; }
.menu-bar .section { display: none; }
.menu-bar.collapsed .section { display: block; padding: .7rem 1.2rem .2rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-top: 1px solid #eef0f4; }
.menu-bar.collapsed li a { padding: .8rem 1.2rem; border-top: 1px solid #eef0f4; box-shadow: none; }
.menu-bar.collapsed li a[aria-current="page"] { box-shadow: inset 4px 0 0 var(--primary); }

/* ---- Wider screens ----------------------------------------------------------------------------------------------------------- */
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  dl.details { grid-template-columns: 14rem 1fr; }
  dl.details dt { margin-top: 0; padding: .3rem 0; }
  dl.details dd { padding: .3rem 0; }

  .table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  .table thead { display: table-header-group; background: #f6f8fb; }
  .table tr { display: table-row; border: 0; border-radius: 0; padding: 0; margin: 0; background: transparent; }
  .table tbody tr + tr { border-top: 1px solid var(--line); }
  .table th, .table td { display: table-cell; padding: .65rem .8rem; text-align: left; vertical-align: middle; }
  .table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .table td::before { content: none; }
  .table td.actions-cell { text-align: right; white-space: nowrap; }
}

@media (min-width: 960px) {
  .admin-layout { display: grid; grid-template-columns: 15rem 1fr; min-height: calc(100vh - 3.5rem); }
  /* Wide screens: the admin menu is a sidebar (menu_controller.js finds nothing to collapse). */
  .admin-nav.menu-bar { overflow: visible; background: var(--surface); border-bottom: 0; border-right: 1px solid var(--line); }
  .admin-nav.menu-bar ul { display: block; white-space: normal; }
  .admin-nav .waffle { display: none !important; }
  .admin-nav.menu-bar li a { font-weight: 500; min-height: 0; padding: .55rem 1.2rem; }
  .admin-nav.menu-bar li a[aria-current="page"] { font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
  .admin-nav.menu-bar .section { display: block; padding: .6rem 1.2rem .1rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .admin-layout .page { max-width: none; padding: 1.5rem 2rem 3rem; }
}

@media print {
  .topbar, .admin-nav, .footer, .actions, .pagination, .filters { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
