:root {
    color-scheme: light;
    font-family: 'IBM Plex Sans KR', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --bg: #f4f5f7;
    --card: #ffffff;
    --card-border: #e0e3ea;
    --accent: #e8661b;
    --accent-soft: #c55717;
    --muted: #5a6072;
    --text: #111827;
    --outline: #c0c7d6;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    display: flex;
    justify-content: center;
    padding: 2rem 1rem 3rem;
}

.app-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.app-header {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-left: 3px solid var(--accent);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.brand strong {
    font-size: 1.25rem;
}

.brand p {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.mode-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    border-bottom: none;
    padding-bottom: 0;
}

.mode-tab {
    border: 1px solid var(--card-border);
    border-radius: 8px; /* Uniform rounded corners */
    background: var(--card); /* Monotone background */
    color: var(--muted);
    padding: 0.6rem 1.5rem;
    font-weight: 600;
    position: relative;
    /* Remove top: 1px for body integration */
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    overflow: hidden; /* To contain the accent */
}

.mode-tab::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 8px; /* Accent line width */
    height: 8px; /* Accent line height */
    background: var(--accent);
    border-bottom-left-radius: 4px; /* Soften accent corner */
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s;
}

.mode-tab.active {
    background: var(--card);
    color: var(--text);
    box-shadow: none; /* Removed: no underline */
    border-color: var(--outline); /* Make active tab border more prominent */
}

.mode-tab.active::before {
    opacity: 1; /* Make accent visible for active tab */
}

.panel.hidden {
    display: none;
}

.tracking-panel {
    width: 100%;
}

.tracking-card {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.tracking-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-end;
}

.tracking-actions {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.tracking-actions label {
    min-width: 220px;
}

.tracking-actions label select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--card-border);
    font-size: 0.95rem;
    font-family: 'IBM Plex Sans KR', system-ui, sans-serif;
    background: #fff;
    color: var(--text);
    cursor: pointer;
}

.tracking-actions label select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(232, 102, 27, 0.15);
}

.tracking-body {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.log-input textarea {
    width: 100%;
    min-height: 140px;
    border: 1px solid var(--card-border);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    resize: vertical;
    font-family: 'IBM Plex Sans KR', system-ui, sans-serif;
}

.log-input textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(232, 102, 27, 0.15);
}

.tracking-body-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.tracking-status {
    color: var(--muted);
    font-size: 0.9rem;
}

.tracking-status.success {
    color: var(--accent);
    font-weight: 600;
}

.tracking-status.error {
    color: #b91c1c;
    font-weight: 600;
}

.tracking-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.tracking-metrics .metric {
    border: 1px solid var(--card-border);
    padding: 1rem;
    background: #fefefe;
    border-top: 2px solid var(--accent);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.tracking-metrics .metric span {
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.tracking-metrics .metric strong {
    font-size: 1.35rem;
}

.tracking-metrics .metric small {
    font-size: 0.75rem;
    color: var(--muted);
}

.tracking-metrics .metric small.cal-note {
    color: #059669;
    font-size: 0.72rem;
}

.tracking-metrics .metric small.warn {
    color: #d97706;
    font-size: 0.72rem;
}

.tracking-timeline {
    border: 1px solid var(--card-border);
    border-left: 3px solid var(--accent);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.timeline-item {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.timeline-time {
    font-weight: 600;
    color: var(--accent);
    min-width: 160px;
}

.timeline-details {
    flex: 1;
}

.timeline-details strong {
    display: block;
    font-size: 1rem;
}

.timeline-details span {
    color: var(--muted);
    font-size: 0.9rem;
}

.timeline-details .tag {
    margin-top: 0.35rem;
}

.layout {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: var(--card);
    border-radius: 0;
    border: 1px solid var(--card-border);
    border-left: 3px solid var(--accent);
    padding: 1.5rem;
    box-shadow: none;
}

.hero-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    position: relative;
    overflow: hidden;
}

.hero-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 120px;
    height: 100%;
    background: linear-gradient(135deg, transparent 40%, rgba(232, 102, 27, 0.06) 40%);
    pointer-events: none;
}

.hero-card h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.25rem);
}

.hero-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.85rem;
    border-radius: 0;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.pill.soft {
    background: #f1f5f9;
    color: var(--accent);
    border: 1px solid rgba(232, 102, 27, 0.35);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.stat {
    border: 1px solid var(--card-border);
    border-radius: 0;
    padding: 1rem;
    background: #fefefe;
    border-top: 2px solid var(--accent);
}

.stat .label {
    text-transform: uppercase;
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.1em;
}

.stat .value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent);
    margin-top: 0.25rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

