/**
 * shared.css — FamilyFolio global design tokens & shell components
 *
 * Loaded by every app page. Contains:
 *   • CSS custom properties (:root)
 *   • Reset + base typography
 *   • Shell layout (sidebar, topbar, page-content)
 *   • Primitive components (buttons, badges, modal, form, toast, stat-cards, loading)
 *   • Responsive breakpoints
 *
 * Page-specific styles stay in each page's own <style> block.
 */

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Design tokens ──────────────────────────────────────────── */
:root {
  --color-bg:            #F7F8F9;
  --color-surface:       #FFFFFF;
  --color-border:        #DFE1E6;
  --color-border-focus:  #5165C2;
  --color-text:          #172B4D;
  --color-text-subtle:   #6B778C;
  --color-text-disabled: #A5ADBA;

  --color-blue:          #5165C2;
  --color-blue-dark:     #3D4FA8;
  --color-blue-subtle:   #ECEFFE;

  --color-red:           #DE350B;
  --color-red-subtle:    #FFEBE6;

  --color-green:         #4E7925;
  --color-green-dark:    #006644;
  --color-green-subtle:  #E3FCEF;

  --color-yellow:        #FF991F;
  --color-yellow-subtle: #FFFAE6;

  --color-purple:        #6554C0;
  --color-purple-subtle: #F3F0FF;

  --color-teal:          #00875A;
  --color-teal-subtle:   #E3FCEF;

  --sidebar-bg:          #172B4D;
  --sidebar-hover:       #253858;
  --sidebar-active:      #1D3461;

  --shadow-e100: 0 1px 1px rgba(9,30,66,0.25), 0 0 1px rgba(9,30,66,0.31);
  --shadow-e200: 0 3px 5px rgba(9,30,66,0.2),  0 0 1px rgba(9,30,66,0.31);
  --shadow-e400: 0 8px 16px rgba(9,30,66,0.15), 0 0 1px rgba(9,30,66,0.31);

  --radius-sm: 3px;
  --radius:    8px;
  --sidebar-w: 220px;
  --topbar-h:  56px;
}

/* ─── Base ───────────────────────────────────────────────────── */
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  background: var(--color-bg); color: var(--color-text);
  font-size: 14px; line-height: 20px; -webkit-font-smoothing: antialiased;
}

/* ─── Shell layout ───────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }
.main   { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ─── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); background: var(--color-blue);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
  box-shadow: var(--shadow-e200); flex-shrink: 0;
}
.topbar-left     { flex: 1; }
.topbar-title    { font-size: 14px; font-weight: 600; color: white; }
.topbar-subtitle { font-size: 12px; color: rgba(255,255,255,0.7); }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.12); border-radius: var(--radius-sm);
  padding: 5px 10px; cursor: pointer; transition: background .12s;
}
.user-chip:hover { background: rgba(255,255,255,0.18); }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; color: white; }
.btn-logout {
  padding: 5px 12px; background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.2); border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: background .12s;
}
.btn-logout:hover { background: rgba(255,255,255,0.22); color: white; }

/* ─── Page chrome ────────────────────────────────────────────── */
.page-content      { flex: 1; overflow-y: auto; }
.page-header       { background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.page-header-inner { padding: 18px 28px 20px; }
.page-title-row    { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
h1                 { font-size: 20px; font-weight: 500; color: var(--color-text); letter-spacing: -0.2px; line-height: 28px; }
h1 em              { font-style: normal; color: var(--color-blue); font-weight: 700; }
.page-subtitle     { font-size: 13px; color: var(--color-text-subtle); margin-top: 2px; }
.inner             { padding: 20px 28px 40px; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; background: var(--color-blue); color: white;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .12s; text-decoration: none;
}
.btn-primary:hover    { background: var(--color-blue-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  padding: 4px 10px; background: transparent; color: var(--color-text-subtle);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: background .12s, color .12s;
}
.btn-ghost:hover { background: var(--color-bg); color: var(--color-text); }
.btn-danger {
  padding: 4px 10px; background: transparent; color: var(--color-red);
  border: 1px solid var(--color-red); border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; font-family: inherit; cursor: pointer;
  transition: background .12s;
}
.btn-danger:hover { background: var(--color-red-subtle); }

/* ─── Icon buttons ───────────────────────────────────────────── */
.icon-btn {
  position: relative;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: none; background: transparent;
  cursor: pointer; color: var(--color-text-subtle); transition: background .12s, color .12s;
}
.icon-btn:hover             { background: var(--color-bg); color: var(--color-text); }
.icon-btn.danger:hover      { background: var(--color-red-subtle); color: var(--color-red); }
.icon-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: rgba(17,24,39,0.88); color: white;
  font-size: 11px; font-weight: 500; white-space: nowrap;
  padding: 3px 8px; border-radius: 4px;
  pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 10;
}
.icon-btn[data-tooltip]:hover::after { opacity: 1; }

/* ─── Stat cards ─────────────────────────────────────────────── */
.cards-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius); box-shadow: var(--shadow-e100); padding: 16px 18px;
}
.stat-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--color-text-subtle); margin-bottom: 6px;
}
.stat-value         { font-size: 22px; font-weight: 600; color: var(--color-text); letter-spacing: -0.3px; }
.stat-value.red     { color: var(--color-red); }
.stat-value.green   { color: var(--color-green); }
.stat-value.blue    { color: var(--color-blue); }
.stat-value.purple  { color: var(--color-purple); }
.stat-sub           { font-size: 12px; color: var(--color-text-disabled); margin-top: 2px; }

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  padding: 2px 7px; border-radius: var(--radius-sm); white-space: nowrap;
}
.badge-blue   { background: var(--color-blue-subtle);   color: var(--color-blue-dark); }
.badge-purple { background: var(--color-purple-subtle); color: var(--color-purple); }
.badge-yellow { background: var(--color-yellow-subtle); color: #974F0C; }
.badge-green  { background: var(--color-green-subtle);  color: var(--color-green); }
.badge-red    { background: var(--color-red-subtle);    color: var(--color-red); }
.badge-gray   { background: #F1F2F4;                    color: var(--color-text-subtle); }
.badge-teal   { background: var(--color-teal-subtle);   color: var(--color-teal); }

/* ─── Loading overlay ────────────────────────────────────────── */
#loadingOverlay {
  position: fixed; inset: 0; background: var(--color-blue);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 9999; gap: 14px;
}
.loading-logo      { display: flex; align-items: center; gap: 10px; }
.loading-logo-icon {
  width: 32px; height: 32px; background: rgba(255,255,255,0.2); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.loading-logo-text { font-size: 17px; font-weight: 700; color: white; }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(9,30,66,0.54);
  z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--color-surface); border-radius: var(--radius);
  box-shadow: var(--shadow-e400); width: 100%; max-width: 540px;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  padding: 18px 22px 14px; flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px; border: none; background: none;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--color-text-subtle);
  display: flex; align-items: center; justify-content: center; transition: background .12s;
}
.modal-close:hover { background: var(--color-bg); color: var(--color-text); }
.modal-body   { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px; flex-shrink: 0; border-top: 1px solid var(--color-border);
  display: flex; gap: 8px; justify-content: flex-end; background: var(--color-surface);
}

