/* Ninja Remote Recording Viewer — Styles */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #232734;
    --border: #2d3142;
    --text: #e4e6eb;
    --text-dim: #8b8f9b;
    --accent: #4f9eff;
    --accent-hover: #6bb0ff;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    color: var(--text-dim);
    font-size: 0.85rem;
}

header h1 {
    font-size: 1.5rem;
    color: var(--text);
}

.back-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 8px;
    display: block;
}

.badge {
    background: var(--surface);
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
}

/* Filters */
.filters {
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.filter-row label {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    color: var(--text-dim);
    gap: 4px;
}

.filter-row input,
.filter-row select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.9rem;
    min-width: 120px;
}

.filter-row input:focus,
.filter-row select:focus {
    border-color: var(--accent);
    outline: none;
}

/* Enhancement #19: AND/OR match-mode toggle + indicator banner. */
.filter-row label.match-mode select {
    border-color: var(--accent);
    background: var(--bg);
}

.match-mode-banner {
    background: #1f3a5f;
    color: #cfe2ff;
    border: 1px solid #2a4a78;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 8px 0 12px 0;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.match-mode-banner a {
    color: #8ec5ff;
    text-decoration: underline;
    font-size: 0.85rem;
}

/* Buttons */
.btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-block;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-hover);
    border: 1px solid var(--border);
}

.btn-sm {
    padding: 3px 10px;
    font-size: 0.8rem;
}

/* Table */
.recordings-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}

.recordings-table thead {
    background: var(--surface-hover);
}

.recordings-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.recordings-table td {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}

.recordings-table tbody tr:hover {
    background: var(--surface-hover);
}

.recordings-table .empty {
    text-align: center;
    color: var(--text-dim);
    padding: 32px;
}

.tech-tag {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--accent);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 20px;
}

.page-info {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* Detail page */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
}

.detail-info {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-table th {
    text-align: left;
    padding: 8px 0;
    color: var(--text-dim);
    font-size: 0.8rem;
    width: 40%;
}

.detail-table td {
    padding: 8px 0;
    border-top: 1px solid var(--border);
}

.detail-player {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
}

.detail-player h2 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.no-player {
    text-align: center;
    padding: 40px;
    color: var(--text-dim);
}

.no-player p {
    margin-bottom: 12px;
}

.actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
}