label {
    font-size: 0.95rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

input {
    border-radius: 0;
    border: 1px solid var(--card-border);
    padding: 0.75rem 1rem;
    font-size: 1rem;
    color: var(--text);
    background: #fff;
    transition: border 0.2s, box-shadow 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(232, 102, 27, 0.15);
}

button {
    font: inherit;
    border: none;
    cursor: pointer;
    border-radius: 0;
    padding: 0.85rem 1.4rem;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    transition: background 0.15s, opacity 0.15s;
}

button:hover {
    background: var(--accent-soft);
}

button.ghost {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--muted);
    box-shadow: none;
}

button.ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.map-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.map-mode {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.map-mode button {
    background: #f3f4f6;
    color: var(--muted);
    border: 1px solid transparent;
}

.map-mode button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.map-container,
#map-wrapper {
    position: relative;
    border-radius: 0;
    overflow: hidden;
    border: 1px solid var(--card-border);
    min-height: 360px;
    background: #eef1f7;
    width: 100%;
}

.map-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    border-radius: 0;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

#map-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--accent);
    background: rgba(245, 246, 248, 0.92);
    z-index: 10;
}

#map-loader.error {
    background: rgba(254, 226, 226, 0.9);
    color: #b91c1c;
}

.map-modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    z-index: 1000;
}

.map-modal.open {
    display: flex;
}

.map-modal-content {
    position: relative;
    width: min(90vw, 1200px);
    height: min(85vh, 820px);
    background: #020817;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 0;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.65);
    padding: 2.5rem;
    display: flex;
}

.map-modal-content .map-canvas {
    flex: 1;
}

#route-map-large {
    background: #030712;
}

.map-modal-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 36px;
    height: 36px;
    border-radius: 0;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.9);
    color: #f8fafc;
    font-size: 1.25rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 0 0 2px rgba(2, 6, 23, 0.8);
}

.map-modal-close:hover {
    background: rgba(232, 102, 27, 0.9);
    border-color: rgba(232, 102, 27, 0.7);
}

.selection-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    color: var(--muted);
}

.selection-pill {
    padding: 0.5rem 1rem;
    border-radius: 0;
    border: 1px solid var(--card-border);
    background: #f8fafc;
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
}

.selection-pill strong {
    color: var(--text);
}

.map-status {
    font-size: 0.9rem;
    color: var(--muted);
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.best-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.best-controls select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    background: #fff;
    font-size: 0.85rem;
    color: var(--text);
}

#route-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.result-card {
    border: 1px solid var(--card-border);
    border-radius: 0;
    padding: 1.1rem;
    background: #fdfdfd;
    border-left: 3px solid var(--accent);
}

.result-card h3 {
    margin: 0 0 0.4rem;
    font-size: 1.05rem;
}

.result-card p {
    margin: 0;
    color: var(--muted);
}

.route-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.tag {
    padding: 0.3rem 0.7rem;
    border-radius: 0;
    background: #fff3e8;
    color: var(--muted);
    font-size: 0.85rem;
}

.tag.accent {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.empty-state {
    padding: 1rem;
    border-radius: 0;
    border: 1px dashed var(--card-border);
    text-align: center;
    color: var(--muted);
}

.best-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.best-card-item {
    border: 1px solid var(--card-border);
    border-radius: 0;
    padding: 1rem;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    border-top: 2px solid var(--accent);
}

.best-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.best-card-header strong {
    font-size: 1rem;
}

.best-card-item p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.best-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    font-size: 0.85rem;
    color: var(--text);
}

.best-grid.loading {
    opacity: 0.5;
}

.best-continent-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
}

.best-continent-container.loading {
    opacity: 0.5;
}

.best-continent-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.best-continent-header {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--accent);
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--card-border);
}

@media (max-width: 720px) {
    .app-shell {
        padding: 1.5rem 1rem 2rem;
    }

    .tracking-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tracking-actions {
        width: 100%;
        align-items: stretch;
    }

    button {
        width: 100%;
    }

    #map-wrapper {
        min-height: 450px;
    }

    .map-modal-content {
        width: 95vw;
        height: 90vh;
        padding: 1.5rem;
    }
}