/* ─── Form primitives ────────────────────────────────────────── */
.form-grid          { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span2   { grid-column: 1 / -1; }
.form-row-hidden    { display: none !important; }
.field              { display: flex; flex-direction: column; gap: 4px; }
.field label        { font-size: 12px; font-weight: 600; color: var(--color-text); }
.required-star      { color: var(--color-red); margin-left: 1px; }
.field input,
.field select {
  height: 36px; padding: 0 10px;
  border: 2px solid var(--color-border); border-radius: var(--radius-sm);
  background: #FAFBFC; font-size: 13px; font-family: inherit; color: var(--color-text);
  transition: border-color .12s, background .12s; width: 100%;
}
.field input:focus,
.field select:focus { outline: none; border-color: var(--color-border-focus); background: white; }
.field input.field-invalid,
.field select.field-invalid { border-color: var(--color-red); background: var(--color-red-subtle); }
.field input.field-invalid:focus,
.field select.field-invalid:focus { border-color: var(--color-red); background: white; }
.field textarea {
  padding: 8px 10px; min-height: 64px;
  border: 2px solid var(--color-border); border-radius: var(--radius-sm);
  background: #FAFBFC; font-size: 13px; font-family: inherit; color: var(--color-text);
  transition: border-color .12s, background .12s; width: 100%; resize: vertical; line-height: 18px;
}
.field textarea:focus { outline: none; border-color: var(--color-border-focus); background: white; }
.field textarea.field-invalid { border-color: var(--color-red); background: var(--color-red-subtle); }
.field-hint  { font-size: 11px; color: var(--color-text-subtle); }
.field-error { font-size: 11px; color: var(--color-red); display: none; margin-top: 1px; }
.field-error.visible { display: block; }
.section-divider {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--color-text-subtle);
  padding: 8px 0 4px; border-bottom: 1px solid var(--color-border);
  margin-bottom: 4px; grid-column: 1 / -1;
}
.field-readonly {
  height: 36px; padding: 0 10px;
  border: 2px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-bg); font-size: 13px; font-family: inherit;
  color: var(--color-text-subtle); display: flex; align-items: center;
  user-select: none; cursor: default;
}
.field-readonly.has-value {
  color: var(--color-green); font-weight: 600;
  background: var(--color-green-subtle); border-color: #b3dfa0;
}
.field-readonly.has-warn {
  color: var(--color-red); font-weight: 600;
  background: var(--color-red-subtle); border-color: #ffbdad;
}

/* ─── Confirm dialog ─────────────────────────────────────────── */
.confirm-backdrop {
  position: fixed; inset: 0; background: rgba(9,30,66,0.54);
  z-index: 1100; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.confirm-backdrop.hidden { display: none; }
.confirm-box {
  background: var(--color-surface); border-radius: var(--radius);
  box-shadow: var(--shadow-e400); width: 100%; max-width: 360px; padding: 24px;
}
.confirm-box h3     { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.confirm-box p      { font-size: 13px; color: var(--color-text-subtle); margin-bottom: 20px; line-height: 18px; }
.confirm-actions    { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--color-text); color: white;
  font-size: 13px; font-weight: 500; padding: 10px 16px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-e200);
  z-index: 2000; opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show    { opacity: 1; transform: translateY(0); }
#toast.error   { background: var(--color-red); }
#toast.success { background: #1A7F4B; }

/* ─── Empty state ────────────────────────────────────────────── */
.empty-wrap {
  background: var(--color-surface);
  border-radius: var(--radius); box-shadow: var(--shadow-e100);
  padding: 48px 24px; text-align: center;
}
.empty-icon-lg {
  width: 56px; height: 56px; background: var(--color-blue-subtle);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.empty-icon-lg svg { color: var(--color-blue); }
.empty-wrap h2 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-wrap p  { font-size: 13px; color: var(--color-text-subtle); max-width: 340px; margin: 0 auto 20px; line-height: 18px; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .cards-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  .form-grid        { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: 1; }
}
