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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    color: black;
    padding: 30px;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

.controls {
    padding: 25px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

select {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    margin-right: 10px;
    margin-bottom: 10px;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    margin-right: 10px;
}

.btn-secondary:hover {
    background: #5a6268;
}

.filter-item {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.filter-item input {
    flex: 1;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.filter-item button {
    padding: 8px 15px;
    background: #dc3545;
    color: white;
    font-size: 14px;
}

.filter-item button:hover {
    background: #c82333;
}

.info-bar {
    padding: 15px 25px;
    background: #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
}

.pagination-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    white-space: nowrap;
}

.pagination-controls button {
    padding: 6px 12px;
    font-size: 14px;
}

.table-container {
    padding: 25px;
    overflow-x: auto;
}

.loading, .error {
    text-align: center;
    padding: 40px;
    font-size: 18px;
}

.error {
    color: #dc3545;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
}

#tableWrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    overflow: visible;
    table-layout: auto; /* Auto-size based on content, but allow manual resizing */
}

thead {
    background: #667eea;
    color: white;
}

th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    white-space: normal;
    word-wrap: break-word;
    word-break: break-word;
}

td {
    padding: 8px 12px;
    border-bottom: 1px solid #e0e0e0;
    vertical-align: top;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal;
    word-wrap: break-word;
    min-width: 80px; /* Ensure minimum readable width */
    max-width: 800px; /* Allow columns to expand for long content */
}

.cell-content {
    min-width: 200px; /* Ensure readable width for content */
    max-width: 100%;
    max-height: 300px;
    overflow: auto !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    word-wrap: break-word !important;
    word-break: break-word !important;
    white-space: pre-wrap !important;
    font-family: inherit;
    line-height: 1.4;
    display: block !important;
    margin: 0;
    padding: 2px 4px;
    text-overflow: clip !important;
    box-sizing: border-box;
}

tbody tr:hover {
    background: #f8f9fa;
}

tbody tr:last-child td {
    border-bottom: none;
}

