/* ===================================================================
   HobbyHub – Prototyp
   =================================================================== */

:root {
  --color-bg: #f7f7f5;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f0ec;
  --color-text: #141413;
  --color-text-secondary: #52514e;
  --color-border: #e4e3de;

  --color-primary: #2a78d6;
  --color-primary-dark: #1d5fae;
  --color-primary-tint: #e8f1fc;

  --color-accent: #eb6834;
  --color-accent-tint: #fdeee6;

  --color-success: #1baf7a;
  --color-success-dark: #128a5f;
  --color-success-tint: #e4f7ef;

  --color-danger: #e34948;
  --color-danger-tint: #fcebea;

  --color-violet: #4a3aa7;

  --avatar-colors: #2a78d6, #eb6834, #008300, #4a3aa7, #e34948;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 3px rgba(20, 20, 19, 0.08);
  --shadow-md: 0 6px 20px rgba(20, 20, 19, 0.10);
  --shadow-lg: 0 20px 50px rgba(20, 20, 19, 0.22);

  --nav-height: 68px;
  --topbar-height: 56px;

  --motion-fast: 140ms;
  --motion-med: 220ms;
  color-scheme: light;
}

html[data-contrast="high"] {
  --color-bg: #000000;
  --color-surface: #111111;
  --color-surface-alt: #1c1c1c;
  --color-text: #ffffff;
  --color-text-secondary: #f0f0f0;
  --color-border: #ffffff;

  --color-primary: #6cb0ff;
  --color-primary-dark: #a9d2ff;
  --color-primary-tint: #0d2744;

  --color-accent: #ffab7a;
  --color-accent-tint: #3a1f10;

  --color-success: #5be8b5;
  --color-success-dark: #8ff2cc;
  --color-success-tint: #0f3328;

  --color-danger: #ff8d8c;
  --color-danger-tint: #3a1414;

  --color-violet: #b7a9ff;
  color-scheme: dark;
}

html[data-fontsize="large"] { font-size: 118%; }
html[data-fontsize="xlarge"] { font-size: 136%; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #d9d9d4;
  color: var(--color-text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

html[data-contrast="high"] body { background: #000; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- App shell / phone frame ---------- */

.app-shell {
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  background: var(--color-bg);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 760px) {
  body { padding: 36px 0; }
  .app-shell {
    min-height: 860px;
    height: 860px;
    border-radius: 44px;
    border: 10px solid #161616;
    box-shadow: var(--shadow-lg);
  }
}

/* ---------- Top bar ---------- */

.topbar {
  height: var(--topbar-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 5;
}

.topbar-brand { display: flex; align-items: center; gap: 8px; }
.topbar-logo { border-radius: 7px; display: block; }
.topbar-title { font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; }

.topbar-a11y {
  width: 36px; height: 36px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.topbar-a11y:hover { background: var(--color-primary-tint); border-color: var(--color-primary); }

/* ---------- Screen area ---------- */

.screen-area {
  flex: 1 1 auto;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.view { display: none; height: 100%; }
.view.active { display: block; }

.screen-pad { padding: 20px 18px calc(28px + var(--nav-height)); }
.screen-pad-h { padding-left: 18px; padding-right: 18px; }

.screen-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 4px 0 6px;
}
.screen-subtitle {
  color: var(--color-text-secondary);
  font-size: 0.94rem;
  line-height: 1.45;
  margin: 0 0 20px;
}

/* ---------- Fields / inputs ---------- */

.field { margin-bottom: 18px; }
.field label, .field-label-standalone {
  display: block;
  font-weight: 650;
  font-size: 0.88rem;
  margin-bottom: 7px;
  color: var(--color-text);
}

input[type="text"], input[type="date"], select {
  width: 100%;
  font-size: 1rem;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}
input[readonly] { background: var(--color-surface-alt); color: var(--color-text-secondary); }

input:focus-visible, select:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
  height: 32px;
  cursor: pointer;
}

.range-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--color-text-secondary);
  margin-top: -4px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.96rem;
  border-radius: var(--radius-md);
  border: none;
  padding: 13px 18px;
  cursor: pointer;
  transition: transform var(--motion-fast) ease, filter var(--motion-fast) ease, background var(--motion-fast) ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px 18px; font-size: 1.02rem; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; border-radius: var(--radius-pill); }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { background: var(--color-success); cursor: default; }

.btn-secondary { background: var(--color-surface-alt); color: var(--color-text); border: 1.5px solid var(--color-border); }
.btn-secondary:hover { border-color: var(--color-primary); }

.btn-danger-outline { background: transparent; color: var(--color-danger); border: 1.5px solid var(--color-danger); }

.btn-icon { padding: 13px; aspect-ratio: 1; }

.btn-link {
  background: none; border: none; color: var(--color-primary);
  font-weight: 650; font-size: 0.9rem; cursor: pointer; padding: 4px 0;
}

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }

/* ---------- Cards / results list ---------- */

.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.result-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color var(--motion-fast) ease, transform var(--motion-fast) ease;
}
.result-card:hover { border-color: var(--color-primary); transform: translateY(-1px); }

