@import url("/shared/base.css");

/* ── Additional variables ──────────────────────────────────────────────── */
:root {
  --bg-input-focus: #fff;
  --logo-filter: none;
  --avatar-bg: #e8eefc;
  --avatar-text: #2555ef;
}
html.dark {
  --bg-input-focus: #1a1a2e;
  --logo-filter: brightness(1.5) saturate(0.8);
  --avatar-bg: rgba(64,104,215,0.22);
  --avatar-text: #8aa6f0;
}
@media (prefers-color-scheme: dark) {
  html:not(.light):not(.dark) {
    --bg-input-focus: #1a1a2e;
    --logo-filter: brightness(1.5) saturate(0.8);
    --avatar-bg: rgba(64,104,215,0.22);
    --avatar-text: #8aa6f0;
  }
}

body { height: 100vh; overflow: hidden; }

/* ── Theme toggle ──────────────────────────────────────────────────────── */
.theme-toggle {
  display: inline-flex; gap: 4px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px;
}
.theme-toggle button {
  background: transparent; border: none; padding: 4px 8px;
  cursor: pointer; border-radius: 4px; color: var(--text-secondary); font-size: 0.95em;
}
.theme-toggle button:hover { background: var(--bg-hover); }
.theme-toggle button.active { background: var(--accent); color: #fff; }

/* ── Login ─────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg-page);
}
.login-card {
  background: var(--bg-surface); border-radius: 12px; padding: 40px;
  box-shadow: var(--shadow-card); width: 400px; max-width: 92vw; text-align: center;
}
.login-card img.logo { height: 36px; margin-bottom: 16px; filter: var(--logo-filter); }
.login-card h1 { font-size: 22px; margin-bottom: 4px; color: var(--text-heading); font-weight: 600; }
.login-card p.sub { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; font-weight: 300; }
.login-card input[type="email"], .login-card input[type="password"] {
  width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 16px; margin-bottom: 12px; outline: none;
  background: var(--bg-input); font-family: inherit; color: var(--text-primary);
}
.login-card input:focus { border-color: var(--accent); background: var(--bg-input-focus); }
.login-card button[type="submit"] {
  width: 100%; padding: 12px; border: none; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; font-family: inherit;
}
.login-card button[type="submit"]:hover { background: var(--accent-hover); }
.login-card button[type="submit"]:disabled { background: var(--accent-disabled); cursor: not-allowed; }
.login-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }

.conn-status { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 16px; font-size: 12px; color: var(--text-muted); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.conn-dot.checking { background: var(--warning); }
.conn-dot.connected { background: var(--success); }
.conn-dot.disconnected { background: var(--error); }
.error-msg { color: var(--error); font-size: 13px; margin-bottom: 12px; min-height: 16px; }

/* ── App layout ────────────────────────────────────────────────────────── */
#app-screen { display: none; flex-direction: column; height: 100vh; }
#app-screen.active { display: flex; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left img { height: 28px; filter: var(--logo-filter); }
.header-left h1 { font-size: 18px; color: var(--text-heading); font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }
#user-display { font-size: 13px; color: var(--text-muted); }
.hdr-btn { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 15px; }
.hdr-btn:hover { background: var(--bg-hover); }

.controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.controls #search {
  flex: 0 1 300px; min-width: 180px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-input); color: var(--text-primary); font-family: inherit; font-size: 14px;
}
.controls #search:focus { outline: none; border-color: var(--accent); background: var(--bg-input-focus); }
.spacer { flex: 1; }
.count { font-size: 13px; color: var(--text-muted); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--bg-surface); border: none; padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--text-secondary); font-family: inherit; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: #fff; }

.cols-menu { position: relative; }
.cols-menu summary { list-style: none; cursor: pointer; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--bg-surface); color: var(--text-secondary); }
.cols-menu summary::-webkit-details-marker { display: none; }
.cols-list {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-card); padding: 8px; display: flex; flex-direction: column; gap: 4px; white-space: nowrap;
}
.cols-list label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-body); cursor: pointer; }

.print-btn { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 8px 16px; cursor: pointer; font-size: 14px; font-weight: 600; font-family: inherit; }
.print-btn:hover { background: var(--accent-hover); }

/* ── Roster ────────────────────────────────────────────────────────────── */
.roster-wrap { flex: 1; overflow: auto; padding: 20px; background: var(--bg-page); }
.status-msg { text-align: center; color: var(--text-muted); padding: 40px; font-size: 14px; }

table.roster { width: 100%; table-layout: fixed; border-collapse: collapse; background: var(--bg-surface); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow-card); }
table.roster th, table.roster td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border-light); font-size: 13px; vertical-align: middle; overflow-wrap: anywhere; }
table.roster th { background: var(--bg-muted); color: var(--text-heading); font-weight: 600; position: sticky; top: 0; }
table.roster tbody tr:hover { background: var(--bg-hover); }
table.roster td.col-photo, table.roster th.col-photo { width: 44px; }

/* Family sections */
.fam-group { background: var(--bg-surface); border-radius: 10px; box-shadow: var(--shadow-card); margin-bottom: 16px; overflow: hidden; break-inside: avoid; }
.fam-head { display: flex; align-items: baseline; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg-muted); }
.fam-name { font-weight: 600; color: var(--text-heading); font-size: 15px; }
.fam-meta { font-size: 12px; color: var(--text-muted); }
.fam-group table.roster { box-shadow: none; border-radius: 0; }
.fam-group table.roster th { position: static; }

/* Avatars */
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--avatar-bg); display: inline-block; vertical-align: middle; }
.avatar-fallback {
  width: 32px; height: 32px; border-radius: 50%; background: var(--avatar-bg); color: var(--avatar-text);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; vertical-align: middle;
}

.muted { color: var(--text-muted); }

/* Print-only / no-print visibility (screen defaults) */
.print-only { display: none; }

/* ── Print styles ──────────────────────────────────────────────────────── */
@media print {
  @page { margin: 14mm; }
  html, body { height: auto; overflow: visible; background: #fff; color: #000; }
  #login-screen { display: none !important; }
  #app-screen { display: block !important; height: auto; }
  .no-print { display: none !important; }
  .print-only { display: block; }

  .roster-wrap { overflow: visible; padding: 0; background: #fff; }
  .status-msg { display: none; }

  .print-header { text-align: center; margin-bottom: 12px; }
  .print-header .ph-title { font-size: 20px; font-weight: 700; color: #000; }
  .print-header .ph-sub { font-size: 11px; color: #333; margin-top: 2px; }
  .print-footer { margin-top: 12px; text-align: center; font-size: 10px; color: #555; }

  table.roster { box-shadow: none; border-radius: 0; background: #fff; }
  table.roster thead { display: table-header-group; }
  table.roster th { background: #fff; color: #000; border-bottom: 1.5px solid #000; position: static; }
  table.roster td { border-bottom: 1px solid #bbb; color: #000; }
  table.roster tbody tr { break-inside: avoid; }

  .fam-group { box-shadow: none; border: 1px solid #999; margin-bottom: 10px; break-inside: avoid; }
  .fam-head { background: #f0f0f0; }
  .fam-name, .fam-meta { color: #000; }

  /* Ensure avatars print with their colors */
  .avatar, .avatar-fallback {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    width: 30px; height: 30px;
  }
  .muted { color: #444; }
  a { color: #000; text-decoration: none; }
}
