/* ==========================================================================
   Amicia — base stylesheet
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1c2330;
  --text-muted: #5f6b7a;
  --text-subtle: #8a94a3;

  --primary: #3b5bdb;
  --primary-hover: #2f4ac0;
  --primary-soft: #edf1ff;
  --on-primary: #ffffff;

  --danger: #c92a2a;
  --danger-soft: #fff0f0;
  --success: #2b8a3e;
  --success-soft: #ebfbee;
  --warning: #a35f00;
  --warning-soft: #fff6e5;

  --nav-bg: #1f2633;
  --nav-text: #c9d1e0;

  --radius-sm: 3px;
  --radius: 4px;
  --radius-lg: 4px;
  --shadow: none;
  --shadow-lg: none;

  --content-width: 46rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1f28;
    --surface-muted: #202633;
    --border: #2c3442;
    --border-strong: #3a4456;
    --text: #e6e9ef;
    --text-muted: #a3adbd;
    --text-subtle: #7b8698;

    --primary: #6d8bff;
    --primary-hover: #8aa2ff;
    --primary-soft: #232c47;
    --on-primary: #0e1424;

    --danger: #ff8787;
    --danger-soft: #3a1f22;
    --success: #69db7c;
    --success-soft: #1d3324;
    --warning: #ffc078;
    --warning-soft: #3a2c17;

    --nav-bg: #0d1016;
    --nav-text: #a3adbd;

    --shadow: none;
    --shadow-lg: none;

    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; }
p { margin: 0; }

img { max-width: 100%; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); font-size: 0.875rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }

/* ---------- Layout ---------- */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--nav-bg);
  padding-top: env(safe-area-inset-top, 0px);
}

.main-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--content-width);
  height: 3.25rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.nav-left, .nav-right { display: flex; align-items: center; gap: 0.25rem; }

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 0.75rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem;
}

.nav-link {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
  font-weight: 500;
  font-size: 0.925rem;
}
.nav-link:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.nav-link.active { color: #fff; background: rgba(255, 255, 255, 0.12); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
}
.icon-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.icon-btn svg, .icon svg, svg.icon {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-user { display: flex; align-items: center; gap: 0.25rem; }
.nav-user .avatar { width: 2rem; height: 2rem; font-size: 0.85rem; border-radius: 50%; }
.nav-user a.avatar-link { border-radius: 50%; padding: 2px; }
.nav-user a.avatar-link:hover { background: rgba(255, 255, 255, 0.12); }
.nav-user a.avatar-link.active { box-shadow: 0 0 0 2px #fff; }

main {
  flex: 1;
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1.75rem 1rem 3rem;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-header p { margin-top: 0.25rem; }

.footer-bar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-subtle);
  font-size: 0.825rem;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0.9rem 1rem;
}
.footer-bar strong { color: var(--text-muted); font-weight: 600; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}
.card-header .count {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.4rem;
  margin-left: 0.4rem;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: middle;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--surface-muted); text-decoration: none; }
.btn svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-muted); color: var(--text); }