.avatar {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 750;
  font-size: 0.92rem;
}
.avatar-lg { width: 60px; height: 60px; font-size: 1.15rem; }

.result-card-body { flex: 1 1 auto; min-width: 0; }
.result-card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.result-card-name { font-weight: 700; font-size: 1rem; }
.result-card-distance { font-size: 0.8rem; color: var(--color-text-secondary); white-space: nowrap; }
.result-card-tags { display: flex; gap: 6px; margin: 4px 0 6px; flex-wrap: wrap; }
.result-card-bio { font-size: 0.86rem; color: var(--color-text-secondary); line-height: 1.4; margin: 0; }

.tag {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 650;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
}
.tag-group { background: var(--color-accent-tint); color: var(--color-accent); }

.empty-state {
  color: var(--color-text-secondary);
  text-align: center;
  padding: 36px 20px;
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ---------- Discover screen ---------- */

.discover-screen { height: 100%; }
.discover-screen .filter-panel { padding: 18px; }
.discover-screen.is-filter-mode .results-panel { display: none; }
.discover-screen:not(.is-filter-mode) .filter-panel { display: none; }

.results-panel { padding: 16px 18px calc(24px + var(--nav-height)); }
.results-header { margin-bottom: 14px; }
.results-summary { margin: 6px 0 0; font-weight: 700; font-size: 1.02rem; }

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 0.72rem; color: var(--color-text-secondary); font-weight: 650; }
.stat-value { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: proportional-nums; }
.stat-delta { font-size: 0.72rem; font-weight: 700; }
.stat-delta-up { color: var(--color-success-dark); }

/* ---------- Blocks ---------- */

.block { margin-bottom: 26px; }
.block-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.block-title { font-size: 1.08rem; font-weight: 750; margin: 0 0 10px; }
.block-header-row .block-title { margin-bottom: 0; }
.block-hint { font-size: 0.85rem; color: var(--color-text-secondary); margin: -4px 0 10px; }

/* request / event cards */

.request-card, .event-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 13px 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.request-card-body, .event-card-body { flex: 1 1 auto; min-width: 0; }
.request-name { font-weight: 700; font-size: 0.96rem; }
.request-note { font-size: 0.84rem; color: var(--color-text-secondary); margin: 2px 0 10px; line-height: 1.4; }
.request-actions { display: flex; gap: 8px; }

.event-title { font-weight: 700; font-size: 0.96rem; }
.event-meta { font-size: 0.82rem; color: var(--color-text-secondary); margin-top: 2px; }

.invite-row { display: flex; gap: 8px; }
.invite-row input { flex: 1 1 auto; }

/* ---------- Chip group ---------- */

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 0.85rem;
  font-weight: 650;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.profile-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 26px;
  text-align: center;
}
.profile-card .avatar { margin: 0 auto 14px; }
.profile-card .field { text-align: left; }

/* ---------- Segmented control / switches ---------- */

