:root {
  --bg: #f3efe6;
  --bg-deep: #e7dfd0;
  --ink: #1f2a24;
  --ink-soft: #4a574f;
  --line: #c9bda8;
  --card: #fffaf2;
  --accent: #2f5d50;
  --accent-2: #8b5a2b;
  --danger: #9b2c2c;
  --ok: #1f6b4a;
  --shadow: 0 12px 40px rgba(31, 42, 36, 0.08);
  --radius: 14px;
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at top left, rgba(47, 93, 80, 0.08), transparent 45%),
    radial-gradient(ellipse at bottom right, rgba(139, 90, 43, 0.1), transparent 40%),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.main { flex: 1; width: min(1200px, calc(100% - 2rem)); margin: 0 auto; padding: 1.25rem 0 2.5rem; }
.page-tree .main { width: min(1400px, calc(100% - 1.5rem)); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  background: rgba(255, 250, 242, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 0.75rem; color: inherit; text-decoration: none; }
.brand-mark {
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #f7f3ea;
  font-family: var(--font-display); font-size: 1.35rem; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--font-display); font-size: 1.35rem; font-weight: 700; }
.brand-text small { color: var(--ink-soft); font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }

.topnav { display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; flex: 1; }
.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-left: auto;
  flex-wrap: wrap;
}
.topnav a, .topnav-btn { color: var(--ink); font-weight: 600; text-decoration: none; }
.topnav a:hover, .topnav-btn:hover { color: var(--accent); }
.topnav-btn {
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.user-chip {
  background: #e8efe9; color: var(--accent);
  padding: 0.25rem 0.7rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600;
}

.site-footer {
  text-align: center; color: var(--ink-soft); font-size: 0.85rem;
  padding: 1rem; border-top: 1px solid rgba(201, 189, 168, 0.5);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0 0 0.4rem; }
h1 { font-size: clamp(1.8rem, 3vw, 2.4rem); }
.muted { color: var(--ink-soft); margin: 0; }
.small { font-size: 0.9rem; }

.flash {
  width: min(1200px, calc(100% - 2rem));
  margin: 0.85rem auto 0;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
}
.flash-success { border-color: #9dceb5; background: #eef8f2; color: var(--ok); }
.flash-error { border-color: #e2b4b4; background: #fdf1f1; color: var(--danger); }

.alert { padding: 0.85rem 1rem; border-radius: 10px; margin: 0.75rem 0; }
.alert-error { background: #fdf1f1; color: var(--danger); border: 1px solid #e2b4b4; }
.alert-success { background: #eef8f2; color: var(--ok); border: 1px solid #9dceb5; }
.alert-info { background: #f4efe6; color: var(--ink); border: 1px solid var(--line); }
.alert ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  border: 1px solid transparent; border-radius: 10px;
  padding: 0.65rem 1.05rem; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: 0.15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #f7f3ea; }
.btn-primary:hover { background: #254a40; color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #efe8da; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.88rem; border-radius: 8px; }
.icon-btn {
  border: 0; background: transparent; font-size: 1.5rem; line-height: 1;
  cursor: pointer; color: var(--ink-soft); padding: 0.2rem 0.45rem;
}

.form { display: grid; gap: 0.85rem; }
.form label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.95rem; }
.form input, .form select, .form textarea {
  width: 100%; font: inherit; padding: 0.65rem 0.75rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  color: var(--ink);
}
.form small { font-weight: 400; color: var(--ink-soft); }
.auth-card .form > .btn {
  margin-top: 0.85rem;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-grid .full { grid-column: 1 / -1; }
fieldset {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin: 0 0 1rem; background: rgba(255,255,255,0.35);
}
legend { font-family: var(--font-display); font-size: 1.2rem; padding: 0 0.35rem; }

.page-auth .main { display: grid; place-items: center; }
.auth-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.6rem;
}
.auth-card > h1 {
  margin-bottom: 0;
}
.auth-card > h1 + .muted {
  margin: 1.15rem 0;
}
.auth-links { margin-top: 1rem; text-align: center; }

.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  background: #e8efe9; color: var(--accent); font-size: 0.8rem; font-weight: 700;
}
.badge-ok { background: #e5f4ec; color: var(--ok); }
.badge-off { background: #f0e7e7; color: var(--danger); }

.inline-form { display: inline; }
.or-sep { text-align: center; color: var(--ink-soft); margin: 0.5rem 0; }

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);
  width: fit-content;
  height: fit-content;
  margin: auto;
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.modal::backdrop { background: rgba(20, 28, 24, 0.45); }
.modal-card {
  display: flex;
  flex-direction: column;
  width: min(480px, 100%);
  max-height: calc(100vh - 2rem);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-card-wide {
  width: min(560px, 100%);
}
.form-section {
  margin: 0;
  padding: 0.85rem 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.85rem;
}
.form-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}
.form-section legend {
  padding: 0;
  margin: 0 0 0.15rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}
.form-hint {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.4;
}
.form-section[hidden] {
  display: none !important;
}
.modal-header, .modal-footer, .drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 0.9rem 1rem; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-footer { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.register-choice {
  display: grid;
  gap: 0.7rem;
}
.register-choice .btn { width: 100%; }

.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer[hidden] { display: none !important; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(20, 28, 24, 0.35); }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: min(380px, 100%);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: slideIn 0.2s ease;
}
.drawer-body { padding: 1rem; overflow: auto; flex: 1; }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0.5; } to { transform: none; opacity: 1; } }

@media (max-width: 720px) {
  .form-row, .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-end { margin-left: 0; width: 100%; justify-content: flex-end; }
}
