/* =========================================================================
   Ghar Maker — mobile-first styles for the webview app.
   The look follows the click-through prototype (prototype/index.html):
   warm off-white page, white bordered cards, brick orange for the primary
   action and the active tab, soft coloured status chips, the phone's own font.
   No framework; one file; no inline styles (CSP: style-src 'self').
   ========================================================================= */

/* ---------- Tokens (same values as the prototype) ---------- */
:root {
  --brick: #D9572B;        /* primary action, active tab, avatars */
  --brick-dark: #B8441C;
  --brick-soft: #FBE9E1;
  --ink: #1F2328;          /* text */
  --ink-2: #4B5563;        /* secondary text */
  --ink-3: #8A929C;        /* hints, section titles, idle icons */
  --line: #E7E3DE;         /* card borders, dividers */
  --field: #D6D1CA;        /* input borders */
  --bg: #F6F4F1;           /* page */
  --card: #FFFFFF;
  --ok: #1F8A5B;    --ok-soft: #E3F4EC;
  --warn: #B7791F;  --warn-soft: #FDF3DC;
  --info: #2B6CB0;  --info-soft: #E4EEF9;
  --danger: #B42318; --danger-soft: #FBE3E1;
  --muted-soft: #EEECE9;

  --radius: 14px;          /* cards */
  --radius-control: 12px;  /* inputs, buttons */
  --tap: 48px;             /* smallest touch target */
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px;               /* 16px: no zoom-on-focus in iOS/Android webviews */
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; }
a { color: inherit; text-decoration: none; }
p a, .alt a, .notice a { color: var(--brick-dark); font-weight: 600; }
button, input, select { font: inherit; color: inherit; }
svg { display: block; }
:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }   /* app.js hides no-JS fallbacks with the hidden attribute */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); font-size: 14px; }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }

