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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    color: #e0e0e0;
}

html[data-theme="light"] {
    background: #e5e5e5;
    min-height: 100vh;
}

html[data-theme="light"] body {
    background: linear-gradient(135deg, #f0f0f0 0%, #e5e5e5 100%);
    color: #222;
}

html[data-theme="light"] header.main-header h1 {
    color: #1976d2;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px 12px;
}

header.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 0 4px;
}

header.main-header h1 {
    color: #4fc3f7;
    font-size: 1.5rem;
    margin: 0;
    text-shadow: 0 2px 10px rgba(79, 195, 247, 0.3);
}

/* Theme toggle: sun = dark mode (click for light), moon = light mode (click for dark) */
.theme-toggle-btn {
    font-size: 1rem;
    padding: 4px 10px;
    min-width: auto;
    color: #888;
    background: rgba(255,255,255,0.05);
    border: 1px solid #333;
    border-radius: 4px;
    cursor: pointer;
}

.theme-toggle-btn:hover {
    color: #4fc3f7;
    border-color: #4fc3f7;
}

html[data-theme="light"] .theme-toggle-btn {
    color: #333;
    background: rgba(0,0,0,0.05);
    border-color: #ccc;
}

html[data-theme="light"] .theme-toggle-btn:hover {
    color: #1976d2;
    border-color: #1976d2;
}

/* Top row: view toggle left, key right-aligned */
.top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.view-toggle-row {
    display: flex;
    gap: 4px;
}

.view-tab {
    padding: 4px 12px;
    font-size: 0.72rem;
    color: #888;
    background: rgba(255,255,255,0.05);
    border: 1px solid #333;
    border-radius: 4px;
    cursor: pointer;
}

.view-tab:hover, .view-tab.active {
    color: #4fc3f7;
    border-color: #4fc3f7;
}

.view-tab.active {
    background: rgba(79, 195, 247, 0.15);
}

html[data-theme="light"] .view-tab {
    color: #666;
    background: #fff;
    border-color: #ccc;
}

html[data-theme="light"] .view-tab:hover,
html[data-theme="light"] .view-tab.active {
    color: #1976d2;
    border-color: #1976d2;
}

html[data-theme="light"] .view-tab.active {
    background: rgba(25, 118, 210, 0.1);
}

/* Auth inline: right-aligned in top row */
.auth-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.auth-label {
    font-size: 0.72rem;
    color: #aaa;
}

html[data-theme="light"] .auth-label {
    color: #555;
}

.auth-input {
    width: 200px;
    max-width: 240px;
    padding: 4px 8px;
    font-size: 0.75rem;
    border: 1px solid #333;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
}

html[data-theme="light"] .auth-input {
    border-color: #ccc;
    background: #fff;
    color: #222;
}

.auth-input:focus {
    outline: none;
    border-color: #4fc3f7;
}

html[data-theme="light"] .auth-input:focus {
    border-color: #1976d2;
}

.auth-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #888;
    cursor: pointer;
}

html[data-theme="light"] .auth-check {
    color: #555;
}

.auth-check input { width: auto; margin: 0; }

/* View Sections */
.view-section {
    display: none;
}

.view-section.active {
    display: block;
}

/* Tool row: label + select + buttons in one row */
.tool-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.tool-row label {
    font-size: 0.72rem;
    color: #aaa;
}

.tool-row select {
    padding: 4px 8px;
    font-size: 0.75rem;
    border: 1px solid #333;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    min-width: 180px;
}

html[data-theme="light"] .tool-row label {
    color: #555;
}

html[data-theme="light"] .tool-row select {
    border-color: #ccc;
    background: #fff;
    color: #222;
}

/* API level: 1–2 placeholder fields between API dropdown and Go */
.api-params-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.api-params-inline .param-inline {
    display: flex;
    align-items: center;
    gap: 4px;
}

.api-params-inline .param-inline label {
    font-size: 0.7rem;
    color: #aaa;
}

html[data-theme="light"] .api-params-inline .param-inline label {
    color: #555;
}

.api-params-inline .param-inline {
    flex-wrap: nowrap;
}

.api-params-inline .param-input-inline {
    padding: 3px 6px;
    font-size: 0.72rem;
    border: 1px solid #333;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    width: 100px;
    min-width: 80px;
}

