/* MendipSys Admin — 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); }

/* ── Icons (includes/icons.php — Lucide, the estate house style) ──
   1em square, so an icon sizes itself from the text beside it; stroke is
   currentColor, so it takes the link/button colour with no extra CSS. */
.ico { width: 1.15em; height: 1.15em; flex: 0 0 auto; vertical-align: -.2em; }
.ico + span { margin-left: .4em; }
:where(a:has(> .ico), button:has(> .ico), summary:has(> .ico), h3:has(> .ico)) { display: inline-flex; align-items: center; }
a:has(> .ico):hover > span { text-decoration: underline; }
a:has(> .ico):hover { text-decoration: none; }

/* ── Top bar ── */
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); }
.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 { color: var(--muted); padding: .3rem .1rem; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.on { color: var(--accent); font-weight: 600; }
.topbar-user a { color: var(--muted); }
.topbar-user a:hover { color: var(--text); }
.topbar-user { display: flex; gap: .8rem; align-items: center; color: var(--muted); }
.nav-toggle { display: none; }

/* ── 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 .35rem; font-size: 15px; display: flex; }
.tile .ico-tile {
  width: 32px; height: 32px; padding: 7px; margin-right: .2rem; border-radius: 9px;
  background: var(--blue-bg); color: var(--accent);
}
.tile:hover .ico-tile { background: var(--accent); color: var(--panel); }
.tile h3 > span { margin-left: .55rem; }
.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 — and the estate "Leave feedback" link, which lives in it
   (David's placement for customer and diary, 2026-09-16). The pill never
   blocks what is under it; only the link takes clicks. ── */
.beta-pill {
  position: fixed; right: .8rem; bottom: .8rem; z-index: 25;
  display: flex; align-items: center; gap: .45rem;
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 3px 11px; font-size: 11.5px; opacity: .85; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
}
.beta-pill:hover { opacity: 1; }
.beta-pill .bp-sep { opacity: .55; }
.beta-pill a.feedback-link { pointer-events: auto; color: inherit; font-weight: 600; }
.beta-pill a.feedback-link .ico { width: 13px; height: 13px; }
.beta-pill a.feedback-link span { margin-left: .3rem; }

/* ── 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: inline-flex; 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%; }
}

/* ── Embedded in the MendipSys desktop shell (app.mendipsys.co.uk): drop our
   own top chrome — the shell already shows where the user is. The top bar is
   in normal flow (not fixed), so nothing else reserves room for it. ── */
body.embedded .topbar { display: none !important; }
/* framed: the word "beta" goes, the feedback link stays */
body.embedded .beta-pill .bp-beta, body.embedded .beta-pill .bp-sep { display: none !important; }
body.embedded .beta-pill:not(:has(.feedback-link)) { display: none !important; }
