/* ===== Design tokens ===== */
:root {
  --bg: #0F1B1E;
  --surface: #16262A;
  --surface-raised: #1C2E32;
  --line: #2A3F44;
  --text: #EDEAE1;
  --text-muted: #8FA3A8;
  --amber: #E8A33D;
  --amber-dim: #6B4E22;
  --green: #6FCF97;
  --red: #E0725A;

  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", monospace;

  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a { color: var(--amber); }

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

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

/* ===== Layout shell ===== */
.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 10px;
}

.site-header h1 {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: 0.02em;
  margin: 0;
}

.site-header h1 .dial {
  color: var(--amber);
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.station-tag {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.1;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--amber); }
.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #16110A;
  font-weight: 600;
}
.btn-primary:hover { background: #f0ac4c; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-danger { color: var(--red); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Login page ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  position: relative;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--amber);
}

.login-card h1 {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  margin: 0 0 4px;
}
.login-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--amber);
}

.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: -8px;
  margin-bottom: 14px;
  min-height: 1em;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 4px;
  margin-right: 20px;
  cursor: pointer;
  font-size: 0.95rem;
  border-bottom: 2px solid transparent;
  font-family: var(--font-mono);
}
.tab-btn.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
}

/* ===== Entry form ===== */
.log-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
}
.log-form h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  margin: 0 0 16px;
  color: var(--text-muted);
  font-weight: 500;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
}
.form-grid .field-wide { grid-column: 1 / -1; }
.field input.mono, .field select.mono { font-family: var(--font-mono); }
input.callsign-input { text-transform: uppercase; font-family: var(--font-mono); letter-spacing: 0.03em; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ===== Log table (desktop) / cards (mobile) ===== */
.notes-dropdown {
  margin-top: 4px;
  font-size: 0.85rem;
}

.notes-dropdown summary {
  cursor: pointer;
  color: #e8a33d;
  font-weight: 500;
  user-select: none;
}

.notes-dropdown summary:hover {
  text-decoration: underline;
}

.notes-content {
  margin-top: 4px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.05);
  border-left: 2px solid #e8a33d;
  border-radius: 3px;
  color: #ddd;
  white-space: pre-wrap;
}

.log-count {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
  font-family: var(--font-mono);
}

.log-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table.log-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  min-width: 760px;
}
.log-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
}
.log-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover td { background: var(--surface-raised); }
.log-table .callsign-cell { color: var(--amber); font-weight: 600; }

.qsl-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-family: var(--font-sans);
  border: 1px solid var(--line);
}
.qsl-none { color: var(--text-muted); }
.qsl-sent { color: var(--amber); border-color: var(--amber-dim); }
.qsl-received, .qsl-confirmed { color: var(--green); border-color: #2c4a3a; }

.row-actions { display: flex; gap: 8px; }
.row-actions button {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.8rem; padding: 2px 4px;
  font-family: var(--font-sans);
}
.row-actions button:hover { color: var(--amber); }
.row-actions button.danger:hover { color: var(--red); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Mobile card list, hidden on desktop */
.log-cards { display: none; }
.log-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.log-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.log-card-callsign {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--amber);
  font-size: 1.05rem;
}
.log-card-meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.log-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.log-card-grid span { color: var(--text-muted); }
.log-card-notes {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

@media (max-width: 760px) {
  .log-table-wrap { display: none; }
  .log-cards { display: block; }
}

/* ===== Map ===== */
#map {
  height: 60vh;
  min-height: 360px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.map-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 10px;
  font-family: var(--font-mono);
}

/* leaflet popup theming */
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { font-family: var(--font-mono); font-size: 0.85rem; max-width: 220px; line-height: 1.4; }
.leaflet-popup-content b { color: var(--amber); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-raised);
  border: 1px solid var(--amber);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}