/* Beta badge for experimental features */
.beta-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: #f59e0b;
    color: #1a1a1a;
    padding: 0.1em 0.45em;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 0.3em;
    line-height: 1.4;
}

.mode-tab-beta {
    border-color: #f59e0b44;
}
.mode-tab-beta.active {
    border-color: #f59e0b;
}

/* Maritime (beta) panel */
.maritime-panel {
    width: 100%;
}

.maritime-card {
    max-width: 860px;
}

.beta-notes {
    margin: 0.75rem 0 0 1.25rem;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.6;
}

.beta-placeholder {
    margin-top: 1.5rem;
}

/* ── Advanced Settings (고급 설정) ────────────────────────────────────── */
.advanced-settings {
    border: 1px solid var(--card-border);
    border-radius: 6px;
    overflow: hidden;
}

.advanced-settings summary {
    cursor: pointer;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface, #f8f8f8);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.advanced-settings summary::-webkit-details-marker { display: none; }
.advanced-settings summary::before {
    content: '▶';
    font-size: 0.7rem;
    transition: transform 0.2s;
    display: inline-block;
}
.advanced-settings[open] summary::before {
    transform: rotate(90deg);
}
.advanced-settings summary:hover {
    color: var(--text);
}

.advanced-settings-body {
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.adv-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.4rem;
}

.adv-section > p {
    font-size: 0.875rem;
    color: var(--muted);
    margin: 0 0 0.75rem;
    line-height: 1.5;
}

.adv-note {
    background: #fffbea;
    border-left: 3px solid #f59e0b;
    padding: 0.5rem 0.75rem;
    border-radius: 0 4px 4px 0;
    font-size: 0.83rem !important;
    color: #78350f !important;
}

.opensky-mode-select {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.radio-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.88rem;
    cursor: pointer;
    line-height: 1.4;
}
.radio-label input[type="radio"] {
    margin-top: 0.15rem;
    flex-shrink: 0;
}

.opensky-credentials {
    margin-bottom: 0.75rem;
}
.opensky-credentials.hidden {
    display: none;
}

.adv-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.opensky-badge {
    font-size: 0.82rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-weight: 600;
    line-height: 1;
}
.opensky-badge.anonymous {
    background: #f1f5f9;
    color: #64748b;
}
.opensky-badge.registered {
    background: #dcfce7;
    color: #166534;
}

/* ================================================================
   소포 행방 추정 탭 (Parcel Location Estimator)
   ================================================================ */

.estimator-card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Map section inside the estimator tab */
.estimator-map-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#estimator-map-wrapper {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--card-border);
  min-height: 360px;
  background: #eef1f7;
  width: 100%;
}

#estimator-map {
  width: 100%;
  height: 360px;
}

#estimator-map-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--accent);
  background: rgba(245, 246, 248, 0.92);
  z-index: 10;
  pointer-events: none;
}

.estimator-results {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.estimator-section {
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

.estimator-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Arrival window */
.eta-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.eta-cell {
  flex: 1 1 160px;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: center;
}

.eta-lower  { background: #eff6ff; border: 1px solid #bfdbfe; }
.eta-mode   { background: #fff7ed; border: 2px solid var(--accent); }
.eta-upper  { background: #fef9c3; border: 1px solid #fde68a; }

.eta-label  { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; }
.eta-value  { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.eta-sub    { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

.confidence-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.confidence-bar {
  flex: 1;
  height: 6px;
  background: var(--card-border);
  border-radius: 999px;
  overflow: hidden;
  max-width: 240px;
}

.confidence-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* Delay breakdown bar */
.breakdown-bar {
  display: flex;
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.breakdown-segment {
  height: 100%;
  transition: width 0.4s ease;
}

.breakdown-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.25rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.breakdown-legend span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.breakdown-legend em {
  font-style: normal;
  font-weight: 600;
  color: var(--text);
}

/* Candidate routes table */
.estimator-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.estimator-table th {
  background: var(--card-border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.estimator-table td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--card-border);
  color: var(--text);
}

.estimator-table tr:last-child td {
  border-bottom: none;
}

.route-cell {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 0.82rem;
}

.score-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.8rem;
}

.score-high  { background: #dcfce7; color: #166534; }
.score-mid   { background: #fef9c3; color: #854d0e; }
.score-low   { background: #fee2e2; color: #991b1b; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-ok { background: #dcfce7; color: #166534; }
.badge-na { background: #f1f5f9; color: #64748b; }