.segmented { display: flex; border: 1.5px solid var(--color-border); border-radius: var(--radius-pill); overflow: hidden; }
.segmented-btn {
  flex: 1 1 auto;
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  padding: 10px 4px;
  font-size: 0.84rem;
  font-weight: 650;
  cursor: pointer;
  font-family: inherit;
  border-right: 1.5px solid var(--color-border);
}
.segmented-btn:last-child { border-right: none; }
.segmented-btn[aria-pressed="true"] { background: var(--color-primary); color: #fff; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 0.94rem;
}
.switch-row:last-child { border-bottom: none; }

.switch {
  width: 50px; height: 30px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  border: 1.5px solid var(--color-border);
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
}
.switch-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 23px; height: 23px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--motion-med) ease;
}
.switch[aria-checked="true"] { background: var(--color-primary); border-color: var(--color-primary); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); }

/* ---------- Chats ---------- */

.chats-screen { height: 100%; display: flex; flex-direction: column; }
.chat-list-panel { flex: 1 1 auto; overflow-y: auto; padding-top: 16px; padding-bottom: calc(20px + var(--nav-height)); }
.chats-screen.is-list-mode .chat-thread-panel { display: none; }
.chats-screen:not(.is-list-mode) .chat-list-panel { display: none; }

.thread-card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  cursor: pointer;
  font-family: inherit;
}
.thread-card-body { flex: 1 1 auto; min-width: 0; }
.thread-card-name { font-weight: 700; font-size: 0.96rem; }
.thread-card-preview {
  font-size: 0.84rem; color: var(--color-text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-card-time { font-size: 0.74rem; color: var(--color-text-secondary); flex: 0 0 auto; }

.chat-thread-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.thread-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  flex: 0 0 auto;
}
.thread-contact { display: flex; align-items: center; gap: 10px; }
.thread-name { font-weight: 700; }

.thread-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { max-width: 78%; padding: 10px 13px; border-radius: 16px; font-size: 0.92rem; line-height: 1.4; }
.msg-them { align-self: flex-start; background: var(--color-surface-alt); border-bottom-left-radius: 4px; }
.msg-me { align-self: flex-end; background: var(--color-primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-typing { align-self: flex-start; background: var(--color-surface-alt); color: var(--color-text-secondary); font-style: italic; }

.thread-composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
.thread-composer input { flex: 1 1 auto; }

.nav-badge {
  position: absolute;
  top: 2px; right: calc(50% - 22px);
  min-width: 16px; height: 16px;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ---------- Bottom nav ---------- */

.bottom-nav {
  flex: 0 0 auto;
  height: var(--nav-height);
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  position: relative;
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 650;
  cursor: pointer;
  position: relative;
  padding: 6px 2px;
}
.nav-btn .icon { width: 22px; height: 22px; }
.nav-btn.active { color: var(--color-primary); }

/* ---------- Overlays: bottom sheet + modal ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  transition: opacity var(--motion-med) ease;
}
.overlay.hidden { display: none; }

.bottom-sheet {
  width: 100%;
  max-height: 86%;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  position: relative;
  animation: sheet-up var(--motion-med) ease;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--color-border); margin: 6px auto 14px; }
.sheet-close {
  position: absolute; top: 14px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--color-surface-alt); color: var(--color-text);
  font-size: 1rem; cursor: pointer;
}
.sheet-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.sheet-name { font-size: 1.2rem; font-weight: 800; margin: 0; }
.sheet-meta { font-size: 0.86rem; color: var(--color-text-secondary); margin: 2px 0 0; }
.sheet-bio { font-size: 0.94rem; line-height: 1.5; color: var(--color-text); margin: 0 0 22px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }

.modal {
  width: 100%;
  max-width: 420px;
  margin: auto;
  background: var(--color-surface);
  border-radius: 24px;
  padding: 24px 20px;
  position: relative;
  animation: sheet-up var(--motion-med) ease;
}

/* ---------- Toasts ---------- */

.toast-container {
  position: absolute;
  bottom: calc(var(--nav-height) + 14px);
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  background: var(--color-text);
  color: var(--color-bg);
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 650;
  box-shadow: var(--shadow-md);
  animation: toast-in var(--motion-med) ease;
  max-width: 100%;
}
html[data-contrast="high"] .toast { background: #fff; color: #000; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Reduced motion ---------- */

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