/* ---------- App shell: a phone-sized column ---------- */
.shell {
  position: relative; width: 100%; height: 100vh; height: 100dvh; margin: 0 auto;
  background: var(--bg); overflow: hidden; display: flex; flex-direction: column;
}
/* On a wide screen, show the app in a phone frame like the prototype. */
@media (min-width: 500px) {
  body { display: flex; align-items: center; justify-content: center; padding: 24px; background: #2A2723; }
  .shell { max-width: 400px; border-radius: 36px; border: 10px solid #111; height: 840px; max-height: calc(100vh - 48px); box-shadow: 0 30px 80px rgba(0, 0, 0, .45); }
}

.scroll { flex: 1; overflow-y: auto; padding: 16px 16px 96px; -webkit-overflow-scrolling: touch; }
.scroll.has-cta { padding-bottom: 96px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title.root { padding-left: 6px; }
.topbar-title h1 { font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title small { display: block; font-size: 12px; color: var(--ink-3); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: none; width: var(--tap); height: var(--tap); display: grid; place-items: center;
  border-radius: var(--radius-control); color: var(--ink-2);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--muted-soft); }

/* The "current site" switcher (Home) */
.site-switch {
  display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; min-height: var(--tap); padding: 6px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--bg);
}
.site-switch small { display: block; font-size: 11px; color: var(--ink-3); line-height: 1.1; }
.site-switch b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-switch .chev { color: var(--ink-3); }
.site-switch svg { width: 18px; height: 18px; }

/* ---------- Bottom tab bar ---------- */
.tabbar { display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; min-height: 56px; font-size: 11px; color: var(--ink-3);
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--brick); }

/* ---------- Cards and lists ---------- */
.card, .panel {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.panel { padding-top: 0; padding-bottom: 0; }              /* a list card: rows bring their own padding */
.panel-body { padding: 14px 0; }
a.card:active, a.row:active, button.row:active { background: #FBFAF8; }
.card-link { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.card .row-top { display: flex; align-items: center; gap: 10px; }
.card .row-top b { flex: 1; min-width: 0; }
.card .meta { display: block; color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.card.btn-reset { background: var(--card); border: 1px solid var(--line); color: var(--ink); font: inherit; }

.section-title, .section-label {
  font-size: 13px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em;
  margin: 18px 2px 8px;
}
.section-title:first-child, .section-label:first-child { margin-top: 0; }

/* One line in a list card */
.row {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 0;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.panel > form + form .row { border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; display: block; }
.row-main strong { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main span { display: block; color: var(--ink-3); font-size: 13px; }
.row .chev, .card-link .chev { color: var(--ink-3); flex: none; }
.row .chev svg, .card-link .chev svg { width: 20px; height: 20px; }
.row-actions { display: flex; gap: 6px; flex: none; align-items: center; }
.row-icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; color: var(--ink-2); }
.row-icon svg { width: 22px; height: 22px; }
.btn-reset { width: 100%; background: none; border: 0; text-align: left; cursor: pointer; }
.empty-note { padding: 16px 0; color: var(--ink-3); font-size: 14px; }

.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; background: var(--brick-soft); color: var(--brick-dark);
}
.avatar svg { width: 20px; height: 20px; }
.avatar.sq { border-radius: 12px; background: var(--info-soft); color: var(--info); }
.avatar.plain { background: var(--muted-soft); color: var(--ink-2); }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }

.call {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok-soft); color: var(--ok);
}
.call svg { width: 18px; height: 18px; }

/* Profile card at the top of a person's screen */
.profile { display: flex; align-items: center; gap: 12px; }
.profile h2 { font-size: 16px; font-weight: 650; }

/* ---------- Home ---------- */
.greet { margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--ink-3); }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.actions a {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 4px; text-align: center; font-size: 12px; color: var(--ink-2);
}
.actions svg { width: 24px; height: 24px; color: var(--brick); }

/* ---------- Chips ---------- */
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; background: var(--muted-soft); color: var(--ink-2);
}
.chip-active { background: var(--info-soft); color: var(--info); }
.chip-hold { background: var(--warn-soft); color: var(--warn); }
.chip-done { background: var(--ok-soft); color: var(--ok); }
.chip-brick { background: var(--brick-soft); color: var(--brick-dark); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Filter tabs (pills) ---------- */
.tabs, .segments { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs a, .segments a {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; white-space: nowrap;
}
.tabs a[aria-current="page"], .segments a[aria-current="page"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Team tree ---------- */
.tree { list-style: none; }
.tree > li + li > .row { border-top: 1px solid var(--line); }
.tree > li:first-child > .row { border-top: 0; }
.tree .tree { border-left: 2px solid var(--line); margin-left: 19px; padding-left: 12px; }
.tree .tree .row { min-height: 52px; border-top: 0; }
.tree .tree .avatar { width: 34px; height: 34px; font-size: 13px; }

/* ---------- Timeline (assignment history) ---------- */
.timeline { list-style: none; padding: 14px 0 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--ink-3);
}
.timeline li.now::before { background: var(--brick); }
.timeline strong { display: block; font-weight: 650; }
.timeline span { display: block; color: var(--ink-3); font-size: 13px; }

/* ---------- Facts (label/value) ---------- */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.facts dt { color: var(--ink-3); }
.facts dd { font-weight: 600; }

/* ---------- Forms (fields sit on the page, as in the prototype) ---------- */
.form-panel { margin-bottom: 8px; }
.field { margin-top: 14px; }
.form-panel > .field:first-child { margin-top: 0; }
.field label, .field .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field .hint, .hint { display: block; font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.field p { font-size: 15px; }
.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--field); border-radius: var(--radius-control); background: #fff; color: var(--ink);
  appearance: none;
}
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238A929C' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px;
}
.input:focus { outline: none; border-color: var(--brick); box-shadow: 0 0 0 3px var(--brick-soft); }
.input.input-validation-error { border-color: var(--danger); }
.field-validation-error, .validation-summary-errors { color: var(--danger); font-size: 13px; font-weight: 600; }
.field-validation-error { display: block; margin-top: 4px; }
.validation-summary-errors { background: var(--danger-soft); border-radius: var(--radius-control); padding: 10px 12px; margin-bottom: 12px; }
.validation-summary-errors ul { padding-left: 18px; }
.validation-summary-valid { display: none; }
fieldset { border: 0; min-width: 0; }

/* Two big choices (the prototype's segmented cards) */
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice label {
  display: block; position: relative; margin: 0; padding: 12px; min-height: var(--tap); cursor: pointer;
  border: 1.5px solid var(--line); border-radius: var(--radius-control); background: #fff;
  font-size: 14px; font-weight: 400; color: var(--ink-2);
}
.choice label b { display: block; font-size: 15px; color: var(--ink); }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice label:has(input:checked) { border-color: var(--brick); background: var(--brick-soft); }
.choice label:has(input:focus-visible) { outline: 3px solid var(--info); outline-offset: 2px; }

/* Brick tick boxes (permission matrix and single checks) */
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-size: 15px; }
.check input, .matrix input[type="checkbox"] {
  appearance: none; flex: none; width: 22px; height: 22px; margin: 0; cursor: pointer;
  border: 2px solid #C9C3BB; border-radius: 6px; background: #fff;
  display: inline-grid; place-items: center;
}
.check input:checked, .matrix input[type="checkbox"]:checked {
  background: var(--brick) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E") center / 14px no-repeat;
  border-color: var(--brick);
}
.check input:disabled, .matrix input:disabled { cursor: default; opacity: .7; }

