/* ==========================================================================
   App Shell, Topbar, Workspaces, Status Bar, Modals & Toast
   ========================================================================== */

#app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-bay);
}

/* Topbar (52px) */
#topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg-bay);
  border-bottom: 1px solid var(--border-tide);
  z-index: var(--z-topbar);
  position: relative;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  padding: 4px 6px 4px 2px;
  border-radius: var(--radius-sm);
}

.brand-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--border-tide);
  display: grid;
  place-items: center;
  color: var(--accent-flamingo);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink-shell);
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-haze);
}

/* Primary Workspace Navigation */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.nav-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 100%;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-haze);
  transition: color var(--dur-fast), background var(--dur-fast);
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--ink-shell);
  background: rgba(255, 255, 255, 0.03);
}

.nav-tab.active {
  color: var(--ink-shell);
  font-weight: 600;
}

.nav-tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 2px;
  background: var(--accent-flamingo);
  border-radius: 2px 2px 0 0;
}

.nav-tab .ic {
  width: 15px;
  height: 15px;
}

.nav-tab.active .ic {
  color: var(--accent-flamingo);
}

/* Topbar Right Tools */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-progress-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 112px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-asphalt);
  border: 1px solid var(--border-tide);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}

.top-progress-btn:hover {
  background: var(--surface-raised);
  border-color: var(--border-strong);
}

.top-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1;
}

.top-progress-row strong {
  color: var(--ink-shell);
  font-weight: 600;
}

.top-progress-row span {
  color: var(--ink-haze);
}

.master-progress-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(238, 242, 247, 0.10);
  overflow: hidden;
}

.master-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--progress-gradient);
  border-radius: 999px;
  transition: width 280ms var(--ease-out);
}

.segmented {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background: var(--surface-asphalt);
  border: 1px solid var(--border-tide);
  border-radius: var(--radius-sm);
  height: 34px;
}

.segmented button {
  height: 28px;
  padding: 0 9px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-haze);
  transition: background var(--dur-fast), color var(--dur-fast);
}

.segmented button:hover {
  color: var(--ink-shell);
}

.segmented button.active {
  background: var(--surface-raised);
  color: var(--ink-shell);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

#btn-mobile-sidebar,
#btn-mobile-search {
  display: none;
}

/* Main Workspace Container */
#workspace-root {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.workspace {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#workspace-map {
  display: flex;
  flex-direction: column;
}

.map-body-row {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

#workspace-database,
#workspace-quiz,
#workspace-progress {
  overflow-y: auto;
  background: var(--bg-bay);
}

/* Status Bar (Map bottom 30px) */
#map-statusbar {
  height: var(--statusbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg-bay);
  border-top: 1px solid var(--border-tide);
  font-size: 11.5px;
  color: var(--ink-haze);
  z-index: var(--z-map-ui);
}

.statusbar-left,
.statusbar-center,
.statusbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.basemap-notice-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-haze);
  font-size: 11.5px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.basemap-notice-btn:hover {
  color: var(--ink-shell);
  background: var(--surface-raised);
}

.notice-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-diff);
  flex-shrink: 0;
}

.coord-readout {
  color: var(--ink-shell);
  font-size: 11.5px;
  white-space: nowrap;
}

.shortcuts-hint {
  color: var(--ink-muted);
  white-space: nowrap;
}

/* Mobile Bottom Nav (Hidden on Desktop) */
#mobile-bottom-nav {
  display: none;
}

/* Modals (Native <dialog> styled cleanly) */
dialog.atlas-modal {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-asphalt);
  color: var(--ink-shell);
  box-shadow: var(--shadow-lg);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

dialog.atlas-modal.modal-wide {
  width: min(860px, calc(100vw - 24px));
}

dialog.atlas-modal::backdrop {
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(4px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-tide);
  background: var(--bg-bay);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  max-height: calc(100vh - 150px);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-tide);
  background: rgba(11, 16, 24, 0.55);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-haze);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  background: var(--bg-bay);
  border: 1px solid var(--border-tide);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--ink-shell);
  font-size: 13px;
  transition: border-color var(--dur-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent-lagoon);
}

.form-textarea {
  resize: vertical;
  min-height: 76px;
}

/* Legend Modal Image */
.legend-img-wrap {
  background: var(--bg-abyss);
  border: 1px solid var(--border-tide);
  border-radius: var(--radius-md);
  padding: 8px;
  text-align: center;
}

.legend-img-wrap img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto;
}

/* Backup / Sources Modal specifics */
.backup-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.backup-status {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-top: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border-tide);
}

.backup-status.is-ok {
  border-color: var(--accent-lagoon-border);
  background: var(--accent-lagoon-soft);
  color: var(--ink-shell);
}

.backup-status.is-err {
  border-color: rgba(251, 113, 133, 0.45);
  background: rgba(251, 113, 133, 0.14);
  color: #FFE4E6;
}

.source-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border-tide);
  margin-bottom: 10px;
}

.source-card h4 {
  margin: 0 0 4px;
  font-size: 13.5px;
  color: var(--ink-shell);
}

.source-card p {
  margin: 4px 0;
  font-size: 12.5px;
  color: var(--ink-haze);
}

.tier-legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.tier-legend-card {
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-bay);
  border: 1px solid var(--border-tide);
  font-size: 12px;
}

.tier-legend-card p {
  margin: 6px 0 0;
  color: var(--ink-haze);
  line-height: 1.45;
}

/* Toast Notification */
#toast {
  position: fixed;
  left: 50%;
  bottom: 44px;
  transform: translate(-50%, 14px);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: var(--surface-glass-heavy);
  border: 1px solid var(--border-strong);
  color: var(--ink-shell);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-toast);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
  max-width: calc(100vw - 32px);
  text-align: center;
}

#toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Drawer Shade (mobile) */
#drawer-shade {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.62);
  z-index: calc(var(--z-sidebar) - 5);
  backdrop-filter: blur(2px);
}
