:root {
  /* Day (light) theme — default */
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --border: #d6dce5;
  --text: #1a212b;
  --muted: #5b6775;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8effa;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --callsign-bg: #fef08a;
  --radius: 8px;
  color-scheme: light;
}

[data-theme="night"] {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #232c38;
  --border: #2c3744;
  --text: #e6edf3;
  --muted: #8b97a6;
  --accent: #3b82f6;
  --accent-hover: #2f6fd6;
  --accent-soft: #1e2a3d;
  --danger: #ef4444;
  --danger-hover: #d23636;
  --warn: #fbbf24;
  --warn-soft: #3b2f0a;
  --callsign-bg: #4a3d0e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.app-header-text { flex: 1; min-width: 0; }
.app-header h1 { margin: 0; font-size: 1.4rem; }
.app-header h1 a {
  color: var(--accent);
  text-decoration: none;
}
.app-header h1 a:hover,
.app-header h1 a:focus-visible { color: var(--accent-hover); }
.tagline { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.85rem; }
.tagline code { font-size: 0.85em; padding: 0.05rem 0.3rem; background: var(--panel-2); border-radius: 4px; }
.tagline a { color: var(--accent); text-decoration: none; font-weight: 600; }
.tagline a:hover, .tagline a:focus-visible { color: var(--accent-hover); text-decoration: underline; }
.theme-toggle { min-width: 64px; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
  align-items: start;
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-width: 0;
}

.panel-head { margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; font-size: 1.05rem; }
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.detail-actions { display: flex; gap: 0.5rem; }

.stack { display: flex; flex-direction: column; gap: 0.6rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 0;
}

input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
button.primary { background: var(--accent); }
button.primary:hover { background: var(--accent-hover); }
button.secondary { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
button.secondary:hover { background: var(--border); }
button.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }

.import-btn { width: 100%; margin-top: 0.5rem; }

.log-list { list-style: none; margin: 1rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.log-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.log-list li.active { border-color: var(--accent); background: var(--accent-soft); }
.log-list .log-title { font-weight: 600; font-size: 0.9rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.log-list .count { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }

.empty-state { color: var(--muted); text-align: center; padding: 3rem 1rem; }

.qso-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
  margin-bottom: 1rem;
}
.qso-form button { height: 38px; }
.field-call { width: 150px; }
#qso-call { background: var(--callsign-bg); }
.field-date { width: 150px; }
.field-time { width: 130px; }
.field-band { width: 100px; }
.field-mode { width: 130px; }
.field-rst  { width: 75px; }

.qso-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* min-width matches the natural single-row width of .qso-form so the table
   never appears narrower than the input row above it. */
.qso-table { width: auto; min-width: 1000px; border-collapse: collapse; font-size: 0.85rem; }
.qso-table td.flag { width: 1.6rem; font-size: 1.05rem; line-height: 1; text-align: center; padding-right: 0.25rem; }
.qso-table th, .qso-table td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.qso-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.qso-table td.mono { font-variant-numeric: tabular-nums; }
.qso-table .row-actions {
  display: flex;
  gap: 0.3rem;
  white-space: nowrap;
  padding-left: 0.25rem;
}
.btn-touch {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-weight: 600;
}
.row-edit { background: var(--panel-2); color: var(--text); }
.row-edit:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.row-del { background: transparent; color: var(--danger); border-color: var(--danger); }
.row-del:hover { background: var(--danger); color: #fff; }
.qso-table tr.editing td { background: var(--accent-soft); }

.detail-title { flex: 1; min-width: 0; }
.rename-input {
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.35rem 0.5rem;
}

.muted { color: var(--muted); font-size: 0.85rem; }
[hidden] { display: none !important; }

.dup-indicator {
  align-self: flex-start;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Mobile tweaks */
@media (max-width: 600px) {
  .app-header { padding: 1rem 1rem 0.75rem; flex-wrap: wrap; }
  .app-header h1 { font-size: 1.2rem; }
  .layout { padding: 0.75rem; gap: 0.75rem; }
  .panel { padding: 0.85rem; }
  .detail-head { flex-direction: column; align-items: stretch; }
  .detail-actions { width: 100%; }
  .detail-actions button { flex: 1; }
  button { min-height: 40px; }
  /* Stack the QSO form on phones:
     Callsign / Date / Time each on their own row, Band+Mode share a row,
     RST sent + RST rcvd share a row. Buttons go full-width. */
  .qso-form > label { width: 100%; }
  .qso-form .field-band,
  .qso-form .field-mode,
  .qso-form .field-rst { width: calc(50% - 0.3rem); }
  .qso-form > button { width: 100%; }

  /* iOS Safari fixes.
     1. Native <input type="date|time"> ships with internal padding + a picker
        icon that ignores `width: 100%` and overflows the container. Removing
        the native appearance lets them respect the parent box.
     2. iOS auto-zooms when focusing an input with font-size < 16px. Bumping
        all inputs/selects to 16px prevents that zoom (matches what most apps
        ship as the mobile input size). */
  input[type="date"],
  input[type="time"] {
    -webkit-appearance: none;
    appearance: none;
  }
  input, select { font-size: 16px; }
}
