/* ============================= Grundlagen & Farbwelt ============================= */
:root {
  --bg-deep: #0a1f24;
  --bg-deep-2: #0d262c;
  --bg-panel: #103038;
  --bg-panel-raised: #143842;
  --bg-input: #0c262c;
  --line: #2a4b52;
  --line-soft: #1c3a40;

  --parchment: #ece1c8;
  --parchment-dim: #b9ad91;
  --parchment-faint: #7f8f8c;

  --amber: #dd9c3f;
  --amber-bright: #f0b45c;
  --amber-dim: #8a6427;

  --moss: #5f7a4e;
  --moss-bright: #7c9b67;
  --moss-dim: #3c4e33;

  --danger: #b5555a;
  --danger-bright: #d17278;

  --font-head: "Fraunces", serif;
  --font-mono: "JetBrains Mono", monospace;
  --font-ui: "Inter", sans-serif;

  --radius: 10px;
  --shadow: 0 6px 18px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(ellipse at 20% -10%, #163842 0%, transparent 55%),
    radial-gradient(ellipse at 100% 110%, #0f2e28 0%, transparent 50%),
    var(--bg-deep);
  color: var(--parchment);
  font-family: var(--font-ui);
  min-height: 100vh;
}

::selection { background: var(--amber-dim); color: var(--parchment); }
a { color: var(--amber-bright); }
.hidden { display: none !important; }

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

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

label { font-size: 0.82rem; color: var(--parchment-dim); display: block; margin-bottom: 4px; }

select, input, textarea {
  font-family: var(--font-ui);
  background: var(--bg-input);
  border: 1px solid var(--line);
  color: var(--parchment);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.92rem;
}
select:hover, input:hover, textarea:hover { border-color: var(--moss-bright); }
input[name="coord"], .mono { font-family: var(--font-mono); letter-spacing: 1px; }

button {
  font-family: var(--font-ui);
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-panel-raised);
  color: var(--parchment);
  padding: 9px 16px;
  font-size: 0.88rem;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { border-color: var(--amber-bright); background: #17414c; }
button:active { transform: translateY(1px); }

button.primary {
  background: linear-gradient(180deg, var(--amber) 0%, var(--amber-dim) 100%);
  color: #241a08;
  border-color: var(--amber-dim);
}
button.primary:hover { background: linear-gradient(180deg, var(--amber-bright) 0%, var(--amber) 100%); }

button.danger { border-color: var(--danger); color: var(--danger-bright); background: transparent; padding: 5px 10px; font-size: 0.78rem; }
button.danger:hover { background: var(--danger); color: #1c0d0d; }

button.ghost-small { padding: 5px 10px; font-size: 0.78rem; }

/* ============================= Login / Registrierung (Modal) ============================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 16, 19, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 2px 8px;
  font-size: 1.1rem;
  line-height: 1;
  background: transparent;
  border-color: transparent;
  color: var(--parchment-faint);
}
.modal-close:hover { color: var(--amber-bright); border-color: var(--line); }

.auth-card h1 {
  font-family: var(--font-head);
  color: var(--amber-bright);
  margin: 0 0 4px;
  font-size: 1.8rem;
}

.auth-subtitle { color: var(--parchment-dim); font-size: 0.88rem; margin: 0 0 20px; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.auth-tab {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--line);
  color: var(--parchment-dim);
}
.auth-tab.active { border-color: var(--amber-bright); color: var(--amber-bright); background: var(--bg-panel-raised); }

.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form input { width: 100%; margin-bottom: 8px; }
.auth-form button { margin-top: 8px; }
.auth-hint { font-size: 0.72rem; color: var(--parchment-faint); margin: -4px 0 8px; }
.auth-error { color: var(--danger-bright); font-size: 0.82rem; min-height: 1.2em; margin-top: 8px; }
.auth-success { color: var(--moss-bright); font-size: 0.82rem; min-height: 1.2em; margin-top: 4px; }

.link-btn {
  background: transparent;
  border: none;
  color: var(--amber-bright);
  padding: 4px 0;
  font-size: 0.82rem;
  text-decoration: underline;
  text-align: left;
}
.link-btn:hover { background: transparent; border-color: transparent; color: var(--amber-dim); }
.auth-forgot-link { align-self: flex-start; margin-top: 2px; }

.locked-notice {
  background: var(--bg-panel-raised);
  border: 1px dashed var(--amber-dim);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 0.88rem;
  color: var(--parchment-dim);
}

/* ============================= Layout ============================= */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 64px;
}

header.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 20px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 20px;
}

header.masthead h1 {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.5px;
  margin: 0;
  color: var(--amber-bright);
}

header.masthead .subtitle {
  font-size: 0.9rem;
  color: var(--parchment-dim);
  font-style: italic;
}

.user-bar { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-badge {
  font-size: 0.82rem;
  color: var(--parchment-dim);
  background: var(--bg-panel-raised);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 5px 12px;
}
.user-badge .role-admin { color: var(--amber-bright); font-weight: 600; }

section.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 22px;
}

section.panel > h2 {
  font-family: var(--font-head);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--amber-bright);
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 8px;
}

.waterbody-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 6px;
}

