* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
}

/* ── Map Container (full-screen, IView-style) ── */
#map {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ── Header Bar ── */
#header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: #1a365d;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#header-bar h1 {
    font-size: 18px;
    font-weight: 600;
    margin-right: 24px;
}

#header-bar .nav-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 6px 14px;
    margin-right: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

#header-bar .nav-btn:hover,
#header-bar .nav-btn.active {
    background: rgba(255,255,255,0.15);
}

/* ── Auth Area ── */
#auth-area .auth-user {
    font-size: 13px;
    font-weight: 600;
}

#auth-area .auth-role {
    font-size: 11px;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 10px;
}

#auth-area .auth-btn {
    font-size: 12px;
    padding: 4px 12px;
}

/* Offset map controls below header */
.leaflet-top {
    top: 56px !important;
}

/* ── Milepoint Control ── */
.mp-control {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.mp-control button#mp-toggle-btn {
    font-weight: 700;
    color: #1a365d;
    font-size: 13px;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.mp-control button#mp-toggle-btn:hover {
    background: #f0f4ff;
}

/* ── Search Control ── */
.geocoder-control {
    max-width: 380px;
}

.geocoder-control-input {
    font-size: 14px !important;
    height: 36px !important;
}

.geocoder-control-suggestions {
    max-height: 300px;
    overflow-y: auto;
}

.geocoder-control-suggestions .geocoder-control-suggestion {
    font-size: 13px;
    padding: 6px 10px;
    line-height: 1.4;
}

.geocoder-control-suggestions .geocoder-control-suggestion:hover {
    background: #f0f4ff;
}

/* ── Bottom Results Panel ── */
#results-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    z-index: 998;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.2);
    transform: translateY(100%);
    transition: transform 0.3s ease;
    height: 40vh;
    display: flex;
    flex-direction: column;
}

#results-panel.open {
    transform: translateY(0);
}

/* Drag handle for resizing */
#results-panel-drag {
    height: 6px;
    background: #e5e7eb;
    cursor: ns-resize;
    flex-shrink: 0;
    position: relative;
}

#results-panel-drag::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 3px;
    border-top: 2px solid #aaa;
    border-bottom: 2px solid #aaa;
}

#results-panel.dragging {
    transition: none;
}

#results-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #1a365d;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    cursor: ns-resize;
}

#results-panel-close {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.results-tab {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 3px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.results-tab.active {
    background: rgba(255,255,255,0.3);
}

/* ── Hamburger Menu Dropdown ── */
#results-menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    z-index: 1001;
    min-width: 240px;
    margin-top: 4px;
    overflow: hidden;
}

.menu-mode-item, .menu-action-item {
    padding: 8px 14px;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.menu-mode-item:hover, .menu-action-item:hover {
    background: #f0f4ff;
}

.menu-mode-item .menu-check {
    display: inline-block;
    width: 16px;
    text-align: center;
}

.menu-mode-item.active .menu-check::after {
    content: '\2713';
    color: #2563eb;
    font-weight: 700;
}

.menu-divider {
    border-top: 1px solid #e5e7eb;
    margin: 4px 0;
}

.menu-action-item {
    color: #dc2626;
    font-weight: 600;
}

#results-panel-body {
    overflow-y: auto;
    flex: 1;
}

.results-table-wrap {
    overflow-x: auto;
}

.results-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.results-table-wrap th {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
    z-index: 1;
}

.results-table-wrap td {
    padding: 5px 10px;
    border-bottom: 1px solid #f0f0f0;
}

.results-table-wrap tr:hover {
    background: #f8faff;
}

