/* ============================================================
   CareSpaces / Wealden Rehab — Internal Portal
   Design system, themed to the CareSpaces brand.
   Brand source: _cswr/brand (brand.md, app-tokens.css).
   ============================================================ */

:root {
  /* --- CareSpaces brand --- */
  --navy:          #103d72;   /* primary */
  --navy-dark:     #0a2544;   /* ink / hover / footers */
  --navy-light:    #40648e;
  --magenta:       #ed1e79;   /* accent — used sparingly */
  --magenta-dark:  #be1861;

  /* Internal dashboard categorical palette */
  --teal:  #68b1a0;
  --gold:  #f3d14e;
  --coral: #da5d51;
  --plum:  #943d76;

  /* Surfaces & ink (from app-tokens.css) */
  --bg:           #f6f8fb;
  --card:         #ffffff;
  --text:         #0a2544;
  --muted:        #54657e;
  --muted-2:      #7d8ba1;
  --border:       #d7dee8;
  --border-strong:#b7c3d5;
  --accent-soft:  #e7ebf1;    /* selected / hover surface */

  --accent:       var(--navy);
  --accent-hover: var(--navy-dark);
  --ok:           #059669;
  --warn:         #b45309;

  /* Shape + depth */
  --radius: 0.875rem;         /* 14px — CareSpaces app radius */
  --radius-sm: 0.625rem;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(10, 37, 68, 0.06);
  --shadow: 0 2px 10px rgba(10, 37, 68, 0.07);
  --shadow-lift: 0 18px 40px -20px rgba(10, 37, 68, 0.45);

  --maxw: 1120px;
  --gap: 16px;

  --font-heading: "Aubaine", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Bliss Pro", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(1100px 460px at 82% -12%, #eaf0f8 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--accent-soft); padding: 1px 6px; border-radius: 5px; }

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

h1, h2, h3 { font-family: var(--font-heading); }

/* ---------- Brand bar (in-flow, not a sticky topbar) ---------- */
.brandbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 0 6px;
}
.brandbar .logo { display: inline-flex; align-items: center; text-decoration: none; }
.brandbar .logo img { height: 34px; width: auto; display: block; }
.brandbar .back {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: var(--navy);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s;
}
.brandbar .back:hover { background: var(--accent-soft); border-color: var(--border-strong); }

/* ---------- Page structure ---------- */
main { flex: 1; padding: 14px 0 64px; }

.page-head { margin: 12px 0 26px; }
.page-head h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -0.4px; color: var(--navy-dark); }
.page-head p { margin: 0; color: var(--muted); max-width: 62ch; font-size: 15px; }

.section { margin-top: 34px; }
.section:first-of-type { margin-top: 0; }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.section__head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 700;
}
.section__head .count { font-size: 12px; color: var(--muted-2); font-weight: 600; }