#wbSelect { min-width: 260px; font-size: 1rem; }

.wb-type-badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--parchment-dim);
}

/* ============================= Grid + Formular Layout ============================= */
.grid-form-layout {
  display: grid;
  grid-template-columns: minmax(320px, 560px) 1fr;
  gap: 24px;
  align-items: start;
}

.grid-wrap {
  position: relative;
  background: var(--bg-deep-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 10px;
}

#spotGrid { width: 100%; height: auto; display: block; }

.grid-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 10px;
  font-size: 0.78rem;
}
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--parchment-dim); }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,0.4); }

#tooltip {
  position: fixed;
  pointer-events: none;
  background: #08181c;
  border: 1px solid var(--amber-dim);
  color: var(--parchment);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  max-width: 260px;
  box-shadow: var(--shadow);
  z-index: 50;
  display: none;
  line-height: 1.45;
}
#tooltip .tt-coord { font-family: var(--font-mono); color: var(--amber-bright); font-weight: 700; }
#tooltip .tt-entry + .tt-entry { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line-soft); }

/* ============================= Formular ============================= */
form#spotForm {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
}
form#spotForm .field-full { grid-column: 1 / -1; }
form#spotForm input, form#spotForm select, form#spotForm textarea { width: 100%; }
textarea#noteInput { resize: vertical; min-height: 48px; font-family: var(--font-ui); }

.field-error {
  color: var(--danger-bright);
  font-size: 0.76rem;
  margin-top: 3px;
  min-height: 1em;
}
.form-error { color: var(--danger-bright); font-size: 0.84rem; min-height: 1.2em; }
input.invalid, select.invalid { border-color: var(--danger-bright); }

.form-mode-banner {
  background: var(--bg-panel-raised);
  border: 1px solid var(--amber-dim);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--amber-bright);
  display: flex;
  align-items: center;
  gap: 10px;
}
.form-mode-banner button { padding: 4px 10px; font-size: 0.76rem; margin-left: auto; }

.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ============================= Kartenliste ============================= */
.card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.spot-card {
  background: var(--bg-panel-raised);
  border: 1px solid var(--line-soft);
  border-left: 4px solid var(--moss-bright);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.84rem;
  position: relative;
}
.spot-card .coord {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--amber-bright);
  font-size: 1rem;
}
.spot-card dl { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; }
.spot-card dt { color: var(--parchment-faint); }
.spot-card dd { margin: 0; }
.spot-card .note { margin-top: 6px; font-style: italic; color: var(--parchment-dim); }
.spot-card .author { margin-top: 6px; font-size: 0.72rem; color: var(--parchment-faint); }
.spot-card .card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.spot-card .card-actions { display: flex; gap: 6px; }
.empty-state { color: var(--parchment-faint); font-style: italic; padding: 12px 0; }

/* ============================= Tabelle ============================= */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 14px;
}
.table-toolbar .field { min-width: 150px; }
.toggle-row { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.toggle-row input { width: auto; }

.table-scroll { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 8px; }
table#spotsTable, table#usersTable { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table#spotsTable { min-width: 900px; }
table#usersTable { min-width: 640px; }
table#spotsTable th, table#spotsTable td, table#usersTable th, table#usersTable td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
table#spotsTable th, table#usersTable th {
  background: var(--bg-panel-raised);
  color: var(--amber-bright);
  position: sticky; top: 0;
}
table#spotsTable th { cursor: pointer; user-select: none; }
table#spotsTable th:hover { color: var(--amber-bright); background: #17414c; }
table#spotsTable th .sort-arrow { font-size: 0.7rem; margin-left: 4px; color: var(--parchment-faint); }
table#spotsTable tbody tr:hover, table#usersTable tbody tr:hover { background: rgba(221,156,63,0.06); }
table#spotsTable td.note-cell { white-space: normal; max-width: 220px; color: var(--parchment-dim); }
table#spotsTable td.actions-cell, table#usersTable td.actions-cell { white-space: nowrap; }
table#spotsTable td.actions-cell .row-actions, table#usersTable td.actions-cell .row-actions { display: flex; gap: 6px; align-items: center; }
table#usersTable select { padding: 4px 6px; font-size: 0.8rem; }

footer.app-footer {
  text-align: center;
  color: var(--parchment-faint);
  font-size: 0.78rem;
  margin-top: 30px;
}

/* ============================= Responsive ============================= */
@media (max-width: 900px) {
  .grid-form-layout { grid-template-columns: 1fr; }
  form#spotForm { grid-template-columns: 1fr; }
  .toggle-row { margin-left: 0; }
  header.masthead h1 { font-size: 1.6rem; }
  .user-bar { margin-left: 0; width: 100%; justify-content: space-between; }
}
