/* ============================================================
   Route Tracker — Main Stylesheet
   Mobile-first. All layout defaults are 1-column (phone).
   2-column layouts are added via @media (min-width: 769px).
   ============================================================ */

/* ── 1. CSS Variables ─────────────────────────────────────── */
:root {
    --primary-color: #e0e0e0;
    --secondary-color: #3498db;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --error-color: #e74c3c;
    --light-bg: #1f2235;
    --text-color: #e0e0e0;
    --text-dark: #e0e0e0;
    --text-light: rgba(255,255,255,0.45);
    --border-color: #2a2d3e;
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
    --shadow-hover: 0 2px 8px rgba(0,0,0,0.5);
    --border-radius: 8px;
    --transition: all 0.3s ease;
    --gradient-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    --bg-body: #0f1117;
    --bg-card: #1a1d2e;
    --bg-card-inner: #161929;
    --bg-input: rgba(255,255,255,0.06);
}

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

html, body {
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-body);
    min-height: 100vh;
    color: var(--text-color);
    line-height: 1.6;
}

/* ── 3. Page Layout ───────────────────────────────────────── */
.route-tracker-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 14px;
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: start;
}

/* ── 4. Header ────────────────────────────────────────────── */
/* Reset shared-styles.css .header which adds padding:2rem and margin:2rem */
.header {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    margin: 0;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.header-content h1 {
    color: var(--primary-color);
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
}

.header-content h1 i {
    color: var(--secondary-color);
    margin-right: 0.5rem;
}

.header-content .subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
}

.breadcrumb {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    width: 100%;
}

.breadcrumb a {
    color: var(--secondary-color);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* ── 5. Buttons ───────────────────────────────────────────── */
.btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-family: inherit;
    min-width: 0;
}

.btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    text-decoration: none;
    color: white;
}