@media (max-width: 768px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
    .filter-row {
        flex-direction: column;
    }
    .speed-shortcut-hint {
        margin-left: 0;
        margin-top: 0.25rem;
        flex-basis: 100%;
    }
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.login-error {
    background: rgba(244, 67, 54, 0.15);
    color: var(--danger);
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.login-form input {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 0.95rem;
}

.login-form input:focus {
    border-color: var(--accent);
    outline: none;
}

.btn-full {
    width: 100%;
    padding: 10px;
    margin-top: 8px;
}

/* ============================================================
   Mobile responsive (enhancement #30a)
   Breakpoints:
     - 768px : tablets & small laptops
     - 480px : phones (iPhone SE / older Android)
     - 360px : very small phones
   ============================================================ */

/* Hamburger menu button (hidden on desktop) */
.nav-toggle {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.4rem;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.nav-toggle:hover {
    background: var(--surface-hover);
}

/* Nav menu (wrapper) is always visible on desktop */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Tablet and smaller */
@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    /* Header collapses to single line with hamburger */
    header {
        flex-wrap: wrap;
        gap: 8px;
    }

    header h1 {
        font-size: 1.2rem;
        flex: 1 1 auto;
        min-width: 0;
    }

    .header-right {
        gap: 8px;
        flex-wrap: wrap;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .user-badge {
        font-size: 0.78rem;
    }

    /* Nav links become a column when menu open (toggled by hamburger) */
    .nav-menu {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        width: 100%;
        order: 3;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 8px;
        margin-top: 4px;
        flex-wrap: nowrap;
    }
    .nav-menu.open {
        display: flex;
    }
    .nav-menu a,
    .nav-menu .btn {
        width: 100%;
        text-align: left;
        padding: 10px 12px;
    }
    .nav-menu .view-toggle {
        flex-direction: column;
        margin-left: 0;
        border: none;
        overflow: visible;
    }
    .nav-menu .view-toggle a {
        width: 100%;
        text-align: left;
    }

    /* Filters: stack labels vertically, full-width inputs */
    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-row label {
        width: 100%;
    }
    .filter-row input,
    .filter-row select {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
        font-size: 1rem; /* 16px prevents iOS zoom on focus */
    }
    .filter-row .btn,
    .filter-row > a.btn {
        width: 100%;
        text-align: center;
        padding: 10px;
    }
    .filters form > div[style*="display:flex"] {
        flex-direction: column;
    }
    .filters form > div[style*="display:flex"] .btn,
    .filters form > div[style*="display:flex"] a {
        width: 100%;
        text-align: center;
    }

    /* Date preset bar wraps and stacks */
    #date-presets {
        flex-wrap: wrap;
    }
    #date-presets button {
        flex: 1 1 auto;
        min-width: 80px;
    }

    /* Detail page: single column */
    .detail-grid {
        grid-template-columns: 1fr;
    }
    .detail-player,
    .detail-info {
        padding: 14px;
    }
    .detail-info {
        order: 2; /* metadata below player on mobile */
    }
    .detail-player {
        order: 1;
    }
    .player-area video {
        max-width: 100%;
    }

    /* Recordings table -> card layout (covers .results-table and .recordings-table) */
    .recordings-table,
    .recordings-table thead,
    .recordings-table tbody,
    .recordings-table tr,
    .recordings-table td,
    .recordings-table th,
    .results-table,
    .results-table thead,
    .results-table tbody,
    .results-table tr,
    .results-table td,
    .results-table th {
        display: block;
        width: 100%;
    }
    .recordings-table thead,
    .results-table thead {
        display: none; /* hide header row, cards use data-label */
    }
    .recordings-table tr,
    .results-table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 12px;
        padding: 10px 12px;
    }
    .recordings-table td,
    .results-table td {
        border: none;
        border-bottom: 1px solid var(--border);
        padding: 8px 0;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        font-size: 0.9rem;
    }
    .recordings-table td:last-child,
    .results-table td:last-child {
        border-bottom: none;
    }
    .recordings-table td::before,
    .results-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-dim);
        font-size: 0.75rem;
        text-transform: uppercase;
        flex: 0 0 40%;
        max-width: 40%;
        word-wrap: break-word;
    }
    .recordings-table td.thumb-cell,
    .results-table td.thumb-cell {
        justify-content: center;
        padding: 8px 0;
    }
    .recordings-table td.thumb-cell::before,
    .results-table td.thumb-cell::before {
        display: none;
    }
    .recordings-table .thumb-img,
    .results-table .thumb-img {
        max-width: 160px;
    }

    /* Sessions table -> card layout (same selectors, but it's also .recordings-table) */
    /* Sessions uses table.recordings-table too - covered above */

    /* Audit table -> card layout */
    .audit-table,
    .audit-table thead,
    .audit-table tbody,
    .audit-table tr,
    .audit-table td,
    .audit-table th {
        display: block;
        width: 100%;
    }
    .audit-table thead {
        display: none;
    }
    .audit-table tr {
        background: #1a2332;
        border: 1px solid #2a3445;
        border-radius: 6px;
        margin-bottom: 10px;
        padding: 8px 10px;
    }
    .audit-table td {
        border: none;
        border-bottom: 1px solid #2a3445;
        padding: 6px 0;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 8px;
        font-size: 0.85rem;
        word-break: break-word;
    }
    .audit-table td:last-child {
        border-bottom: none;
    }
    .audit-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #8b9bb5;
        font-size: 0.7rem;
        text-transform: uppercase;
        flex: 0 0 38%;
        max-width: 38%;
    }
    .audit-table .ua,
    .audit-table .detail {
        max-width: 60%;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
    .audit-table .ip,
    .audit-table .ts {
        font-size: 0.78rem;
    }
    /* Remove the table-wrap max-height on mobile (cards are tall, scroll naturally) */
    .table-wrap {
        overflow: visible;
        max-height: none;
        border: none;
    }

    /* Session detail layout (similar to recording detail) */
    .detail-grid {
        grid-template-columns: 1fr;
    }

    /* Pagination: smaller buttons, wrap */
    .pagination {
        flex-wrap: wrap;
        gap: 6px;
    }
    .pagination a,
    .pagination span {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    /* Speed shortcut hint wraps */
    .speed-shortcut-hint {
        margin-left: 0;
        margin-top: 0.25rem;
        flex-basis: 100%;
    }

    /* Session queue panel: touch-friendly items */
    .queue-item {
        padding: 0.75rem 0.85rem;
        min-height: 48px;
    }
    .queue-item .queue-label .queue-title {
        font-size: 0.9rem;
    }
    .queue-item .queue-label .queue-sub {
        font-size: 0.75rem;
    }
    .queue-panel {
        margin-top: 0.75rem;
    }

    /* Login card full-width with less padding */
    .login-container {
        padding: 16px;
    }
    .login-card {
        padding: 24px 20px;
    }

    /* Video player controls: ensure touch-friendly */
    video {
        max-width: 100%;
    }
    /* The native HTML5 video control bar is touch-friendly on iOS/Android */

    /* Form buttons (apply/clear) full width on mobile */
    form .btn {
        min-height: 40px;
    }

    /* Code/monospace blocks: break long values */
    code {
        word-break: break-all;
    }

    /* Avoid horizontal overflow on all containers */
    body {
        overflow-x: hidden;
    }
    .container {
        overflow-x: hidden;
    }
}

/* Smaller phones */
@media (max-width: 480px) {
    .container {
        padding: 8px;
    }

    header h1 {
        font-size: 1.05rem;
    }

    .badge {
        font-size: 0.75rem;
        padding: 3px 8px;
    }

    /* Thumbnail smaller on tiny screens */
    .recordings-table .thumb-img,
    .results-table .thumb-img,
    .thumb-cell img {
        max-width: 120px;
        height: auto;
    }
    .recordings-table td,
    .results-table td {
        font-size: 0.85rem;
        padding: 6px 0;
    }
    .recordings-table td::before,
    .results-table td::before {
        font-size: 0.7rem;
    }

    .audit-table td {
        font-size: 0.8rem;
    }
    .audit-table td::before {
        font-size: 0.65rem;
    }

    /* Stack filter form actions vertically */
    .filters form > div[style*="display:flex"] {
        gap: 0.5rem;
    }
}

/* Very small phones (e.g. iPhone 5/SE 1st gen) */
@media (max-width: 360px) {
    header h1 {
        font-size: 0.95rem;
    }
    .nav-toggle {
        width: 36px;
        height: 36px;
        font-size: 1.2rem;
    }
    .recordings-table td::before {
        flex: 0 0 45%;
        max-width: 45%;
    }
}

/* Enhancement #17: Saved Searches (chips under the filter bar) */
.saved-searches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    margin: 0 0 0.75rem 0;
    padding: 0.4rem 0;
}
.saved-searches-label {
    color: #888;
    font-size: 0.8rem;
    margin-right: 0.25rem;
}
.saved-searches-empty {
    color: #555;
    font-size: 0.8rem;
    font-style: italic;
}
.saved-chip {
    display: inline-flex;
    align-items: center;
    background: #1a2b3a;
    border: 1px solid #2a4a68;
    border-radius: 999px;
    padding: 0.15rem 0.4rem 0.15rem 0.75rem;
    font-size: 0.82rem;
    color: #cfe2ff;
    transition: background 0.15s;
}
.saved-chip:hover {
    background: #233a52;
}
.saved-chip-link {
    color: inherit;
    text-decoration: none;
    margin-right: 0.35rem;
    white-space: nowrap;
}
.saved-chip-link:hover {
    text-decoration: underline;
}
.saved-chip-del {
    background: transparent;
    border: none;
    color: #ff8a8a;
    font-size: 1.05rem;
    line-height: 1;
    padding: 0 0.35rem;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
}
.saved-chip-del:hover {
    background: #4a1a1a;
    color: #fff;
}
#save-search-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
@media (max-width: 768px) {
    .saved-searches {
        gap: 0.3rem;
    }
    .saved-chip {
        font-size: 0.78rem;
    }
}
