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

:root {
    --primary: #1a73e8;
    --primary-dark: #1558b0;
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 16px;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Offline banner ──────────────────────────────────────────────── */
.offline-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--warning);
    color: #fff;
    text-align: center;
    padding: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 9999;
}

/* ── Toast ────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.9rem;
    z-index: 9998;
    box-shadow: var(--shadow);
    transition: opacity 0.3s;
}

/* ── Header ──────────────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--primary);
    color: #fff;
    flex-shrink: 0;
    gap: 24px;
}
.app-title { font-size: clamp(1rem, 4vw, 1.25rem); font-weight: 700; }
.header-right { display: flex; gap: 8px; align-items: center; }
.app-header .btn-lang-toggle {
    border-color: #fff;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 0.8rem;
    padding: 5px 12px;
}
.app-header .btn-lang-toggle:hover { background: #fff; color: var(--primary); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-large { padding: 16px 24px; font-size: 1.05rem; }
.btn-full { width: 100%; }
.btn-icon {
    background: none; border: none; color: inherit;
    cursor: pointer; padding: 8px; border-radius: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }
.btn-small { padding: 4px 8px; font-size: 0.85rem; }

/* ── Search ──────────────────────────────────────────────────────── */
.search-container {
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: 12px;
    padding: 4px 12px;
    gap: 8px;
}
.search-icon { flex-shrink: 0; color: var(--text-secondary); }
.search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 1rem;
    padding: 10px 0;
    outline: none;
    color: var(--text);
}
.btn-search {
    border: none;
    background: var(--primary);
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ── Map ─────────────────────────────────────────────────────────── */
.map-container {
    flex: 1;
    position: relative;
    min-height: 0;
}
.map-view {
    width: 100%;
    height: 100%;
}
.map-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #e8edf2;
    color: var(--text-secondary);
    text-align: center;
    padding: 32px 28px;
    gap: 8px;
}
.map-placeholder .sub { font-size: 0.85rem; }

/* ── Panels (results, favorites, route, saved-routes) ────────────── */
.results-panel, .favorites-panel, .route-panel, .saved-routes-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    max-height: 50%;
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    overflow-y: auto;
    z-index: 100;
    padding: 16px;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.panel-header h2 { font-size: 1.1rem; }
