/* ==========================================================================
   Family Hub — shared visual language for all logged-in pages
   Extends the home dashboard styling to modules, sections, forms and tables.
   ========================================================================== */

:root {
  --fg: var(--text);
  --hover: var(--surface-2);
  --danger: #8a2d2d;
  --danger-soft: #fff4f4;
  --danger-border: #e7c9c9;
  --info: #2563eb;
  --info-soft: #eef4fb;
  --fh-ui-radius: 24px;
  --fh-ui-radius-sm: 16px;
  --fh-view: var(--primary);
  --fh-view-soft: var(--primary-soft);
}

html[data-theme="dark"] {
  --danger: #ffb4b4;
  --danger-soft: #3a2020;
  --danger-border: #6b3a3a;
  --info: #8ab4ff;
  --info-soft: #263246;
}

/* --- Per-view accents ---------------------------------------------------- */
body.view-agenda { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }
body.view-school { --fh-view: #4f7ab5; --fh-view-soft: var(--blue); }
body.view-study-ai { --fh-view: var(--plum); --fh-view-soft: var(--plum-soft); }
body.view-task { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }
body.view-work { --fh-view: #4a6c8c; --fh-view-soft: var(--blue); }
body.view-health,
body.view-health-result { --fh-view: var(--terra); --fh-view-soft: var(--terra-soft); }
body.view-kitchen { --fh-view: var(--amber); --fh-view-soft: var(--amber-soft); }
body.view-finance { --fh-view: var(--sage); --fh-view-soft: var(--sage-soft); }
body.view-free-time { --fh-view: var(--plum); --fh-view-soft: var(--plum-soft); }
body.view-automation { --fh-view: var(--plum); --fh-view-soft: var(--plum-soft); }
body.view-vault { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }
body.view-memories { --fh-view: var(--amber); --fh-view-soft: var(--amber-soft); }
body.view-assistant { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }
body.view-settings { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }
body.view-family { --fh-view: var(--sage); --fh-view-soft: var(--sage-soft); }
body.view-home { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }
body.view-family-home { --fh-view: var(--primary); --fh-view-soft: var(--primary-soft); }

/* --- Topbar -------------------------------------------------------------- */
.content .topbar-heading {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.content .topbar-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .13em;
  line-height: 1;
  text-transform: uppercase;
}

.content .topbar-kicker::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fh-view);
  box-shadow: 0 0 0 4px var(--fh-view-soft);
  flex: 0 0 auto;
}

.content .topbar-kicker-sep {
  color: var(--border-strong);
  font-weight: 700;
}

.content .topbar-title-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.content .topbar-icon {
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 16px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--surface);
  color: var(--fh-view);
  font-size: 26px;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}

.content .topbar-icon::after {
  content: "";
  position: absolute;
  right: -14px;
  bottom: -16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--fh-view-soft);
  opacity: .9;
}

.content .topbar-icon > * {
  position: relative;
  z-index: 1;
}

.content .topbar-title {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 31px);
  font-weight: 900;
  letter-spacing: -.035em;
  line-height: 1.04;
}

.content .topbar-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
}

.content .search {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.content .theme-btn,
.content .bell-btn,
.content .hamburger {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.content .bell-dropdown {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

/* --- Sidebar ------------------------------------------------------------- */
.nav a {
  border: 1px solid transparent;
  transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.nav a.active {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary-hover);
  font-weight: 900;
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav a.active:hover {
  transform: none;
  background: var(--primary-soft);
}

.brand-mark {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.sidebar-card {
  background: linear-gradient(145deg, var(--surface), var(--surface-2));
}

.sidebar-card h2::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--fh-view);
  vertical-align: 2px;
}

/* --- Module shell and cards --------------------------------------------- */
.content .module-shell {
  display: grid;
  gap: 18px !important;
}

.content .module-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--fh-ui-radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  animation: slideUp .45s ease-out;
  min-width: 0;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.content .module-shell > .module-card:first-child,
.content .section-grid > .section-card:first-child {
  background:
    radial-gradient(circle at 100% 0%, var(--fh-view-soft), transparent 44%),
    var(--surface);
}

@media (hover: hover) and (pointer: fine) {
  .content .module-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
  }
}

.content .module-eyebrow,
.content .section-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .14em;
  line-height: 1.25;
  text-transform: uppercase;
}

.content .module-eyebrow::before,
.content .section-eyebrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fh-view);
  box-shadow: 0 0 0 4px var(--fh-view-soft);
  flex: 0 0 auto;
}