.btn-primary  { background: var(--secondary-color); }
.btn-primary:hover  { background: #2980b9; }
.btn-success  { background: var(--success-color); }
.btn-success:hover  { background: #219a52; }
.btn-warning  { background: var(--warning-color); }
.btn-warning:hover  { background: #d68910; }
.btn-secondary { background: #6c757d; }
.btn-secondary:hover { background: #5a6268; }
.btn-danger   { background: var(--error-color); }
.btn-danger:hover   { background: #c0392b; }
.btn-info     { background: #17a2b8; }
.btn-info:hover     { background: #138496; }

.btn-sm {
    padding: 4px 10px;
    font-size: 0.82rem;
}

.btn-large {
    width: 100%;
    justify-content: center;
    font-size: 1.1rem;
    padding: 1.25rem 2rem;
}

/* ── 6. Section Headers ───────────────────────────────────── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}

/* ── 7. Panels ────────────────────────────────────────────── */
.control-panel {
    background: var(--bg-card);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid #3498db;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

/* ── Compact GPS 2-line bar ───────────────────────────────── */
.gps-compact-panel {
    padding: 6px 10px;
}

.gps-bar-line {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    flex-wrap: nowrap;
}

.gps-bar-line + .gps-bar-line {
    border-top: 1px solid var(--border-color);
    margin-top: 5px;
    padding-top: 5px;
}

/* Traffic-light dot */
.gps-ampel {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(0,0,0,0.15);
    box-shadow: 0 0 0 2px rgba(255,255,255,0.08);
    transition: background 0.3s;
}
.gps-ampel.status-active   { background: var(--success-color, #2ecc71); box-shadow: 0 0 6px rgba(46,204,113,0.6); }
.gps-ampel.status-inactive { background: #6e6e6e; }

.gps-bar-name {
    font-weight: 600;
    font-size: 0.9em;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    flex-shrink: 1;
}

/* All action buttons – pushed to the far right */
.gps-bar-actions-right {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.btn-icon-gps {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-card-inner);
    color: var(--text-color);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    transition: filter 0.15s;
    padding: 0;
    box-sizing: border-box;
    flex-shrink: 0;
}
/* Solid-color variants – hover just dims, no size/border change */
.btn-icon-gps.btn-icon-active  { background: var(--success-color, #2ecc71); color: #fff; border-color: var(--success-color, #2ecc71); }
.btn-icon-gps.btn-icon-stopped { background: #e74c3c;                       color: #fff; border-color: #e74c3c; }
.btn-icon-gps.btn-icon-pause   { background: #f39c12;                       color: #fff; border-color: #f39c12; }
.btn-icon-gps.btn-icon-play    { background: var(--success-color, #2ecc71); color: #fff; border-color: var(--success-color, #2ecc71); }
.btn-icon-gps.btn-icon-primary { background: #3498db; color: #fff; border-color: #3498db; }
.btn-icon-gps.btn-icon-exit    { background: #e74c3c;                       color: #fff; border-color: #e74c3c; }
/* Hover: dim only – no dimension change */
.btn-icon-gps:hover { filter: brightness(1.18); }
.btn-icon-gps:not([class*="btn-icon-active"]):not([class*="btn-icon-stopped"]):not([class*="btn-icon-pause"]):not([class*="btn-icon-play"]):not([class*="btn-icon-primary"]):not([class*="btn-icon-exit"]):hover {
    filter: none;
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.gps-rate-select {
    height: 26px;
    line-height: 26px;
    padding: 0 6px;
    font-size: 0.82em;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card-inner);
    color: var(--text-color);
    cursor: pointer;
    box-sizing: border-box;
}

/* ── Modern pill-shaped device selector ──────────────────── */
.gps-device-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card-inner);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 3px 28px 3px 10px;
    min-width: 100px;
    max-width: 240px;
    flex: 1;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.gps-device-wrap:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52,152,219,0.25);
}
.gps-device-wrap::after {
    content: '▾';
    position: absolute;
    right: 10px;
    font-size: 0.9em;
    color: var(--text-light);
    pointer-events: none;
    line-height: 1;
}
.gps-device-icon {
    color: var(--primary-color);
    font-size: 0.82em;
    flex-shrink: 0;
}
.gps-device-select {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    flex: 1;
    min-width: 0;
    outline: none;
    padding: 0;
}

.gps-route-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.82em;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    flex-shrink: 1;
}

/* ── Mobile: hide refresh-rate selector, allow wrapping ─── */
@media (max-width: 600px) {
    .gps-rate-select { display: none !important; }
    .gps-bar-name    { max-width: 110px; }
    .gps-device-wrap { max-width: 180px; }
    .gps-route-indicator { max-width: 140px; }
}

.stats-dashboard {
    background: var(--bg-card);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid #2ecc71;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.export-panel {
    background: var(--bg-card);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid #f39c12;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    align-self: start;
    height: fit-content;
}

.route-history {
    background: var(--bg-card);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid #17a2b8;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.config-section {
    background: var(--bg-card);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid #9b59b6;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.status-panel {
    background: var(--bg-card-inner);
    padding: 12px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    min-width: 0;
}

.device-selector-panel {
    background: var(--bg-card-inner);
    padding: 15px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

/* ── 8. Grids — Mobile-first (1-column default) ───────────── */
.control-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 0;
}

/* Inner status/control grids */
.status-details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 10px;
    min-width: 0;
}

.control-settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 10px;
    min-width: 0;
}

.export-buttons-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

/* Route management */
.route-management {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    align-items: start;
}

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

/* History filters */
.history-filters {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
}

/* ── 9. Stat Cards ────────────────────────────────────────── */
.stat-card {
    background: var(--bg-card-inner);
    padding: 10px 8px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary-color);
    display: block;
    margin-bottom: 4px;
}

.stat-label {
    color: var(--text-light);
    font-size: 0.76em;
    font-weight: 500;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ── 10. Map ──────────────────────────────────────────────── */
.map-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-hover);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.map-section.map-edit-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 5000;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
}

.map-edit-fullscreen .map-container {
    flex: 1;
    height: unset;
    min-height: unset;
}

.map-header {
    background: var(--bg-card-inner);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.map-container {
    height: 45vh;
    min-height: 250px;
    position: relative;
}

#map {
    height: 100%;
    width: 100%;
}

.leaflet-container { background: #1a1d2e; }
.leaflet-tile { max-width: none !important; max-height: none !important; }

/* ── 11. Route Items ──────────────────────────────────────── */
.route-item {
    display: flex;
    flex-direction: column;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    background: var(--bg-card-inner);
    transition: all 0.2s ease;
}

.route-item:hover {
    background: #1f2438;
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.route-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.route-info h4 {
    margin: 0;
    color: #e0e0e0;
    font-size: 1rem;
}

.route-meta {
    color: var(--text-light);
    font-size: 0.82em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    width: 100%;
}

.history-action-btn {
    padding: 4px 8px;
    font-size: 0.74rem;
    line-height: 1.2;
}

/* ── 12. History Filters ──────────────────────────────────── */
.history-filters .filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.history-filters input[type="date"] {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.8rem;
    width: 100%;
    background: var(--bg-input);
    color: var(--text-color);
    color-scheme: dark;
}

/* ── 13. Archive Calendar ─────────────────────────────────── */
.archive-calendar {
    margin-top: 14px;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.archive-calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.archive-calendar-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
}

.archive-calendar-nav {
    display: flex;
    gap: 6px;
}

.archive-calendar-nav .btn {
    min-width: 30px;
    padding: 4px 8px;
}

.archive-calendar-month {
    text-align: center;
    font-size: 0.84rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.archive-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.archive-calendar-weekday {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-light);
    padding: 2px 0;
    font-weight: 600;
}

.archive-calendar-day {
    border: 1px solid var(--border-color);
    background: var(--bg-card-inner);
    border-radius: 6px;
    font-size: 0.76rem;
    line-height: 1;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    color: var(--text-color);
}

.archive-calendar-day.empty    { border-color: transparent; background: transparent; cursor: default; }
.archive-calendar-day.has-archive { border-color: #2ecc71; background: rgba(46,204,113,0.15); font-weight: 700; }
.archive-calendar-day.selected { border-color: #3498db; background: rgba(52,152,219,0.2); box-shadow: inset 0 0 0 1px #3498db; }

.archive-calendar-day-count {
    position: absolute;
    bottom: 2px;
    right: 3px;
    font-size: 0.6rem;
    color: #2e7d32;
    font-weight: 700;
}

.archive-calendar-hint {
    margin-top: 8px;
    font-size: 0.74rem;
    color: var(--text-light);
}

/* ── 14. Status Indicators ────────────────────────────────── */
.status-text {
    font-family: monospace;
    background: rgba(255,255,255,0.06);
    color: #e0e0e0;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    min-width: 0;
}

.status-active   { color: var(--success-color); font-weight: bold; }
.status-inactive { color: var(--text-light); }

/* ── 15. Forms ────────────────────────────────────────────── */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input,
.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-color);
    min-width: 0;
}

.form-group input::placeholder { color: var(--text-light); }
.form-control::placeholder      { color: var(--text-light); }

select.form-control option {
    background: #1a1d2e;
    color: #e0e0e0;
}

.form-control:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--secondary-color);
    background: rgba(255,255,255,0.08);
    box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}

/* ── 16. Overlays & Modals ────────────────────────────────── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
}

.overlay.show { display: block; }

.login-form, .register-form {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-hover);
    z-index: 1001;
    min-width: 300px;
    width: 90%;
    max-width: 400px;
}

.login-form.show, .register-form.show { display: block; }

/* ── 17. Notifications ────────────────────────────────────── */
.notifications {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1002;
}

.notification {
    background: var(--success-color);
    color: white;
    padding: 15px 20px;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    transform: translateX(400px);
    transition: var(--transition);
}

.notification.show    { transform: translateX(0); }
.notification.error   { background: var(--error-color); }
.notification.warning { background: var(--warning-color); }

/* ── 18. Offline Indicator ────────────────────────────────── */
.offline-indicator {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--warning-color);
    color: white;
    padding: 10px 15px;
    border-radius: var(--border-radius);
    z-index: 1000;
    display: none;
}

.offline-indicator.show { display: block; }

/* ── 19. Context Menu ─────────────────────────────────────── */
#route-context-menu {
    display: none;
    position: absolute;
    z-index: 10001;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    overflow: hidden;
    min-width: 170px;
}

.ctx-item {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
    color: var(--text-color);
}

.ctx-item:hover               { background: rgba(255,255,255,0.07); }
.ctx-item.ctx-danger:hover    { background: rgba(231,76,60,0.15); color: #e74c3c; }
.ctx-separator                { height: 1px; background: var(--border-color); margin: 0; }

/* ── 20. Edit Toolbar ─────────────────────────────────────── */
#edit-toolbar {
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(243,156,18,0.12);
    border-bottom: 2px solid #f39c12;
    padding: 8px 16px;
    font-size: 0.9em;
}

#edit-toolbar span { flex: 1; color: #f39c12; }

/* ── 21. Route Point Editing ──────────────────────────────── */
.edit-point-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid;
    cursor: grab;
    box-shadow: 0 0 5px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.edit-point-dot:active { cursor: grabbing; }
.edit-point-new        { font-size: 10px; font-weight: bold; color: white; line-height: 1; }

/* ── 22. Route Merge Checkbox ─────────────────────────────── */
.route-merge-check {
    display: flex;
    align-items: center;
    padding: 0 6px 0 2px;
    cursor: pointer;
    flex-shrink: 0;
}

.route-merge-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* ── 23. Main App Border ──────────────────────────────────── */
#main-app { border: none; }

/* ── 24. Role-based Visibility ────────────────────────────── */
.role-viewer .admin-only          { display: none !important; }
.role-admin  .viewer-only         { display: none !important; }
.role-viewer #gps-status-btn      { pointer-events: none; cursor: default; opacity: 0.85; }

/* ── 25. Endpoint / Setup Info ────────────────────────────── */
.endpoint-info {
    background: rgba(52,152,219,0.1);
    border: 1px solid rgba(52,152,219,0.25);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-top: 10px;
    font-family: monospace;
    font-size: 0.9em;
    color: #7ec8e3;
}

.setup-section {
    background: var(--bg-card-inner);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-top: 15px;
}

.setup-section code {
    background: #333;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

/* ── 26. Language Switcher ────────────────────────────────── */
.language-switcher .language-option:hover  { background: rgba(255,255,255,0.1); }
.language-switcher .language-option.active { background: rgba(46,204,113,0.2); color: #2ecc71; font-weight: 600; }
.dropdown-menu a:hover { background: rgba(255,255,255,0.07) !important; }
.dropdown-toggle:hover { opacity: 0.8; }

/* ── 27. Misc shared elements ─────────────────────────────── */
.status-details-grid > div,
.control-settings-grid > .btn,
.control-settings-grid > .form-control,
#device-selector,
#device-selector-viewer {
    min-width: 0;
}

/* Dark theme: re-colour native elements inside dark panels */
.status-panel h4,
.status-panel small,
.control-panel h4,
.config-section p,
.config-section li,
.config-section ol,
.config-section strong {
    color: var(--text-color);
}

.status-panel small { color: var(--text-light); }

.map-header h3 { color: #e0e0e0 !important; }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ── Small tablet (769px–899px) — e.g. iPad 10 portrait ───── */
/* Layout becomes 2-column for stat cards and side-by-side    */
/* status panels. Inner button grids stay 1-column to prevent */
/* overflow of longer translated button labels.              */
@media (min-width: 769px) {
    .route-tracker-container {
        padding: 16px;
        gap: 16px;
    }

    .header {
        padding: 14px 18px;
        margin: 0;
    }

    .header-content h1  { font-size: 1.9rem; }

    .main-content { gap: 14px; }

    .control-panel,
    .stats-dashboard,
    .export-panel,
    .route-history,
    .config-section,
    .status-panel {
        padding: 14px 16px;
    }

    .control-grid {
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        gap: 12px;
        margin-bottom: 0;
    }

    /* Inner button grids: stay single-column at narrow tablet
       widths — goes 2-col at 900px+ where columns are wide enough */
    .status-details-grid,
    .control-settings-grid  { grid-template-columns: 1fr; }

    .export-buttons-grid    { grid-template-columns: 1fr; }
    .route-management       { grid-template-columns: 1fr; }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 12px;
    }

    .stat-card   { padding: 14px 10px; }
    .stat-value  { font-size: 1.8em; margin-bottom: 6px; }
    .stat-label  { font-size: 0.82em; }

    .section-title { font-size: 1.15rem; }

    .map-container {
        height: 50vh;
        min-height: 300px;
    }
}

/* ── Wide tablet & phablet landscape (min-width: 900px) ───── */
/* At 900px, inner button grids have enough width for 2 cols  */
/* and route-management can safely go side-by-side.          */
@media (min-width: 900px) {
    .route-tracker-container {
        padding: 18px;
        gap: 16px;
    }

    .header {
        padding: 14px 20px;
        margin: 0;
    }

    .header-content h1  { font-size: 2rem; }

    .main-content { gap: 16px; }

    .control-panel,
    .stats-dashboard,
    .export-panel,
    .route-history,
    .config-section,
    .status-panel {
        padding: 16px 18px;
    }

    .control-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 12px;
        margin-bottom: 0;
    }

    .status-details-grid,
    .control-settings-grid  { grid-template-columns: 1fr 1fr; }

    .export-buttons-grid    { grid-template-columns: 1fr 1fr; gap: 10px; }
    .route-management       { grid-template-columns: 1fr 1fr; gap: 12px; }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 10px;
    }

    .stat-card   { padding: 14px 12px; }
    .stat-value  { font-size: 1.9em; margin-bottom: 6px; }
    .stat-label  { font-size: 0.88em; }

    .section-title { font-size: 1.15rem; }

    .map-container {
        height: 56vh;
        min-height: 400px;
    }
}

/* ── Large Desktop (min-width: 1025px) ───────────────────── */
@media (min-width: 1025px) {
    .route-tracker-container { padding: 20px; gap: 18px; }

    .control-panel,
    .stats-dashboard,
    .export-panel,
    .route-history,
    .config-section {
        padding: 18px 20px;
    }

    .map-container {
        height: 65vh;
        min-height: 500px;
    }

    .header {
        padding: 16px 22px;
        margin: 0;
    }

    .header-content h1 { font-size: 2.2rem; }

    .main-content { gap: 18px; }
}

/* ── Phone landscape (short viewport) ────────────────────── */
/* iPhone 15 Pro Max landscape = 932×430 CSS px.             */
/* Without this, map min-height:400px fills the entire       */
/* 430px-tall landscape viewport.                            */
@media (orientation: landscape) and (max-height: 500px) {
    .route-tracker-container {
        padding: 8px;
        gap: 10px;
    }

    .header {
        padding: 8px 14px;
        margin: 0;
    }

    .header-content h1   { font-size: 1.3rem; }
    .header-content .subtitle { display: none; }

    .control-panel,
    .stats-dashboard,
    .export-panel,
    .route-history,
    .config-section,
    .status-panel {
        padding: 10px 14px;
    }

    .map-container {
        height: 38vh;
        min-height: 150px;
    }

    .stat-card  { padding: 8px 6px; }
    .stat-value { font-size: 1.3em; }
    .stat-label { font-size: 0.72em; }

    .section-header { margin-bottom: 10px; }
}

/* ── Phone portrait: safe-area + touch (max-width: 430px) ── */
@media (max-width: 430px) {
    .route-tracker-container {
        padding: max(10px, env(safe-area-inset-left))
                 max(10px, env(safe-area-inset-right))
                 max(12px, env(safe-area-inset-bottom))
                 max(10px, env(safe-area-inset-left));
        gap: 10px;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .section-header .btn {
        width: 100%;
        justify-content: center;
    }

    /* #gps-status-btn is now an icon-only button in the compact bar — no full-width override */

    .breadcrumb {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px;
    }

    .breadcrumb > div {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px !important;
        margin-left: 0 !important;
    }

    .route-actions .btn,
    .history-action-btn,
    .archive-calendar-nav .btn {
        min-height: 36px;
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .archive-calendar-day { min-height: 32px; font-size: 0.78rem; }
    .route-meta           { white-space: normal; }
}

/* ── Narrow phones (max-width: 393px) ────────────────────── */
@media (max-width: 393px) {
    .section-title { font-size: 1.05rem; }
    .stat-value    { font-size: 1.3em; }

    .route-actions .btn {
        flex: 1 1 calc(50% - 6px);
        justify-content: center;
    }
}