.panel-header-actions { display: flex; align-items: center; gap: 4px; }
.btn-lang-toggle {
    border: 1.5px solid var(--primary);
    background: var(--card);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.btn-lang-toggle:hover { background: var(--primary); color: #fff; }

/* ── Result cards ────────────────────────────────────────────────── */
.results-list { display: flex; flex-direction: column; gap: 24px; }
.poi-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 32px 28px;
    cursor: pointer;
    transition: box-shadow 0.2s;
    touch-action: manipulation;
}
.poi-card:hover { box-shadow: var(--shadow); }
.poi-card--active {
    box-shadow: 0 0 0 2px var(--primary), var(--shadow);
    background: #eef3fb;
}
.poi-card-name {
    font-weight: 700; font-size: 1rem; margin-bottom: 4px;
    display: flex; align-items: center;
}
.poi-card-number {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; min-width: 22px;
    background: var(--primary); color: #fff; border-radius: 50%;
    font-size: 0.75rem; font-weight: 700; margin-right: 8px;
}
.poi-card--active .poi-card-number { background: var(--danger); }
.poi-card-addr { color: var(--text-secondary); font-size: 0.85rem; }
.poi-card-desc { color: var(--text-secondary); font-size: 0.8rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poi-card-cat { color: var(--primary); font-size: 0.8rem; margin-top: 4px; }

/* ── Route inputs ────────────────────────────────────────────────── */
.route-inputs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.route-input-row { display: flex; align-items: center; gap: 8px; }
.route-input-dot {
    width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}
.route-input-dot--origin { background: var(--success); }
.route-input-dot--dest { background: var(--danger); }
.route-input {
    flex: 1; border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font-size: 0.9rem; background: var(--bg);
    color: var(--text); outline: none; cursor: pointer;
}
.route-input:focus { border-color: var(--primary); }
.route-input.filled { background: var(--card); font-weight: 500; }
.route-result-actions { display: flex; gap: 8px; margin-bottom: 12px; }

/* ── Route ───────────────────────────────────────────────────────── */
.route-type-selector { display: flex; gap: 8px; margin-bottom: 12px; }
.route-type-btn {
    flex: 1; border: 2px solid var(--border); background: var(--card);
    border-radius: 8px; padding: 8px; font-weight: 600; cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.route-type-btn.active { border-color: var(--primary); color: var(--primary); }
.route-summary { padding: 12px; background: var(--bg); border-radius: 8px; margin-bottom: 12px; }
.route-steps { display: flex; flex-direction: column; gap: 8px; }
.route-step {
    padding: 10px 14px;
    background: var(--bg);
    border-radius: 8px;
    font-size: 0.9rem;
}

/* ── Saved routes ────────────────────────────────────────────────── */
.saved-routes-list { display: flex; flex-direction: column; gap: 12px; }
.saved-route-card {
    background: var(--bg); border-radius: var(--radius); padding: 16px;
    cursor: pointer; transition: box-shadow 0.2s;
}
.saved-route-card:hover { box-shadow: var(--shadow); }
.saved-route-names { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.saved-route-meta { font-size: 0.8rem; color: var(--text-secondary); }
.saved-route-type { display: inline-block; background: var(--primary); color: #fff;
    padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; margin-right: 6px; }

/* ── Map picking mode ────────────────────────────────────────────── */
.map-picking { cursor: crosshair !important; }
.map-picking .leaflet-container { cursor: crosshair !important; }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 500;
    padding: 16px;
}
.modal-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 28px;
    max-width: 420px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.auth-buttons { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
.auth-info { font-size: 0.8rem; color: var(--text-secondary); text-align: center; }

/* ── POI detail ──────────────────────────────────────────────────── */
.poi-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.poi-actions .btn { flex: 1; min-width: 80px; text-align: center; }

/* ── Favorites list ──────────────────────────────────────────────── */
.favorites-list { display: flex; flex-direction: column; gap: 24px; }
.empty-msg { text-align: center; color: var(--text-secondary); padding: 24px; }
.fav-card {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg); border-radius: var(--radius); padding: 32px 28px;
}
.fav-card-info { flex: 1; cursor: pointer; }
.fav-card-name { font-weight: 600; }
.fav-card-addr { font-size: 0.85rem; color: var(--text-secondary); }

/* ── Offline badge ───────────────────────────────────────────────── */
.badge-offline {
    display: inline;
    font-size: 0.65rem;
    font-weight: 500;
    background: var(--warning);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ── Numbered map markers ──────────────────────────────────────── */
.numbered-marker { background: none !important; border: none !important; }
.marker-number {
    width: 28px; height: 28px;
    background: var(--primary); color: #fff;
    border: 2px solid #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.2s, background 0.2s;
}
.marker-number--active {
    background: var(--danger);
    transform: scale(1.3);
    box-shadow: 0 3px 10px rgba(239,68,68,0.4);
}

/* ── Offline panel ──────────────────────────────────────────────── */
.offline-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    max-height: 60%;
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    overflow-y: auto;
    z-index: 100;
    padding: 16px;
}
.offline-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.offline-regions-list { display: flex; flex-direction: column; gap: 10px; }
.offline-region-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
    border-radius: 12px;
    padding: 14px 16px;
}
.offline-region-info { flex: 1; }
.offline-region-name { font-weight: 600; font-size: 0.95rem; }
.offline-region-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.offline-region-actions { display: flex; align-items: center; gap: 8px; }
.btn-download {
    border: none;
    background: var(--primary);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.btn-download:hover { background: var(--primary-dark); }
.btn-download:disabled { background: var(--border); color: var(--text-secondary); cursor: default; }
.btn-delete-region {
    border: none;
    background: var(--danger);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.badge-downloaded {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--success);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
}

/* ── Progress bar ──────────────────────────────────────────────── */
.offline-progress { margin-bottom: 12px; }
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s;
}
.progress-text { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px; }

/* ── Leaflet overrides ──────────────────────────────────────────── */
#leaflet-map { z-index: 1; }
.leaflet-control-attribution { font-size: 10px; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (min-width: 768px) {
    .results-panel, .favorites-panel, .route-panel, .saved-routes-panel, .offline-panel {
        max-width: 420px;
        left: 16px;
        right: auto;
        bottom: 16px;
        border-radius: var(--radius);
        max-height: calc(100dvh - 180px);
    }
}