.content .module-title,
.content .section-title {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -.035em;
  line-height: 1.05;
  text-wrap: balance;
}

.content .section-title {
  font-size: 29px;
}

.content .module-text,
.content .section-text {
  margin: 0;
  max-width: 72ch;
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.65;
}

.content .module-text strong,
.content .section-text strong,
.content .module-card strong {
  color: var(--text);
}

.content .module-card h3 {
  letter-spacing: -.015em;
  line-height: 1.2;
}

.content .module-card > .module-text:only-child {
  max-width: none;
  padding: 24px 8px;
  text-align: center;
}

/* --- Inner rows and soft panels ---------------------------------------- */
.content .module-card div[style*="border-radius:10px"],
.content .module-card div[style*="border-radius:12px"] {
  border-radius: var(--fh-ui-radius-sm) !important;
}

.content .module-card div[style*="border:1px solid var(--border)"][style*="background:#fff;"] {
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
}

.content .module-card > div[style*="border-left:4px solid"] {
  border-radius: var(--fh-ui-radius-sm) !important;
}

.content .module-card .cta,
.content .module-card .secondary,
.content .module-card .btn-primary,
.content .module-card button[type="submit"] {
  align-self: center;
}

.content .module-card .secondary {
  background: var(--surface-2);
}

.content .module-card .secondary:hover {
  background: var(--primary-soft);
}

/* --- Forms -------------------------------------------------------------- */
.content form label {
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .01em;
}

.content form small,
.content form .hint {
  color: var(--muted);
}

.content input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(.search),
.content select:not(.search),
.content textarea:not(.search) {
  min-height: 42px;
  padding: 10px 12px !important;
  border: 1px solid var(--border) !important;
  border-radius: 13px !important;
  background: var(--surface-2) !important;
  color: var(--text) !important;
  font-family: inherit;
  box-shadow: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.content textarea {
  min-height: 88px;
  resize: vertical;
}

.content input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(.search):focus,
.content select:not(.search):focus,
.content textarea:not(.search):focus {
  outline: none;
  border-color: var(--fh-view) !important;
  box-shadow: 0 0 0 3px var(--fh-view-soft) !important;
  background: var(--surface) !important;
}

.content input::placeholder,
.content textarea::placeholder {
  color: var(--muted-2);
  font-weight: 600;
}

.content input[type="file"] {
  max-width: 100%;
  padding: 8px !important;
  border: 1px dashed var(--border) !important;
  border-radius: 13px !important;
  background: var(--surface-2) !important;
  color: var(--muted) !important;
  font-family: inherit;
  font-size: 12px;
}

.content input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.content input[type="file"]::file-selector-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.content input[type="checkbox"],
.content input[type="radio"] {
  accent-color: var(--primary);
}

/* --- Tables ------------------------------------------------------------- */
.content table {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--fh-ui-radius-sm);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  background: var(--surface-2);
}

.content th {
  padding: 10px 12px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-align: left;
  text-transform: uppercase;
}

.content td {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}

/* --- Notices ------------------------------------------------------------ */
.content .notice {
  background: var(--surface);
  border-radius: var(--fh-ui-radius-sm);
  box-shadow: var(--shadow-sm);
}

/* --- Family page sections ---------------------------------------------- */
.content .section-grid {
  display: grid;
  gap: 18px;
}

.content .section-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--fh-ui-radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.content .stat-chip,
.content .member-badge,
.content .mini-chip {
  font-weight: 900;
}