.api-params-inline select.param-input-inline {
    width: auto;
    min-width: 90px;
    cursor: pointer;
}

html[data-theme="light"] .api-params-inline .param-input-inline {
    border-color: #ccc;
    background: #fff;
    color: #222;
}

.tool-row-actions {
    display: flex;
    gap: 6px;
}

.stop-btn {
    padding: 12px 40px;
    font-size: 1rem;
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stop-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(244, 67, 54, 0.4);
}

.stop-btn:disabled {
    background: #555;
    cursor: not-allowed;
    transform: none;
}

/* Legacy dropdown-section for any standalone use */
.dropdown-section {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
}

.dropdown-section label {
    display: block;
    margin-bottom: 10px;
    font-size: 1.1rem;
    font-weight: 500;
}

.dropdown-section select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 1rem;
    cursor: pointer;
}

.dropdown-section select:focus {
    outline: none;
    border-color: #4fc3f7;
}

/* API Cards Container (Client View) */
.api-cards-container {
    display: grid;
    gap: 10px;
}

.api-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 10px 12px;
    border: 1px solid #333;
    transition: border-color 0.3s;
}

.api-card:hover {
    border-color: #4fc3f7;
}

.api-card h3 {
    color: #4fc3f7;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.api-card .description {
    color: #888;
    font-size: 0.72rem;
    margin-bottom: 8px;
    line-height: 1.2;
}

.api-card .params-form {
    gap: 6px;
    margin-bottom: 8px;
}

.api-card .param-group label {
    font-size: 0.68rem;
}

.api-card .param-group input {
    padding: 4px 6px;
    font-size: 0.72rem;
}

.api-card .card-actions {
    gap: 6px;
    margin-top: 8px;
}

.api-card .go-btn,
.api-card .stop-btn {
    padding: 5px 12px;
    font-size: 0.78rem;
}

/* Parameters Section */
.params-section {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
}

.params-section h3 {
    color: #4fc3f7;
    margin-bottom: 15px;
}