/* ---------- Search ---------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 12px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
}
.searchbar:focus-within { border-color: var(--navy); box-shadow: 0 0 0 3px var(--accent-soft); }
.searchbar svg { flex-shrink: 0; color: var(--muted-2); }
.searchbar input { border: none; outline: none; background: none; font-size: 15px; width: 100%; color: var(--text); font-family: var(--font-body); }

/* ---------- Tile grid ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(252px, 1fr));
  gap: var(--gap);
}
.tile {
  position: relative;
  display: flex;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}
.tile:hover {
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
  border-color: var(--border-strong);
}
.tile__icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--navy);
}
.tile__icon svg { width: 21px; height: 21px; }
.tile__body { min-width: 0; flex: 1; }
.tile__title { font-size: 15px; font-weight: 700; color: var(--navy-dark); display: flex; align-items: center; gap: 6px; }
.tile__title .ext { color: var(--muted-2); flex-shrink: 0; }
.tile__desc {
  font-size: 13px; color: var(--muted); margin-top: 3px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.tile__badge {
  position: absolute; top: 12px; right: 12px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--magenta); background: #fdeef5; border: 1px solid #f9cfe1;
  padding: 2px 8px; border-radius: var(--radius-pill);
}
.tile--app { cursor: pointer; }
.tile__more {
  margin-top: 9px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: var(--muted-2);
  transition: color 0.15s ease;
}
.tile__more svg { transition: transform 0.15s ease; }
.tile--app:hover .tile__more { color: var(--navy); }
.tile--app:hover .tile__more svg { transform: translateX(2px); }
.tiles .empty, .links .empty { grid-column: 1 / -1; text-align: center; color: var(--muted-2); padding: 40px 0; font-size: 14px; }

/* ---------- Compact link rows (weblinks) ---------- */
.links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 8px;
}
.linkrow {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.linkrow:hover { background: var(--accent-soft); border-color: var(--border-strong); }
.linkrow__icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--navy);
}
.linkrow:hover .linkrow__icon { background: #fff; }
.linkrow__icon svg { width: 16px; height: 16px; }
.linkrow__title {
  flex: 1; min-width: 0;
  font-size: 14px; font-weight: 600; color: var(--navy-dark);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.linkrow__badge {
  flex-shrink: 0;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--magenta);
}
.linkrow .ext { flex-shrink: 0; color: var(--muted-2); }

/* ---------- Home greeting + search hint + empty ---------- */
.home-head { margin: 6px 0 22px; }
.home-head h1 { margin: 0; font-size: 30px; letter-spacing: -0.4px; color: var(--navy-dark); }
.home-head__meta { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.searchbar__hint {
  flex-shrink: 0;
  font-family: var(--font-body);
  font-size: 12px; font-weight: 600; color: var(--muted-2);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 1px 8px; background: var(--bg);
}
.searchbar:focus-within .searchbar__hint { opacity: 0; }

.no-results { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; margin: 0; }

/* ---------- App details popover ---------- */
.popover-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 37, 68, 0.10);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity 0.2s ease;
}
.popover-backdrop.open { opacity: 1; }
.popover-backdrop[hidden] { display: none; }
/* Anchored to the tile via JS (left/top/width/transform). Liquid glass surface. */
.popover {
  position: fixed; left: 0; top: 0;
  width: 380px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px); overflow: auto;
  padding: 20px; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 26px 64px -20px rgba(10, 37, 68, 0.55),
    0 4px 12px rgba(10, 37, 68, 0.12);
  opacity: 0;
  will-change: transform, opacity;
}
.popover__close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; color: var(--muted);
  display: grid; place-items: center;
}
.popover__close:hover { background: var(--accent-soft); color: var(--navy); }
.popover__head { display: flex; gap: 14px; align-items: flex-start; padding-right: 30px; }
.popover__icon {
  width: 48px; height: 48px; flex-shrink: 0; border-radius: 12px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--navy);
}
.popover__icon svg { width: 24px; height: 24px; }
.popover__title { margin: 0; font-size: 19px; color: var(--navy-dark); letter-spacing: -0.2px; }
.popover__sub { margin: 5px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.popover__section { margin-top: 20px; }
.popover__h3 {
  margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700;
}
.popover__features { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.popover__features li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--text); }
.popover__check { color: var(--navy); flex-shrink: 0; margin-top: 2px; }
.popover__foot { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; }
.popover__open, .popover__alt { width: 100%; }
.popover__open.is-disabled {
  background: var(--accent-soft); color: var(--muted); cursor: not-allowed;
}

/* ---------- Generic card ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--gap); }

/* ---------- Onboarding: checklist ---------- */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.checklist li {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 15px; box-shadow: var(--shadow-sm);
}
.checklist .tick {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border-strong); display: grid; place-items: center;
  color: transparent; margin-top: 1px; transition: all 0.15s; cursor: pointer; background: #fff;
}
.checklist li.done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist li.done .step-title { text-decoration: line-through; color: var(--muted); }
.checklist .step-title { font-weight: 600; font-size: 14px; }
.checklist .step-detail { font-size: 13px; color: var(--muted); margin-top: 2px; }
.checklist .step-detail a { color: var(--navy); }

