/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Brand tokens ── */
:root {
  --void:     #16140f;
  --obsidian: #131210;
  --crater:   #1e1c18;
  --rust:     #c1440e;
  --sand:     #d4a96a;
  --dust:     #f5e6d0;
  --ash:      #5a5650;
  --font-logo: 'Rajdhani', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'Space Grotesk', sans-serif;
  --nav-height: 53px;
}

/* ── Base ── */
html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--void);
  color: var(--dust);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Logo ── */
.logo { line-height: 1; }

.logo-un {
  font-family: var(--font-logo);
  font-weight: 700;
  font-size: 2.4rem;
  color: var(--rust);
  letter-spacing: -0.01em;
}

.logo-charted {
  font-family: var(--font-logo);
  font-weight: 700;
  font-size: 2.4rem;
  color: var(--sand);
  letter-spacing: -0.01em;
}

.nav-logo .logo-un,
.nav-logo .logo-charted {
  font-size: 1.3rem;
}

/* ── Auth screen ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
  background-image:
    linear-gradient(var(--crater) 1px, transparent 1px),
    linear-gradient(90deg, var(--crater) 1px, transparent 1px);
  background-size: 48px 48px;
  overflow-y: auto;
}

.auth-card {
  background: var(--obsidian);
  border: 0.5px solid var(--crater);
  border-radius: 4px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  position: relative;
}

.auth-card::before,
.auth-card::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: var(--rust);
  border-style: solid;
}
.auth-card::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.auth-card::after  { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.tagline {
  font-size: 0.72rem;
  color: var(--ash);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: -0.5rem;
}

/* ── Tabs ── */
.tab-row { display: flex; gap: 6px; }

.tab {
  flex: 1;
  padding: 0.5rem;
  background: transparent;
  border: 0.5px solid var(--crater);
  border-radius: 2px;
  color: var(--ash);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--rust);
  border-color: var(--rust);
  color: var(--dust);
}

/* ── Form fields ── */
.form-fields {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-label {
  font-size: 0.68rem;
  color: var(--ash);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

input[type="email"],
input[type="password"],
input[type="text"] {
  padding: 0.7rem 0.75rem;
  background: var(--void);
  border: 0.5px solid var(--crater);
  border-radius: 2px;
  color: var(--dust);
  font-family: var(--font-body);
  font-size: 16px; /* prevents iOS zoom */
  outline: none;
  transition: border-color 0.15s ease;
  width: 100%;
}

input::placeholder { color: var(--ash); opacity: 0.6; }
input:focus { border-color: var(--sand); }

/* ── Buttons ── */
.btn-primary {
  padding: 0.7rem 1rem;
  background: var(--rust);
  border: none;
  border-radius: 2px;
  color: var(--dust);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.15s ease;
  text-transform: lowercase;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active { background: #a8380b; }

.btn-ghost {
  padding: 0.4rem 0.75rem;
  background: transparent;
  border: 0.5px solid var(--crater);
  border-radius: 2px;
  color: var(--ash);
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn-ghost:active {
  border-color: var(--ash);
  color: var(--dust);
}

/* ── Message ── */
.message {
  font-size: 0.8rem;
  color: var(--sand);
  font-family: var(--font-mono);
  min-height: 1rem;
  letter-spacing: 0.04em;
}

.message.error { color: var(--rust); }

/* ── Coordinates readout ── */
.coords {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--ash);
  letter-spacing: 0.06em;
  border-top: 0.5px solid var(--crater);
  padding-top: 0.85rem;
  margin-top: 0.25rem;
}

/* ── App screen ── */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── Nav ── */
nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  height: var(--nav-height);
  background: var(--obsidian);
  border-bottom: 0.5px solid var(--crater);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-username {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--sand);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Map container ── */
#map-container {
  flex: 1;
  position: relative;
  width: 100%;
  min-height: 0;
}

/* ── Map controls — bottom left on mobile ── */
#map-controls {
  position: absolute;
  bottom: 1.5rem;
  left: 1rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.map-control-btn {
  padding: 0.4rem 0.75rem;
  background: var(--obsidian);
  border: 0.5px solid var(--crater);
  border-radius: 2px;
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
}

.map-control-btn.active {
  border-color: #4a9ebb;
  color: #4a9ebb;
}

/* ── Settings overlay ── */
#settings-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 12, 10, 0.6);
  z-index: 100;
  backdrop-filter: blur(2px);
}

#settings-backdrop.open { display: block; }

#settings-panel {
  position: fixed;
  top: var(--nav-height);
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  background: var(--void);
  border-left: 0.5px solid var(--crater);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#settings-panel.open { transform: translateX(0); }

#settings-inner {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 3rem;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.settings-close {
  background: transparent;
  border: 0.5px solid var(--crater);
  border-radius: 2px;
  color: var(--ash);
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-family: var(--font-mono);
  -webkit-tap-highlight-color: transparent;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Dashboard cards ── */
.dashboard-card {
  background: var(--obsidian);
  border: 0.5px solid var(--crater);
  border-radius: 4px;
  padding: 1.25rem;
  position: relative;
  flex-shrink: 0;
}

.dashboard-card::before,
.dashboard-card::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--rust);
  border-style: solid;
}
.dashboard-card::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.dashboard-card::after  { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.section-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ash);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.section-sub {
  font-size: 0.75rem;
  color: var(--ash);
  margin-bottom: 0.75rem;
  font-family: var(--font-body);
}

