:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #efece4;
  --border: #e0dbcd;
  --text: #262420;
  --text-dim: #736c5e;
  --accent: #3d4b8c;
  --accent-hover: #2f3b70;
  --accent-soft: #e8eaf5;
  --amber: #c97a2b;
  --danger: #b3392c;
  --danger-bg: #fbeae7;
  --ok: #2f7a4f;
  --ok-bg: #e7f3ea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30,26,14,0.06), 0 8px 24px rgba(30,26,14,0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181a;
    --surface: #222124;
    --surface-2: #2b2a2d;
    --border: #38363a;
    --text: #eeece7;
    --text-dim: #a29c8f;
    --accent: #7684d6;
    --accent-hover: #8d99e0;
    --accent-soft: #262a44;
    --amber: #e0995a;
    --danger: #e17567;
    --danger-bg: #3a2320;
    --ok: #6bc890;
    --ok-bg: #1c3327;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #18181a; --surface: #222124; --surface-2: #2b2a2d; --border: #38363a;
  --text: #eeece7; --text-dim: #a29c8f; --accent: #7684d6; --accent-hover: #8d99e0;
  --accent-soft: #262a44; --amber: #e0995a; --danger: #e17567; --danger-bg: #3a2320;
  --ok: #6bc890; --ok-bg: #1c3327; --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
}
:root[data-theme="light"] {
  --bg: #f7f5f0; --surface: #ffffff; --surface-2: #efece4; --border: #e0dbcd;
  --text: #262420; --text-dim: #736c5e; --accent: #3d4b8c; --accent-hover: #2f3b70;
  --accent-soft: #e8eaf5; --amber: #c97a2b; --danger: #b3392c; --danger-bg: #fbeae7;
  --ok: #2f7a4f; --ok-bg: #e7f3ea; --shadow: 0 1px 2px rgba(30,26,14,0.06), 0 8px 24px rgba(30,26,14,0.06);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
a { color: inherit; }
button, input, select { font-family: inherit; }
.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.hidden { display: none !important; }

/* ---------- Auth screen ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% -10%, rgba(61,75,140,0.10), transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px 26px;
}
.auth-card .brand { font-size: 26px; margin: 0 0 2px; }
.auth-card .tagline { color: var(--text-dim); font-size: 13.5px; margin: 0 0 24px; }
.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
input[type=text], input[type=password], select {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
input:focus-visible, select:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 14.5px;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { filter: brightness(1.08); }
.msg { margin-top: 14px; padding: 11px 12px; border-radius: 9px; font-size: 13.5px; line-height: 1.5; }
.msg.error { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-size: 19px; color: var(--accent); flex: none; }
.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-dim);
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 14px; padding: 4px 6px; border-radius: 6px; font-family: inherit;
}
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs button.current { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--border); }
.user-menu { position: relative; flex: none; }
.user-chip {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 20px; padding: 6px 12px 6px 6px;
  cursor: pointer; font-size: 13.5px; color: var(--text);
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex: none;
}
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  min-width: 190px; overflow: hidden; z-index: 30;
}
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left; padding: 10px 14px; font-size: 14px;
  background: none; border: none; cursor: pointer; color: var(--text); text-decoration: none;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--surface-2); }
.user-dropdown .divider { height: 1px; background: var(--border); margin: 4px 0; }

main { flex: 1; padding: 18px; max-width: 1100px; width: 100%; margin: 0 auto; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 18px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  position: relative;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.tile:hover { border-color: var(--accent); }
.tile .tab {
  position: absolute; top: 0; left: 14px; width: 30px; height: 6px;
  border-radius: 0 0 4px 4px;
}
.tile .thumb {
  height: 84px; border-radius: 8px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  color: var(--text-dim); font-size: 28px;
}
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.tile .name { font-size: 13px; font-weight: 600; word-break: break-word; line-height: 1.3; }
.tile .meta { font-size: 11.5px; color: var(--text-dim); }
.tile .actions {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 4px;
  opacity: 0; transition: opacity 0.1s;
}
.tile:hover .actions, .tile:focus-within .actions { opacity: 1; }
.icon-btn {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.empty {
  text-align: center; padding: 60px 20px; color: var(--text-dim);
}
.empty .big { font-size: 34px; margin-bottom: 10px; }

.upload-list { margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.upload-row { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.upload-row .name { font-weight: 600; margin-bottom: 5px; display: flex; justify-content: space-between; gap: 8px; }
.upload-row .bar-bg { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.upload-row .bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.15s; }
.upload-row.done .bar { background: var(--ok); }
.upload-row.error .bar { background: var(--danger); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,18,12,0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 380px; padding: 22px 22px 18px; border: 1px solid var(--border);
}
.modal h2 { font-size: 16px; margin: 0 0 14px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Add family member ---------- */
.role-preview {
  display: flex; gap: 9px; align-items: flex-start; margin-top: 10px; padding: 11px 12px;
  border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-dim); line-height: 1.4;
}
.role-preview strong { color: var(--text); }
.role-preview .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--accent); }
.pw-row { display: flex; gap: 8px; }
.pw-row input { flex: 1; min-width: 0; }
.credentials { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.cred-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cred-copy { border: none; background: none; color: inherit; text-decoration: underline; cursor: pointer; font-size: 12.5px; padding: 0; }
code { background: rgba(127,127,127,0.16); padding: 1px 6px; border-radius: 5px; font-size: 13px; }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
}