/* ---------- Contact cards ---------- */
.contact { display: flex; flex-direction: column; gap: 3px; }
.contact .name { font-weight: 700; font-size: 15px; color: var(--navy-dark); }
.contact .role { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.contact .rows { margin-top: 8px; display: grid; gap: 4px; }
.contact .rows a, .contact .rows span { font-size: 13px; color: var(--navy); text-decoration: none; word-break: break-word; }
.contact .rows a:hover { text-decoration: underline; }

/* ---------- Company info: copy fields ---------- */
.toggle {
  display: inline-flex; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 4px; margin-bottom: 8px; box-shadow: var(--shadow-sm);
}
.toggle button {
  border: none; background: transparent; padding: 8px 20px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-radius: var(--radius-pill); cursor: pointer; transition: all 0.15s; font-family: var(--font-body);
}
.toggle button.active { background: var(--navy); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.field {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-sm);
}
.field .body { flex: 1; min-width: 0; }
.field .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 2px; }
.field .value { font-size: 14px; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
button.copy {
  border: 1px solid var(--border-strong); background: #fff; color: var(--text); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer; flex-shrink: 0; transition: all 0.15s; font-family: var(--font-body);
}
button.copy:hover { background: var(--navy); color: #fff; border-color: var(--navy); }
button.copy.copied { background: var(--ok); color: #fff; border-color: var(--ok); }

.ref-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.ref-card h3 { margin: 0 0 12px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; color: var(--navy-dark); }
.ref-card .ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.scope { grid-column: 1 / -1; }

.company-only { display: none; }
body[data-company="wealden"] .company-only.wealden { display: block; }
body[data-company="wealden"] .grid > .company-only.wealden { display: flex; }
body[data-company="carespaces"] .company-only.carespaces { display: block; }
body[data-company="carespaces"] .grid > .company-only.carespaces { display: flex; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  font-family: var(--font-body); font-weight: 600; font-size: 14px; cursor: pointer;
  border-radius: var(--radius-sm); padding: 10px 16px; border: 1px solid transparent; transition: all 0.15s;
}
.btn--primary { background: var(--navy); color: #fff; }
.btn--primary:hover { background: var(--navy-dark); }
.btn--ghost { background: var(--card); color: var(--navy); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--danger { background: #fff; color: #dc2626; border-color: #f3c3c3; }
.btn--danger:hover { background: #fef2f2; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: 13px; }
.footer__inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 0; }
.footer a { color: var(--navy); text-decoration: none; font-weight: 600; }
.footer a:hover { text-decoration: underline; }
.footer .admin-link { color: var(--muted-2); font-weight: 500; }

/* ============================================================
   Admin editor
   ============================================================ */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 50% -10%, #1a4a86, var(--navy-dark));
}
.gate__card {
  background: var(--card); border-radius: var(--radius); padding: 30px; width: 100%; max-width: 380px;
  box-shadow: 0 30px 70px -20px rgba(0,0,0,0.5); text-align: center;
}
.gate__card img { height: 32px; margin-bottom: 18px; }
.gate__card h1 { font-size: 20px; margin: 0 0 6px; color: var(--navy-dark); }
.gate__card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.gate__card input {
  width: 100%; padding: 12px 14px; font-size: 15px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); margin-bottom: 12px; font-family: var(--font-body); text-align: center;
}
.gate__card input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--accent-soft); }
.gate__err { color: #dc2626; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

.admin-toolbar {
  position: sticky; top: 0; z-index: 20; background: rgba(246,248,251,0.9); backdrop-filter: blur(8px);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 14px 0; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.admin-toolbar .spacer { flex: 1; }
.admin-status { font-size: 13px; color: var(--muted); }
.admin-status.saved { color: var(--ok); font-weight: 600; }

.editor-group { margin-top: 26px; }
.editor-group > label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin-bottom: 8px; }

.row-editor { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.row-editor .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.row-editor .field-input { display: flex; flex-direction: column; gap: 4px; }
.row-editor .field-input--wide { grid-column: 1 / -1; }
.row-editor .field-input label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted-2); font-weight: 600; }
.row-editor input, .row-editor textarea, .form-input {
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 14px;
  font-family: var(--font-body); background: #fff; color: var(--text); width: 100%;
}
.row-editor input:focus, .row-editor textarea:focus, .form-input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--accent-soft); }
.row-editor .row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.icon-btn {
  border: 1px solid var(--border-strong); background: #fff; border-radius: 8px; padding: 6px 10px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--muted); font-family: var(--font-body);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--navy); }
.icon-btn.del:hover { background: #fef2f2; color: #dc2626; border-color: #f3c3c3; }
.add-row { margin-top: 4px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-input-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-input-group label { font-size: 12px; font-weight: 600; color: var(--muted); }

.notice {
  background: #fdeef5; border: 1px solid #f9cfe1; color: var(--magenta-dark);
  border-radius: var(--radius-sm); padding: 12px 15px; font-size: 13px; margin-bottom: 6px;
}

/* ---------- Accessibility ---------- */
a.tile:focus-visible,
a.linkrow:focus-visible,
.brandbar .back:focus-visible,
.toggle button:focus-visible,
button.copy:focus-visible,
.btn:focus-visible,
.footer a:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.searchbar input:focus-visible { outline: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .tile:hover { transform: none; }
  html { scroll-behavior: auto; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .brandbar { flex-wrap: wrap; }
  .page-head h1, .home-head h1 { font-size: 25px; }
  .searchbar__hint { display: none; }
}