.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.source-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1;
}

.source-name {
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--dust);
  font-weight: 500;
}

.source-status {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--ash);
  letter-spacing: 0.05em;
  line-height: 1.4;
}

.source-status.connected { color: var(--sand); }

.source-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-shrink: 0;
}

/* ── Sync ── */
.sync-result {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  margin-top: 0.75rem;
  min-height: 1rem;
  line-height: 1.5;
  color: var(--ash);
}

.sync-result.success { color: var(--sand); }
.sync-result.error   { color: var(--rust); }

/* ── Upload ── */
.upload-dropzone {
  border: 0.5px dashed var(--ash);
  border-radius: 4px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.upload-dropzone.drag-over {
  border-color: var(--sand);
  background: rgba(212, 169, 106, 0.04);
}

.upload-icon {
  font-size: 1.75rem;
  color: var(--ash);
  line-height: 1;
  font-family: var(--font-mono);
}

.upload-hint {
  font-size: 0.78rem;
  color: var(--ash);
  font-family: var(--font-body);
}

.upload-types {
  font-size: 0.62rem;
  color: var(--ash);
  opacity: 0.5;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
}

.upload-message {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  min-height: 1rem;
  margin-top: 0.6rem;
  line-height: 1.5;
}

.upload-message.success { color: var(--sand); }
.upload-message.error   { color: var(--rust); }

/* ── Toggle ── */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--crater);
  border: 0.5px solid var(--ash);
  border-radius: 24px;
  transition: 0.2s;
}

.toggle-slider:before {
  position: absolute;
  content: '';
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: var(--ash);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--rust);
  border-color: var(--rust);
}

.toggle input:checked + .toggle-slider:before {
  transform: translateX(20px);
  background: var(--dust);
}

/* ── Danger zone ── */
.danger-card { border-color: rgba(193, 68, 14, 0.3); }
.danger-title { color: var(--rust) !important; }

.danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0;
}

.danger-divider {
  border: none;
  border-top: 0.5px solid var(--crater);
  margin: 0.1rem 0;
}

.btn-danger {
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 0.5px solid var(--rust);
  border-radius: 2px;
  color: var(--rust);
  font-family: var(--font-body);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.btn-danger:active {
  background: var(--rust);
  color: var(--dust);
}

.danger-footer {
  margin-top: 1rem;
  font-size: 0.68rem;
  color: var(--ash);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  border-top: 0.5px solid var(--crater);
  padding-top: 0.85rem;
}

.danger-footer a { color: var(--ash); text-decoration: none; }
.danger-footer a:active { color: var(--sand); }

/* ── Mobile specific ── */
@media (max-width: 480px) {
  .auth-card { padding: 1.5rem; }
  .logo-un, .logo-charted { font-size: 2rem; }

  /* Full width settings panel on mobile */
  #settings-panel { width: 100vw; border-left: none; }

  /* Hide username on very small screens if needed */
  .nav-username { max-width: 80px; }

  /* Larger tap targets */
  .btn-ghost { min-height: 36px; }
}

/* ── Tablet ── */
@media (min-width: 481px) and (max-width: 768px) {
  #settings-panel { width: 380px; }
}