/* MendipSys Diary — family styling (CSS variables, dark theme via
   [data-theme=dark], same ms_theme localStorage key as the other apps).
   Core design system only: chrome, cards, stats, tables, chips, forms,
   login, mobile. Page-specific styles go at the bottom under a heading. */

:root {
  --bg: #f7f8fc;
  --panel: #ffffff;
  --border: #dfe2ea;
  --text: #202333;
  --muted: #73788b;
  --accent: #005e85;
  --shadow: 0 10px 30px rgba(35, 25, 66, .07);
  --red: #c0392b;   --red-bg: #fdecea;
  --blue: #1f5f9e;  --blue-bg: #e8f1fb;
  --green: #1e7e46; --green-bg: #e7f5ec;
  --grey: #5c6270;  --grey-bg: #eef0f4;
  --amber: #9a6b00; --amber-bg: #fdf3dd;
}
[data-theme="dark"] {
  --bg: #15161d;
  --panel: #1e2029;
  --border: #33364a;
  --text: #e8eaf2;
  --muted: #9aa0b5;
  --accent: #5db3d9;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --red-bg: #3a2220;  --blue-bg: #1d2a3a;
  --green-bg: #1e3227; --grey-bg: #272a36;
  --amber: #e3b04b;   --amber-bg: #33290f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 18px; }
h2 { font-size: 14px; margin: 0 0 .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
small { color: var(--muted); }

/* ── Top bar ── */
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); }
/* Embedded in the MendipSys desktop shell (app.mendipsys.co.uk, ?embed=1): drop
   our own top chrome — the shell shows where the user is. The diary tabs and
   the phone ☰ stay. The topbar is in flow (not fixed), so nothing to re-pad. */
body.embedded .topbar { display: none !important; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: .65rem 1rem;
  display: flex; align-items: center; gap: 1.4rem;
}
.brand { font-weight: 700; font-size: 15px; color: var(--text); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a.on { color: var(--accent); font-weight: 600; }
.topbar-user { display: flex; gap: .8rem; align-items: center; color: var(--muted); }
.nav-toggle { display: none; }
.nav-toggle .ico { width: 20px; height: 20px; vertical-align: -4px; }

/* Dark-mode pill switch (assets/js/app.js writes the shared ms_theme key). */
.theme-switch {
  position: relative; width: 40px; height: 22px; padding: 0; flex: 0 0 auto;
  background: var(--grey-bg); border: 1px solid var(--border); border-radius: 999px;
  cursor: pointer; transition: 180ms ease;
}
.theme-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25); transition: transform 180ms ease;
}
[data-theme="dark"] .theme-switch { background: var(--accent); }
[data-theme="dark"] .theme-switch::after { transform: translateX(18px); }

/* ── Layout ── */
.page { max-width: 1200px; margin: 1.2rem auto; padding: 0 1rem; }
.cols { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.grow { flex: 1 1 560px; }
.side { flex: 0 1 320px; display: flex; flex-direction: column; gap: 1rem; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 1rem 1.1rem;
}
.card + .card { margin-top: 1rem; }
.notice {
  background: var(--red-bg); border: 1px solid var(--red); color: var(--text);
  border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1rem;
}
.notice-ok { background: var(--green-bg); border-color: var(--green); }
.empty { color: var(--muted); }

/* ── Stats ── */
.stat-row { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: .7rem 1.2rem; min-width: 110px;
}
.stat-n { display: block; font-size: 22px; font-weight: 700; }
.stat-n small { font-size: 13px; font-weight: 400; }
.stat-l { color: var(--muted); font-size: 12px; }
.stat-link { text-decoration: none; }
.stat-link:hover { border-color: var(--accent); text-decoration: none; }

/* ── Tiles (module launcher) ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; }
.tile {
  display: block; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 1rem 1.1rem; color: var(--text);
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile h3 { margin: 0 0 .3rem; font-size: 15px; }
.tile p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.tile.soon { opacity: .6; pointer-events: none; }

/* ── Table ── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: .35rem .5rem; border-bottom: 1px solid var(--border);
}
.tbl td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .empty { color: var(--muted); text-align: center; padding: 1.4rem; }
/* Tables live inside their card: if columns ever exceed the card width the
   card scrolls internally rather than the table spilling out of the panel. */
.table-card { overflow-x: auto; }

/* ── Chips / dots / lists ── */
.chip {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: 12px; white-space: nowrap;
}
.chip-red   { background: var(--red-bg);   color: var(--red); }
.chip-blue  { background: var(--blue-bg);  color: var(--blue); }
.chip-green { background: var(--green-bg); color: var(--green); }
.chip-grey  { background: var(--grey-bg);  color: var(--grey); }
.chip-amber { background: var(--amber-bg); color: var(--amber); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .45rem; }
.dot-on  { background: var(--green); }
.dot-off { background: var(--border); }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .3rem 0; display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; }
ul.plain.tight li { padding: .15rem 0; }