.params-form {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.param-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.param-group label {
    font-size: 0.85rem;
    color: #aaa;
}

.param-group input {
    padding: 10px 12px;
    border: 1px solid #333;
    border-radius: 6px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 0.9rem;
}

.param-group input:focus {
    outline: none;
    border-color: #4fc3f7;
}

.param-group input.default-value {
    border-color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
}

.hidden {
    display: none !important;
}

/* Go / Stop buttons (compact in tool row) */
.go-btn {
    padding: 4px 12px;
    font-size: 0.72rem;
    background: linear-gradient(135deg, #4fc3f7 0%, #29b6f6 100%);
    color: #1a1a2e;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.go-btn:hover { opacity: 0.9; }
.go-btn:disabled { background: #555; cursor: not-allowed; opacity: 1; }

html[data-theme="light"] .go-btn {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    color: #fff;
}

html[data-theme="light"] .tool-row .stop-btn {
    background: #c62828;
    color: #fff;
}

.tool-row .stop-btn {
    padding: 4px 12px;
    font-size: 0.72rem;
    background: #f44336;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Card-level Go/Stop (client view) */
.api-card .card-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.api-card .go-btn,
.api-card .stop-btn {
    min-width: 60px;
}

.api-card .stop-btn {
    padding: 10px 24px;
    font-size: 0.95rem;
}

/* Params row: inline params (API view) */
.params-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.params-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.params-inline .param-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.params-inline .param-group label {
    font-size: 0.68rem;
    color: #888;
}

.params-inline .param-group input {
    padding: 3px 6px;
    font-size: 0.7rem;
    width: 80px;
    max-width: 100px;
}

/* Progress row */
.progress-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.progress-row .progress-bar {
    flex: 1;
    height: 6px;
    background: #1a1a2e;
    border-radius: 3px;
    overflow: hidden;
}

.progress-row .progress-bar .progress-fill {
    border-radius: 3px;
}

.progress-row #apiProgressText {
    font-size: 0.7rem;
    color: #888;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4fc3f7 0%, #29b6f6 50%, #4fc3f7 100%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite linear;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 12px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* R1–R6 legend above table (API level, when R1-6 API selected) */
.api-r16-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin-top: 8px;
    margin-bottom: 6px;
    padding: 8px 10px;
    background: rgba(79, 195, 247, 0.08);
    border-radius: 6px;
    border-left: 3px solid #4fc3f7;
    font-size: 0.78rem;
    color: var(--muted, #aaa);
}
.api-r16-legend.hidden {
    display: none;
}
.api-r16-legend .legend-item {
    white-space: nowrap;
}
.api-r16-legend .legend-item strong {
    color: #4fc3f7;
    margin-right: 2px;
}
html[data-theme="light"] .api-r16-legend {
    background: rgba(25, 118, 210, 0.08);
    border-left-color: #1976d2;
    color: #555;
}
html[data-theme="light"] .api-r16-legend .legend-item strong {
    color: #1976d2;
}

/* Results wrap + data table (single compact table) */
.results-wrap {
    margin-top: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

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

html[data-theme="light"] .data-table th,
html[data-theme="light"] .data-table td {
    border-bottom-color: #ddd;
}

.data-table th {
    background: rgba(79, 195, 247, 0.1);
    color: #4fc3f7;
    font-weight: 600;
}

html[data-theme="light"] .data-table th {
    background: rgba(25, 118, 210, 0.12);
    color: #1976d2;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

html[data-theme="light"] .data-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.04);
}

.data-table tbody tr.error td {
    color: #ff6b6b;
}

html[data-theme="light"] .data-table tbody tr.error td {
    color: #c62828;
}

.data-table tbody tr.success {
    background: rgba(76, 175, 80, 0.06);
}

html[data-theme="light"] .data-table tbody tr.success {
    background: rgba(76, 175, 80, 0.1);
}

.data-table tbody tr.loading td {
    color: #888;
}

html[data-theme="light"] .data-table tbody tr.loading td {
    color: #666;
}

/* Sortable API table headers – click to sort asc/desc */
.sortable-table .sortable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    padding-right: 18px;
}
.sortable-table .sortable-th.api-col-dynamic {
    white-space: normal;
    max-width: 220px;
    line-height: 1.25;
}
.sortable-table .sortable-th:hover {
    background: rgba(79, 195, 247, 0.18);
}
html[data-theme="light"] .sortable-table .sortable-th:hover {
    background: rgba(25, 118, 210, 0.2);
}
.sortable-th .sort-icon {
    display: inline-block;
    margin-left: 2px;
    font-size: 0.7em;
    opacity: 0.6;
}
.sortable-th .sort-icon::after {
    content: '\25b2\25bc'; /* ▲▼ both when unsorted */
    letter-spacing: -0.2em;
}
.sortable-th.sort-asc .sort-icon::after {
    content: '\25b2'; /* ▲ */
    opacity: 1;
}
.sortable-th.sort-desc .sort-icon::after {
    content: '\25bc'; /* ▼ */
    opacity: 1;
}

/* Top X% staffs column: show only for A6 (Time Correction Anomalies) - 15th column */
.sortable-table.hide-top-x-column th.api-col-top-x,
.sortable-table.hide-top-x-column td:nth-child(15) {
    display: none;
}

/* R1-R6 columns: show only for R1-6 (Workforce Insights) API - columns 9-14 */
.sortable-table th.api-col-r,
.sortable-table td:nth-child(9),
.sortable-table td:nth-child(10),
.sortable-table td:nth-child(11),
.sortable-table td:nth-child(12),
.sortable-table td:nth-child(13),
.sortable-table td:nth-child(14) {
    display: none;
}
.sortable-table.api-view-r16 th.api-col-r,
.sortable-table.api-view-r16 td:nth-child(9),
.sortable-table.api-view-r16 td:nth-child(10),
.sortable-table.api-view-r16 td:nth-child(11),
.sortable-table.api-view-r16 td:nth-child(12),
.sortable-table.api-view-r16 td:nth-child(13),
.sortable-table.api-view-r16 td:nth-child(14) {
    display: table-cell;
}
.sortable-table.api-view-r16 th.api-col-number-percent,
.sortable-table.api-view-r16 th.api-col-top-x,
.sortable-table.api-view-r16 td:nth-child(7),
.sortable-table.api-view-r16 td:nth-child(8),
.sortable-table.api-view-r16 td:nth-child(15) {
    display: none;
}

.response-cell {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
}

.recall-btn {
    padding: 2px 6px;
    font-size: 0.72rem;
    background: rgba(79, 195, 247, 0.2);
    color: #4fc3f7;
    border: 1px solid #4fc3f7;
    border-radius: 3px;
    cursor: pointer;
}

.recall-btn:hover {
    background: rgba(79, 195, 247, 0.35);
}

html[data-theme="light"] .recall-btn {
    background: rgba(25, 118, 210, 0.15);
    color: #1976d2;
    border-color: #1976d2;
}

html[data-theme="light"] .recall-btn:hover {
    background: rgba(25, 118, 210, 0.25);
}

.loading-dots {
    color: #888;
    font-size: 0.7rem;
}

.status-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.76rem;
}

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

.results-table th,
.results-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid #333;
    font-size: 0.82rem;
}

.results-table th {
    background: rgba(79, 195, 247, 0.1);
    color: #4fc3f7;
    font-weight: 600;
}

.results-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.results-table tbody tr.error {
    background: rgba(244, 67, 54, 0.1);
}

.results-table tbody tr.error td {
    color: #ff6b6b;
}

.results-table tbody tr.success {
    background: rgba(76, 175, 80, 0.06);
}

.results-table tbody tr.loading td {
    color: #888;
}

.status-badge.success {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
}

.status-badge.error {
    background: rgba(244, 67, 54, 0.2);
    color: #f44336;
}

.status-badge.loading {
    background: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

/* Response Data */
.response-data {
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.8rem;
    background: #0d0d1a;
    padding: 10px;
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Scrollbar */
.response-data::-webkit-scrollbar {
    width: 8px;
}

.response-data::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.response-data::-webkit-scrollbar-thumb {
    background: #4fc3f7;
    border-radius: 4px;
}

/* Client View Results */
/* Client table: Params column – label and value on same line (override global .param-group column layout) */
.client-params-cell {
    padding: 6px 8px;
    min-width: 320px;
    max-width: 420px;
}

.client-params-cell .client-params-inline {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
}

/* Each param group has .param-group .param-inline – force row so label + input stay on one line */
.client-params-cell .param-group.param-inline,
.client-params-cell .param-inline {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.client-params-cell .param-label-inline {
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
}

.client-params-cell .param-input-inline {
    padding: 3px 6px;
    font-size: 0.82rem;
    width: 44px;
    min-width: 40px;
}

.client-params-cell select.param-input-inline {
    width: auto;
    min-width: 68px;
}

html[data-theme="light"] .client-params-cell .param-input-inline {
    border-color: #ccc;
    background: #fff;
    color: #222;
}

.client-results-section {
    margin-top: 10px;
}

.client-results-section .results-table th,
.client-results-section .results-table td {
    padding: 4px 6px;
    font-size: 0.72rem;
}

.client-results-section .results-table .response-data {
    font-size: 0.68rem;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-results-section .recall-wrap {
    margin-top: 6px;
    text-align: right;
}

.client-results-section .recall-btn {
    font-size: 0.68rem;
    padding: 3px 8px;
    min-width: auto;
}

.client-results-section .results-table th:nth-child(1),
.client-results-section .results-table td:nth-child(1) {
    width: 120px;
}

/* Collapsible JSON */
.json-toggle {
    cursor: pointer;
    color: #4fc3f7;
    text-decoration: underline;
    font-size: 0.85rem;
}

.json-content {
    margin-top: 10px;
}

/* Loading spinner for rows */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #333;
    border-top-color: #4fc3f7;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .view-toggle-bar {
        flex-direction: column;
    }
    
    .view-panel {
        min-height: 80px;
        padding: 20px;
    }
    
    .view-panel:first-child {
        border-right: none;
        border-bottom: 1px solid #333;
    }
    
    .view-panel-text {
        font-size: 1.2rem;
    }
    
    .params-form {
        grid-template-columns: 1fr;
    }
    
    .auth-section {
        flex-direction: column;
        align-items: stretch;
    }
    
    .results-table {
        font-size: 0.85rem;
    }
}