code {
    background: #f4f4f4;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

code.cell-content {
    background: #f4f4f4;
    padding: 6px;
    border-radius: 4px;
    display: block;
    min-width: 200px; /* Ensure readable width for JSON content */
    max-width: 100%;
    max-height: 300px;
    overflow: auto;
    overflow-x: auto;
    overflow-y: auto;
    white-space: pre-wrap !important;
    word-wrap: break-word;
    word-break: break-word;
    box-sizing: border-box;
}

.empty-state {
    text-align: center;
    padding: 60px;
    color: #6c757d;
}

.empty-state h2 {
    margin-bottom: 10px;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    padding: 0 25px;
}

.tab-btn {
    padding: 15px 30px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #6c757d;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.tab-btn:hover {
    color: #333;
    background: rgba(102, 126, 234, 0.1);
}

.tab-btn.active {
    color: #667eea;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background: #667eea;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* TTS Table Styles */
.tts-table {
    width: 100%;
    table-layout: auto;
}

.tts-play-col {
    width: 60px;
}

/* Override global td/th word-wrap so utterance IDs stay on one line (e.g. ut_ar-001_000001). */
.tts-table th.tts-id-col,
.tts-table td.tts-id-col {
    width: max-content;
    min-width: 14rem;
    max-width: none !important;
    white-space: nowrap !important;
    word-wrap: normal !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
    vertical-align: middle;
}

.tts-table code.tts-id-code {
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
    display: inline-block;
    max-width: none !important;
    font-size: 0.85em;
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
        monospace;
}

.play-cell {
    text-align: center;
    vertical-align: middle !important;
}

.play-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    color: #333;
    border: 1px solid #d1d1d1;
    cursor: pointer;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, border 0.2s, box-shadow 0.2s;
    padding: 0;
}

.play-btn:hover {
    background: #e6e6e6;
    color: #222;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.08);
}

.play-btn.playing {
    background: #d1f2e5;
    color: #1ca35f;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

.no-audio {
    color: #ccc;
    font-size: 18px;
}

.text-cell {
    max-width: 600px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.text-cell.rtl {
    direction: rtl;
    text-align: right;
    unicode-bidi: isolate;
}

/* ---- TTS Catalog: locale row ---- */
.tts-locale-row label {
    display: block;
    margin-bottom: 8px;
}

.tts-locale-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.tts-locale-actions select {
    flex: 1 1 220px;
    min-width: 0;
    max-width: none;
    margin-right: 0;
    margin-bottom: 0;
}

.btn-load-utterances {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* ---- TTS Catalog: filters (stacked fields; label always above control) ---- */
.tts-filter-block {
    margin-bottom: 0;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
}

.tts-filter-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
    margin-top: 4px;
}

.tts-filter-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #555;
}

.tts-filter-field select,
.tts-filter-field input[type="text"] {
    width: 100%;
    max-width: none;
    margin-right: 0;
    margin-bottom: 0;
    min-height: 44px;
    font-size: 16px; /* avoids iOS zoom on focus */
}

.tts-filter-field--full {
    grid-column: 1 / -1;
    margin-bottom: 4px;
}

/* ---- TTS pagination (layout refined in mobile section) ---- */
.pagination-controls--tts {
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.pagination-per-page {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-per-page label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #444;
    white-space: nowrap;
}

.pagination-per-page select {
    min-width: 4.5rem;
    padding: 8px 10px;
    margin: 0;
    font-size: 16px;
    min-height: 44px;
}

.pagination-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.pagination-page-meta {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
    margin-right: 4px;
}

/* ---- TTS table: readable headers + horizontal scroll on narrow viewports ---- */
.tts-table {
    min-width: 760px;
}

.tts-table thead th {
    white-space: nowrap;
    font-size: 0.8125rem;
    letter-spacing: 0.02em;
}

.tts-table td {
    font-size: 0.9375rem;
}

.table-container--tts {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    -webkit-overflow-scrolling: touch;
}

/* ---- Mobile / narrow screens ---- */
@media (max-width: 768px) {
    body {
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .container {
        border-radius: 8px;
    }

    header {
        padding: 18px 16px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .tab-nav {
        padding: 0 8px;
    }

    .tab-btn {
        flex: 1;
        padding: 14px 12px;
        font-size: 0.9rem;
        text-align: center;
    }

    .controls {
        padding: 16px 14px;
    }

    .control-group {
        margin-bottom: 16px;
    }

    .tts-locale-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .tts-locale-actions select {
        flex: none;
        width: 100%;
    }

    .btn-load-utterances {
        width: 100%;
        min-height: 44px;
    }

    .tts-filter-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .info-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        padding: 14px 16px;
    }

    .info-bar--tts #ttsRowCount {
        text-align: center;
        font-size: 0.9rem;
        line-height: 1.4;
        white-space: normal;
    }

    .info-bar--tts #ttsPagination {
        width: 100%;
    }

    .pagination-controls--tts {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        white-space: normal;
    }

    .pagination-per-page {
        justify-content: space-between;
        width: 100%;
    }

    .pagination-per-page select {
        flex: 1;
        max-width: 8rem;
    }

    .pagination-nav {
        justify-content: center;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .pagination-page-meta {
        flex: 1 1 100%;
        text-align: center;
        order: -1;
        margin-right: 0;
        margin-bottom: 4px;
    }

    .pagination-nav button {
        min-height: 44px;
        padding: 10px 16px;
        flex: 1 1 auto;
        min-width: calc(50% - 6px);
    }

    .table-container {
        padding: 12px 10px;
    }

    .tts-table {
        min-width: 720px;
    }

    .tts-table th.tts-id-col,
    .tts-table td.tts-id-col {
        min-width: 10.5rem;
    }

    .text-cell {
        max-width: none;
    }

    .play-btn {
        width: 44px;
        height: 44px;
    }

    .pagination-controls:not(.pagination-controls--tts) {
        flex-wrap: wrap;
        justify-content: center;
        white-space: normal;
        gap: 8px;
    }

    .pagination-controls:not(.pagination-controls--tts) button {
        min-height: 44px;
    }
}

@media (max-width: 380px) {
    .tab-btn {
        font-size: 0.82rem;
        padding: 12px 8px;
    }
}