/* ── Buttons / forms ── */
.btn {
  padding: .55rem 1.1rem; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  align-self: center;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-off { background: var(--grey); }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 13px; }

.form label { display: block; color: var(--muted); font-size: 13px; margin-bottom: .6rem; }
.form input, .form textarea, .form select {
  display: block; width: 100%; margin-top: .3rem; padding: .5rem .7rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
.search-row { display: flex; gap: .6rem; margin-bottom: 1rem; }
.search-row input {
  flex: 1; padding: .55rem .8rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg); color: var(--text); font-size: 14px;
}
.filter-label {
  display: flex; align-items: center; gap: .4rem;
  color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
.filter-label select {
  padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 13px;
  text-transform: none; letter-spacing: 0;
}

/* ── Login ── */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 2rem; width: min(92vw, 24rem);
}
.login-box h1 { margin: 0 0 1rem; }
.login-box p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.login-box label { display: block; margin: .8rem 0; color: var(--muted); font-size: 13px; }
.login-box input {
  width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.login-box button {
  width: 100%; margin-top: 1rem; padding: .6rem;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.login-error {
  background: var(--red-bg); color: var(--red); border-radius: 8px;
  padding: .55rem .8rem; margin-bottom: .6rem; font-size: 13px;
}

/* ── Beta pill ── */
.beta-pill {
  position: fixed; right: .8rem; bottom: .8rem;
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 2px 10px; font-size: 11px; opacity: .75; pointer-events: none;
  display: flex; align-items: center; gap: .35rem;
}
/* the pill never blocks what's under it — except the feedback link itself */
.beta-pill .bb-sep { opacity: .6; }
.beta-pill a.feedback-link { pointer-events: auto; color: inherit; font-weight: 600; text-decoration: none; }
.beta-pill a.feedback-link:hover { text-decoration: underline; }
.beta-pill:has(a.feedback-link:hover) { opacity: 1; }

/* ── Mobile: table rows become panels within the table's card ── */
@media (max-width: 760px) {
  .page { margin: .8rem auto; padding: 0 .7rem; }

  /* Hamburger menu: pages + log out live behind ☰ */
  .topbar-inner { flex-wrap: wrap; gap: .5rem .9rem; padding: .6rem .8rem; }
  .nav-toggle {
    display: block; margin-left: auto; cursor: pointer;
    background: none; border: 1px solid var(--border); border-radius: 8px;
    padding: .3rem .6rem; color: var(--text); font-size: 17px; line-height: 1;
  }
  .topbar nav, .topbar-user { display: none; }
  .topbar.open nav {
    display: flex; flex-direction: column; order: 3; flex-basis: 100%; gap: 0;
  }
  .topbar.open nav a { padding: .65rem .15rem; border-top: 1px solid var(--border); }
  .topbar.open .topbar-user {
    display: flex; order: 4; flex-basis: 100%; justify-content: space-between;
    padding: .65rem .15rem .2rem; border-top: 1px solid var(--border);
  }

  .stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat { min-width: 0; padding: .55rem .8rem; }
  .stat-row .btn, .stat-row form { grid-column: span 2; }

  .tbl.responsive thead { display: none; }
  .tbl.responsive, .tbl.responsive tbody { display: block; }
  .tbl.responsive tr {
    display: block;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 10px; padding: .55rem .8rem; margin-bottom: .6rem;
  }
  .tbl.responsive td {
    display: flex; gap: .8rem; align-items: baseline;
    justify-content: space-between; text-align: right;
    border: 0; padding: .18rem 0; max-width: none;
  }
  .tbl.responsive td::before {
    content: attr(data-label);
    flex: 0 0 5.2rem; text-align: left;
    font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted);
  }
  .tbl.responsive td.cell-main {
    display: block; text-align: left;
    font-weight: 600; padding-bottom: .35rem;
  }
  .tbl.responsive td.cell-main::before { display: none; }
  .tbl.responsive .empty { display: block; text-align: center; }

  .search-row { flex-direction: column; }
  .cols { flex-direction: column; }
  .side { flex: none; width: 100%; }
}

/* ── View as (super admins): banner, picker, access report ── */
.va-bar {
  position: sticky; top: 0; z-index: 300; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .8rem;
  padding: .45rem 1rem; background: #7a3e00; color: #fff; font-size: 13px;
}
.va-bar .ico { width: 16px; height: 16px; }
.va-bar b { font-weight: 700; }
.va-bar form { margin: 0; }
.va-bar button {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px; padding: 2px 11px; font: inherit; cursor: pointer;
}
.va-bar button:hover { background: rgba(255,255,255,.26); }
.va-bar .va-stop { background: #fff; color: #7a3e00; font-weight: 700; }
.beta-pill button.va-open {
  pointer-events: auto; background: none; border: 0; padding: 0; color: inherit; font: inherit; font-weight: 600; cursor: pointer;
}
.beta-pill button.va-open:hover { text-decoration: underline; }
.beta-pill:has(button.va-open:hover) { opacity: 1; }
.va-dlg {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 1rem 1.2rem 1.2rem;
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text);
}
.va-dlg::backdrop { background: rgba(0,0,0,.4); }
.va-head { display: flex; align-items: center; gap: .6rem; margin: 0; }
.va-head h2 { flex: 1; margin: 0; font-size: 17px; text-transform: none; letter-spacing: 0; }
.va-head button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px; }
.va-note { color: var(--muted); font-size: 13px; margin: .5rem 0 .8rem; }
.va-dlg h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem 0 .3rem; }
.va-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.va-tbl td { padding: .3rem .4rem; border-top: 1px solid var(--border); vertical-align: top; }
.va-tbl .va-i { width: 20px; }
.va-tbl .va-i .ico { width: 15px; height: 15px; }
.va-yes .va-i { color: #1a7f37; }
.va-no { color: var(--muted); }
.va-why { width: 46%; font-size: 12px; color: var(--muted); }
.va-yes .va-why { color: #1a7f37; }
.va-codes { font-size: 12px; margin: .3rem 0; word-break: break-word; }
.va-muted { color: var(--muted); }
.va-find {
  width: 100%; box-sizing: border-box; padding: .5rem .7rem; font: inherit; margin-bottom: .6rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg, #fff); color: var(--text);
}
.va-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px; max-height: 60vh; overflow: auto; margin: 0; }
.va-list button {
  text-align: left; background: none; border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem;
  font: inherit; font-size: 13px; color: var(--text); cursor: pointer;
}
.va-list button:hover, .va-list button.on { border-color: var(--accent); color: var(--accent); }
.va-list button[hidden] { display: none; }
.va-list small { color: var(--muted); margin-left: .3rem; }
@media (max-width: 760px) { .va-why { width: auto; display: block; } .va-tbl tr { display: grid; grid-template-columns: 20px 1fr; } .va-tbl .va-why { grid-column: 2; border-top: 0; padding-top: 0; } }
@media print { .va-bar { display: none !important; } }
.va-alert { background: #fdecea; color: #8a1c12; border: 1px solid #f1b5ae; border-radius: 8px; padding: .5rem .7rem; font-size: 13px; }
.va-sum { font-size: 13px; margin: 0 0 .4rem; }