.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.825rem; }
.btn-lg { padding: 0.7rem 1.3rem; font-size: 1rem; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label, .field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.textarea { resize: vertical; min-height: 6rem; line-height: 1.5; }
.select { width: auto; padding-right: 2rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}
.form-grid .span-all { grid-column: 1 / -1; }

.form-section + .form-section { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.form-section h2 { margin-bottom: 1rem; }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}
.form-actions .spacer { margin-right: auto; }

.inline-input { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.inline-input .input { flex: 1 1 14rem; }

/* File picker */
.file-drop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.file-drop:hover, .file-drop:focus-within { border-color: var(--primary); background: var(--primary-soft); }
.file-drop input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop .icon svg { width: 1.4rem; height: 1.4rem; color: var(--primary); }
.file-drop strong { display: block; color: var(--text); font-weight: 600; }
.file-drop .file-names { font-size: 0.85rem; }

/* Segmented control (radio-based) */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 2px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.segmented label svg { width: 0.95rem; height: 0.95rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }
.segmented input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- Alerts ---------- */

.alert {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.925rem;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---------- Avatars & badges ---------- */

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  background: #7b8bb2;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  user-select: none;
}
.post-header .avatar { border-radius: 50%; }
.avatar-lg { width: 4.5rem; height: 4.5rem; font-size: 1.8rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge svg { width: 0.8rem; height: 0.8rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.badge-public { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-friends { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-private { background: var(--warning-soft); color: var(--warning); border-color: transparent; }

/* ---------- Feed ---------- */

.feed-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.feed { display: flex; flex-direction: column; gap: 1rem; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem 0.75rem;
}
.post-header { display: flex; align-items: center; gap: 0.75rem; }
.post-author { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.post-author-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-author-name:hover { text-decoration: underline; }
.post-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; color: var(--text-subtle); font-size: 0.8rem; }

.post-content {
  margin-top: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.975rem;
}

.post-images {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-top: 0.85rem;
  border-radius: var(--radius);
  overflow: hidden;
}
.post-images a { display: block; background: var(--surface-muted); }
.post-images img { display: block; width: 100%; height: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.post-images:has(> a:only-child) { grid-template-columns: 1fr; }
.post-images:has(> a:only-child) img { aspect-ratio: auto; max-height: 32rem; object-fit: contain; }
.post-images:has(> a:nth-child(3):last-child) > a:first-child { grid-column: 1 / -1; }
.post-images:has(> a:nth-child(3):last-child) > a:first-child img { aspect-ratio: 2 / 1; }

.post-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  color: var(--text-subtle);
  font-size: 0.875rem;
}
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.end-of-feed { text-align: center; color: var(--text-subtle); font-size: 0.85rem; padding: 0.5rem 0 0; }

/* ---------- Empty states & hero ---------- */

.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--text-muted);
}
.empty-state .icon svg { width: 2.5rem; height: 2.5rem; color: var(--text-subtle); stroke-width: 1.5; }
.empty-state h2 { margin: 0.75rem 0 0.35rem; color: var(--text); }
.empty-state .btn { margin-top: 1.1rem; }
.empty-inline { color: var(--text-subtle); font-size: 0.9rem; padding: 0.25rem 0; }

.hero {
  text-align: center;
  padding: 3.5rem 1.5rem;
}
.hero .brand-mark { width: 3.5rem; height: 3.5rem; border-radius: var(--radius); font-size: 1.8rem; margin: 0 auto 1.25rem; }
.hero h1 { font-size: 2.1rem; letter-spacing: -0.02em; }
.hero p { max-width: 30rem; margin: 0.75rem auto 1.75rem; color: var(--text-muted); font-size: 1.05rem; }
.feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.feature { text-align: left; }
.feature .icon svg { width: 1.4rem; height: 1.4rem; color: var(--primary); }
.feature h2 { font-size: 1rem; margin: 0.5rem 0 0.25rem; }
.feature p { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- People lists ---------- */

.person-list { list-style: none; margin: 0; padding: 0; }
.person {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--border);
}
.person:first-child { border-top: none; padding-top: 0; }
.person:last-child { padding-bottom: 0; }
.person-info { flex: 1; min-width: 0; }
.person-name { font-weight: 600; color: var(--text); }
a.person-name:hover { color: var(--primary); }
.person-email { color: var(--text-subtle); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-note {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  overflow-wrap: anywhere;
}
.person-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Profile ---------- */

.profile-header { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.profile-header .identity { flex: 1; min-width: 12rem; }
.profile-header h1 { font-size: 1.45rem; }

.details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 1.5rem;
  margin: 0;
}
.details dt { color: var(--text-muted); font-size: 0.875rem; font-weight: 500; }
.details dd { margin: 0; overflow-wrap: anywhere; }

.note-display {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-muted);
  font-style: italic;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: 1rem;
}

/* ---------- Prose (help) ---------- */

.prose h2 { margin: 1.5rem 0 0.5rem; }
.prose h2:first-child { margin-top: 0; }
.prose p, .prose ul { color: var(--text-muted); }
.prose ul { padding-left: 1.2rem; margin: 0.5rem 0; }
.prose li + li { margin-top: 0.35rem; }
.prose strong { color: var(--text); }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .brand-text { display: none; }
  .brand { margin-right: 0.25rem; }
  .nav-link { padding: 0.4rem 0.55rem; }
  main { padding-top: 1.25rem; }
  .details { grid-template-columns: 1fr; gap: 0.1rem; }
  .details dd { margin-bottom: 0.6rem; }
  .person { flex-wrap: wrap; }
  .person-actions { width: 100%; justify-content: flex-start; padding-left: 3.25rem; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; }
  .form-actions .spacer { flex-basis: 100%; }
}

/* ---------- Small utilities used by templates ---------- */

.form-actions-tight { margin-top: 0; }
.split-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.split-row p { flex: 1 1 16rem; }

/* ---------- Post edit: existing media ---------- */

.media-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 0.5rem;
}
.media-edit-item {
  position: relative;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-muted);
}
.media-edit-item img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.media-edit-item input { position: absolute; top: 0.4rem; left: 0.4rem; width: 1rem; height: 1rem; margin: 0; cursor: pointer; }
.media-remove-tag {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 0.2rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: var(--danger);
  visibility: hidden;
}
.media-edit-item:has(input:checked) { border-color: var(--danger); }
.media-edit-item:has(input:checked) img { opacity: 0.35; filter: grayscale(1); }
.media-edit-item:has(input:checked) .media-remove-tag { visibility: visible; }

/* htmx request indicators (htmx's own inline styles are disabled for the CSP, see layout.hbs). */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }

/* Profile: visibility setting and account deletion. */
.checkbox-field { display: flex; gap: 0.75rem; align-items: flex-start; cursor: pointer; }
.checkbox-field input { margin-top: 0.25rem; }
.checkbox-field .subtle { display: block; margin-top: 0.25rem; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.danger-zone { border-color: var(--danger); }