.results-table-wrap .met-y { color: #16a34a; font-weight: 600; }
.results-table-wrap .met-n { color: #dc2626; font-weight: 600; }

.results-table-wrap tr.clickable-row {
    cursor: pointer;
}

.results-table-wrap tr.clickable-row:hover {
    background: #e0edff !important;
}

.results-table-wrap tr.selected {
    background: #bfdbfe !important;
    outline: 2px solid #2563eb;
}

/* ── RCI inline detail (Option A: click-to-expand) ── */
.results-table-wrap th.rci-chevron-col,
.results-table-wrap td.rci-chevron-col {
    width: 22px;
    padding-left: 8px;
    padding-right: 0;
    text-align: center;
}

.rci-chevron {
    display: inline-block;
    color: #94a3b8;
    font-size: 14px;
    transition: transform 0.15s ease;
}

.results-table-wrap tr.rci-summary-row.expanded .rci-chevron {
    transform: rotate(90deg);
    color: #2563eb;
}

.results-table-wrap tr.rci-detail-row > td {
    padding: 0;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    white-space: normal;
}

.rci-detail {
    padding: 12px 16px;
}

.rci-detail-groups {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px 24px;
}

.rci-detail-group h4 {
    margin: 0 0 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #2563eb;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 2px;
}

.rci-detail-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 0;
    font-size: 12px;
}

.rci-detail-label { color: #64748b; }
.rci-detail-value { color: #0f172a; font-weight: 600; text-align: right; word-break: break-word; }

.rci-detail-synced {
    margin-top: 10px;
    font-size: 11px;
    color: #94a3b8;
    font-style: italic;
}

.rci-detail-empty {
    margin: 0;
    color: #94a3b8;
    font-size: 12px;
}

/* ── Record Label Box (IView SIO labeler style) ── */
.record-label-icon {
    background: none !important;
    border: none !important;
}

.record-label-box {
    background: white;
    padding: 3px 8px;
    border: 2px solid #2563eb;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
    color: #1a365d;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    cursor: grab;
}

.record-label-box:active {
    cursor: grabbing;
}

/* Milepost tooltip */
.mp-tooltip {
    background: #1a365d;
    color: white;
    border: none;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.mp-tooltip::before {
    border-bottom-color: #1a365d !important;
}

/* Attachment layer tooltip */
.attachment-tooltip {
    background: #16a34a;
    color: white;
    border: none;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
}

.attachment-tooltip::before {
    border-bottom-color: #16a34a !important;
}

/* ── Attachment Upload Row ── */
.attach-add-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8faff;
}

.attach-add-row button {
    background: #2563eb;
    color: white;
    border: none;
    padding: 5px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.attach-add-row button:hover {
    background: #1d4ed8;
}

.attach-status {
    font-size: 12px;
    color: #888;
}

/* ── Side Panel ── */
#side-panel {
    position: fixed;
    top: 48px;
    right: 0;
    width: 380px;
    height: calc(100% - 48px);
    background: white;
    z-index: 999;
    box-shadow: -2px 0 8px rgba(0,0,0,0.15);
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

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

#side-panel .panel-header {
    background: #2d4a7a;
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

#side-panel .panel-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

#side-panel .panel-body {
    padding: 16px;
}

/* ── Data Table Styles ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th,
.data-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.data-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #444;
}

.data-table tr:hover {
    background: #f0f4ff;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
}

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

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-success {
    background: #16a34a;
    color: white;
}

.btn-success:hover {
    background: #15803d;
}

.btn-danger {
    background: #dc2626;
    color: white;
}

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

/* ── File Upload ── */
.upload-zone {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    color: #888;
    cursor: pointer;
    transition: border-color 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: #2563eb;
    color: #2563eb;
}

.file-list {
    list-style: none;
    margin-top: 8px;
}

.file-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}

/* ── Popup Styles (IView-inspired) ── */
.leaflet-popup-content-wrapper {
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.leaflet-popup-content {
    font-size: 13px;
    line-height: 1.5;
}

.popup-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 6px;
    color: #1a365d;
}

.popup-field {
    margin-bottom: 2px;
}

.popup-field strong {
    color: #555;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    #side-panel {
        width: 100%;
    }

    #header-bar h1 {
        font-size: 15px;
    }
}

/* ── Route Survey video player — docked at bottom so the map stays visible ── */
#route-video-modal {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    pointer-events: none;
    /* let map clicks pass through the empty area */
}

/* No backdrop — the map must remain visible/interactive while the dot moves. */
#route-video-modal-backdrop {
    display: none;
}

#route-video-modal-box {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(640px, 96vw);
    min-width: 300px;
    min-height: 220px;
    max-width: 98vw;
    background: #fff;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
    padding: 12px 14px 14px;
    pointer-events: auto;
    resize: both;
    overflow: hidden;
}

#route-video-player {
    width: 100%;
    max-height: calc(100% - 52px);
    background: #000;
}

/* Title bar doubles as the drag handle. */
#route-video-modal-title {
    cursor: move;
    user-select: none;
}

#route-video-modal-close {
    position: absolute;
    top: 6px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #555;
    z-index: 1;
}

#route-video-modal-title {
    font-weight: 600;
    margin-bottom: 6px;
    padding-right: 24px;
    font-size: 13px;
}

/* ── Moving dot + heading arrow synced to video playback ── */
.d7-video-dot {
    position: relative;
}

.d7-video-dot-core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border-radius: 50%;
    background: #2563eb;
    border: 2px solid #fff;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
}

.d7-video-dot-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    transform-origin: center center;
}

/* Arrow points "up" (north) at heading 0; the wrap rotates it to bearing. */
.d7-video-dot-arrow {
    position: absolute;
    left: -7px;
    top: -20px;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 12px solid #ffdd00;
    filter: drop-shadow(0 0 1px #333);
}

/* ── Floating Route Survey status box ── */
#route-status-box {
    display: none;
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 300px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 1200;
    font-size: 12px;
    overflow: hidden;
}

#route-status-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1e3a5f;
    color: #fff;
    padding: 8px 10px;
    font-weight: 600;
}

#route-status-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

#route-status-body {
    max-height: 220px;
    overflow-y: auto;
    padding: 8px 10px;
}

.route-status-line {
    padding: 3px 0;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    word-break: break-word;
}

.route-status-line:last-child {
    border-bottom: none;
}

.route-status-line.err {
    color: #b91c1c;
}

/* ── Transcode-completion toasts (global, bottom-right) ── */
#d7-toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.d7-toast {
    background: #1f2937;
    color: #fff;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    font-size: 13px;
    line-height: 1.4;
    border-left: 4px solid #6b7280;
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.d7-toast-success {
    border-left-color: #16a34a;
}

.d7-toast-error {
    border-left-color: #dc2626;
}

.d7-toast-hide {
    opacity: 0;
    transform: translateX(20px);
}