.content .stat-chip {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.content .conn-tile,
.content .member-card,
.content .summary-box {
  background: var(--surface-2);
  border-color: var(--border);
}

.content .conn-tile {
  border-radius: var(--fh-ui-radius-sm);
}

.content .member-card {
  border-radius: 18px;
}

.content .summary-box {
  border-radius: var(--fh-ui-radius-sm);
}

.content .member-badge {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.content .btn-primary {
  background: var(--primary);
  color: #fff;
}

.content .btn-primary:hover {
  background: var(--primary-hover);
}

.content .btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.content .field input,
.content .field textarea,
.content .manage-form input,
.content .manage-form select {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.content .field input:focus,
.content .field textarea:focus,
.content .manage-form input:focus,
.content .manage-form select:focus {
  outline: none;
  border-color: var(--fh-view);
  box-shadow: 0 0 0 3px var(--fh-view-soft);
}

/* --- Legacy AI lesson content ------------------------------------------ */
html[data-theme="dark"] .lesson-container {
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

html[data-theme="dark"] .lesson-h3 {
  color: var(--info);
  border-bottom-color: var(--info);
}

html[data-theme="dark"] .lesson-h4 {
  color: var(--primary);
  border-left-color: var(--primary);
}

html[data-theme="dark"] .lesson-paragraph,
html[data-theme="dark"] .lesson-list li {
  color: var(--text);
}

html[data-theme="dark"] .lesson-paragraph strong {
  color: var(--info);
}

html[data-theme="dark"] .lesson-paragraph em {
  color: var(--muted);
}

html[data-theme="dark"] .lesson-list {
  background: var(--surface-2);
  border-left-color: var(--sage);
}

/* --- Dark-mode normalisation for inline colours ------------------------- */
html[data-theme="dark"] .content [style*="background:#fff;"],
html[data-theme="dark"] .content [style*="background:#fff"],
html[data-theme="dark"] .content [style*="background:#ffffff"],
html[data-theme="dark"] .content [style*="background:#fcfbf8"],
html[data-theme="dark"] .content [style*="background:#fdfbf8"],
html[data-theme="dark"] .content [style*="background:#f8f9fa"],
html[data-theme="dark"] .content [style*="background:#f9f7f4"],
html[data-theme="dark"] .content [style*="background:#f4f1ec"],
html[data-theme="dark"] .content [style*="background:#f1efec"],
html[data-theme="dark"] .content [style*="background:#f4efe7"],
html[data-theme="dark"] .content [style*="background:#f4f1ea"],
html[data-theme="dark"] .content [style*="background:#f1ece3"] {
  background: var(--surface-2) !important;
}

html[data-theme="dark"] .content [style*="background:#eee"],
html[data-theme="dark"] .content [style*="background:#ddd"] {
  background: var(--surface-3) !important;
}

html[data-theme="dark"] .content [style*="background:#f4fbf6"],
html[data-theme="dark"] .content [style*="background:#e8f5ee"],
html[data-theme="dark"] .content [style*="background:#d9f2e3"] {
  background: var(--sage-soft) !important;
}

html[data-theme="dark"] .content [style*="background:#e4f1ef"],
html[data-theme="dark"] .content [style*="background:#eef7f5"],
html[data-theme="dark"] .content [style*="background:#eef6f6"],
html[data-theme="dark"] .content [style*="background:#f4faf9"],
html[data-theme="dark"] .content [style*="background:#eef9f7"],
html[data-theme="dark"] .content [style*="background:#e8f6f4"] {
  background: var(--primary-soft) !important;
}

html[data-theme="dark"] .content [style*="background:#fff4f4"],
html[data-theme="dark"] .content [style*="background:#fdf1f1"],
html[data-theme="dark"] .content [style*="background:#fdeeee"] {
  background: var(--danger-soft) !important;
}

html[data-theme="dark"] .content [style*="background:#fff8e8"],
html[data-theme="dark"] .content [style*="background:#fff8ec"],
html[data-theme="dark"] .content [style*="background:#fff6e8"],
html[data-theme="dark"] .content [style*="background:#fdf6e3"],
html[data-theme="dark"] .content [style*="background:#fdf8ec"] {
  background: var(--amber-soft) !important;
}

html[data-theme="dark"] .content [style*="background:#f4f1fb"],
html[data-theme="dark"] .content [style*="background:#ece8f7"] {
  background: var(--plum-soft) !important;
}

html[data-theme="dark"] .content [style*="background:#eef4fb"],
html[data-theme="dark"] .content [style*="background:#dbeafe"],
html[data-theme="dark"] .content [style*="background:#f6f8fb"] {
  background: var(--blue) !important;
}

html[data-theme="dark"] .content [style*="color:#8a2d2d"],
html[data-theme="dark"] .content [style*="color:#a04444"] {
  color: var(--danger) !important;
}

html[data-theme="dark"] .content [style*="color:#256245"] {
  color: var(--sage) !important;
}

html[data-theme="dark"] .content [style*="color:#0a7272"],
html[data-theme="dark"] .content [style*="color:#0d6b6f"],
html[data-theme="dark"] .content [style*="color:#1f6f66"] {
  color: var(--primary) !important;
}

html[data-theme="dark"] .content [style*="color:#8a6a1f"],
html[data-theme="dark"] .content [style*="color:#8a6d1a"],
html[data-theme="dark"] .content [style*="color:#8a6414"],
html[data-theme="dark"] .content [style*="color:#b45309"] {
  color: var(--amber) !important;
}

html[data-theme="dark"] .content [style*="color:#2563eb"],
html[data-theme="dark"] .content [style*="color:#2b4d8f"] {
  color: var(--info) !important;
}

html[data-theme="dark"] .content [style*="color:#5b4a8a"] {
  color: var(--plum) !important;
}

html[data-theme="dark"] .content [style*="color:#5c5650"],
html[data-theme="dark"] .content [style*="color:#5b564f"],
html[data-theme="dark"] .content [style*="color:#4f4942"],
html[data-theme="dark"] .content [style*="color:#3c3831"],
html[data-theme="dark"] .content [style*="color:#1a202c"],
html[data-theme="dark"] .content [style*="color:#2d3748"],
html[data-theme="dark"] .content [style*="color:#446"] {
  color: var(--text) !important;
}

html[data-theme="dark"] .content [style*="color:#736d65"],
html[data-theme="dark"] .content [style*="color:#6d665e"],
html[data-theme="dark"] .content [style*="color:#6a645e"],
html[data-theme="dark"] .content [style*="color:#5c6b68"],
html[data-theme="dark"] .content [style*="color:#718096"],
html[data-theme="dark"] .content [style*="color:#4a5568"],
html[data-theme="dark"] .content [style*="color:#665"],
html[data-theme="dark"] .content [style*="color:#667"],
html[data-theme="dark"] .content [style*="color:#8a857d"] {
  color: var(--muted) !important;
}

html[data-theme="dark"] .content [style*="color:#a0aec0"] {
  color: var(--muted-2) !important;
}

html[data-theme="dark"] .content [style*="border:1px solid #e7c9c9"],
html[data-theme="dark"] .content [style*="border:1px solid #e8bcbc"] {
  border-color: var(--danger-border) !important;
}

html[data-theme="dark"] .content [style*="border:1px solid #cfe4d8"],
html[data-theme="dark"] .content [style*="border:1px solid #bcd9c6"] {
  border-color: var(--sage) !important;
}

html[data-theme="dark"] .content [style*="border:1px solid #cfe6e2"],
html[data-theme="dark"] .content [style*="border:1px solid #bfe0dc"],
html[data-theme="dark"] .content [style*="border:1px solid #dde8e6"],
html[data-theme="dark"] .content [style*="border:1px solid #e2e8f0"] {
  border-color: var(--border) !important;
}

html[data-theme="dark"] .content [style*="border:1px solid #f0e0a8"],
html[data-theme="dark"] .content [style*="border:1px solid #ecd3a5"] {
  border-color: var(--amber) !important;
}

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 900px) {
  .content .module-card,
  .content .section-card {
    padding: 21px;
  }
}

@media (max-width: 760px) {
  .content .topbar-heading.home-title {
    display: none !important;
  }

  .content .topbar-title-row {
    gap: 10px;
  }

  .content .topbar-icon {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    font-size: 21px;
  }

  .content .topbar-title {
    font-size: 24px !important;
  }

  .content .topbar-subtitle {
    font-size: 12px !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  .content .module-shell,
  .content .section-grid {
    gap: 14px !important;
  }

  .content .conn-grid {
    grid-template-columns: 1fr;
  }

  .content .module-card,
  .content .section-card {
    padding: 18px;
    border-radius: 20px;
  }

  .content .module-title,
  .content .section-title {
    font-size: 26px;
  }

  .content .module-shell > .module-card:first-child .module-title {
    font-size: clamp(25px, 7vw, 30px) !important;
  }

  .content input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(.search),
  .content select:not(.search),
  .content textarea:not(.search) {
    font-size: 16px !important;
  }

  .content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .content .module-card,
  .content .section-card,
  .content .topbar-icon {
    animation: none !important;
    transition: none !important;
  }
}