/* Permission matrix */
.matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix th { font-weight: 600; color: var(--ink-3); padding: 6px 2px; text-align: center; }
.matrix thead th:first-child, .matrix tbody th { text-align: left; }
.matrix tbody th { color: var(--ink); font-size: 14px; font-weight: 400; }
.matrix td, .matrix tbody th { border-top: 1px solid var(--line); padding: 0 2px; height: 44px; }
.matrix td { text-align: center; }
.matrix td label { display: grid; place-items: center; width: 100%; height: 44px; cursor: pointer; }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius-control);
  font-weight: 650; font-size: 16px; cursor: pointer;
  border: 1px solid transparent; background: var(--card); color: var(--ink);
}
.btn svg { width: 20px; height: 20px; }
.btn-primary { background: var(--brick); color: #fff; }
.btn-primary:active { background: var(--brick-dark); }
.btn-outline, .btn-ghost { background: transparent; border-color: var(--field); color: var(--ink); }
.btn-danger { background: transparent; border-color: #E7B4AF; color: var(--danger); }
.btn-sm { width: auto; min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-busy { opacity: .6; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.btn-row > * { flex: 1 1 140px; }
.stack > * + * { margin-top: 10px; }
.spaced { margin-top: 12px; }

/* The one primary action of a full-screen form, pinned to the bottom of the phone */
.action-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}

/* Floating add button on list screens (sits above the tab bar) */
.fab {
  position: absolute; right: 16px; bottom: 76px; z-index: 5; height: 52px; padding: 0 20px 0 16px;
  border-radius: 26px; background: var(--brick); color: #fff; font-weight: 650;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 8px 20px rgba(217, 87, 43, .35);
}
.fab svg { width: 20px; height: 20px; }

/* ---------- Messages ---------- */
.flash {
  display: flex; gap: 10px; align-items: flex-start; background: var(--ok-soft); color: #14613F;
  border-radius: var(--radius-control); padding: 10px 12px; margin-bottom: 12px; font-size: 14px; font-weight: 600;
}
.flash svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice { background: var(--info-soft); color: #1F4E80; border-radius: var(--radius-control); padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner, .readonly-note { background: var(--warn-soft); color: #7A5214; border-radius: var(--radius-control); padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }

/* One-time password reveal */
.secret {
  display: block; font-size: 26px; font-weight: 700; letter-spacing: .06em; text-align: center;
  background: var(--brick-soft); border: 2px dashed var(--brick); border-radius: var(--radius-control);
  padding: 12px 16px; margin: 10px 0; user-select: all;
}

/* ---------- Signed-out screens ---------- */
.auth { flex: 1; overflow-y: auto; padding: 48px 24px 24px; background: linear-gradient(180deg, var(--brick-soft), var(--bg) 40%); }
.auth .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--brick); display: grid; place-items: center; color: #fff; margin-bottom: 16px; }
.auth .logo svg { width: 30px; height: 30px; }
.auth h1 { font-size: 26px; margin-bottom: 4px; }
.auth > .muted { margin-bottom: 8px; }
.auth .btn-primary { margin-top: 20px; }
.auth .alt { color: var(--ink-3); font-size: 14px; text-align: center; margin-top: 14px; }
.auth .gap { height: 24px; }
/* One-time code: big, spaced digits; a text-styled button for "send a new code". */
.otp-input { font-size: 24px; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.link-button { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--brick-dark); cursor: pointer; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
