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

:root {
    --primary: #5b6abf;
    --primary-hover: #4a58a8;
    --primary-light: #eef0fb;
    --bg: #fafbfc;
    --card: #ffffff;
    --border: #e8eaed;
    --border-light: #f2f3f5;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-muted: #aeaeb2;
    --success: #34c759;
    --danger: #ff3b30;
    --danger-bg: #fff5f5;
    --warning: #ff9500;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.03);
    --shadow: 0 2px 8px rgba(0,0,0,0.06), 0 0 1px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.1), 0 0 1px rgba(0,0,0,0.08);
    --transition: 0.15s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card);
    border-radius: 14px;
    padding: 28px;
    min-width: 420px;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-wide {
    min-width: 900px;
    max-width: 1200px;
    width: 90vw;
}

.modal-wide table {
    display: block;
    overflow-x: auto;
}

.modal-wide thead,
.modal-wide tbody,
.modal-wide tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.modal-wide table {
    display: table;
    table-layout: auto;
    min-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 17px;
    font-weight: 600;
}

.modal-header button {
    background: var(--border-light);
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.modal-header button:hover {
    background: var(--border);
    color: var(--text);
}

/* ===== Login ===== */
.login-box {
    text-align: center;
    max-width: 360px;
}

.login-box h2 {
    margin-bottom: 6px;
    color: var(--primary);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.login-box p {
    margin-bottom: 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.login-box input {
    display: block;
    width: 100%;
    padding: 11px 14px;
    margin-bottom: 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: border-color var(--transition);
    outline: none;
}

.login-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91,106,191,0.12);
}

.login-box button {
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}

.login-box button:hover {
    background: var(--primary-hover);
}

.error {
    color: var(--danger);
    margin-top: 10px;
    font-size: 13px;
}

/* ===== Header ===== */
header {
    background: var(--card);
    padding: 0 28px;
    height: 56px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 36px;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    letter-spacing: -0.3px;
}

nav {
    display: flex;
    gap: 2px;
    height: 100%;
    align-items: center;
}

.tab {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
    position: relative;
}

.tab:hover {
    background: var(--border-light);
    color: var(--text);
}

.tab.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* ===== Tab Content ===== */
.tab-content {
    display: none;
    padding: 24px 28px;
    max-width: 1400px;
    margin: 0 auto;
}

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

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sep {
    color: var(--border);
    margin: 0 4px;
}

.hint {
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== Filters ===== */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}

/* ===== Buttons ===== */
button {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
    outline: none;
}

button:hover {
    background: var(--border-light);
    border-color: #d0d3d8;
    color: var(--text);
}

button:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #e0332b;
    border-color: #e0332b;
    color: #fff;
}

.btn-large {
    padding: 10px 28px;
    font-size: 14px;
    border-radius: var(--radius);
}

/* ===== Select & Input ===== */
select, input[type="text"], input[type="number"], input[type="password"], textarea {
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
    background: var(--card);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91,106,191,0.1);
}

select {
    min-width: 130px;
    cursor: pointer;
}

textarea {
    width: 100%;
    resize: vertical;
    line-height: 1.5;
}

/* ===== Table ===== */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

th, td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

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

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: #f7f8fc;
}

td {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

td button {
    padding: 4px 10px;
    font-size: 12px;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 13px;
}

/* ===== Forms ===== */
.form-row {
    margin-bottom: 14px;
}

.form-row label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 13px;
}

.form-row input, .form-row select, .form-row textarea {
    width: 100%;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    justify-content: flex-end;
}

.radio-group {
    display: flex;
    gap: 20px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    cursor: pointer;
    color: var(--text);
}

/* ===== Script Cards ===== */
.script-cards {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.script-card {
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 22px;
    min-width: 200px;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.script-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 12px rgba(91,106,191,0.12);
    transform: translateY(-1px);
}

.script-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.script-card h4 {
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 600;
}

.script-card p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Script Editor ===== */
.script-editor {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.script-editor h3 {
    margin-bottom: 18px;
    font-size: 16px;
}

.script-editor h4 {
    margin: 18px 0 10px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.param-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.param-row input {
    flex: 1;
}

.param-row button {
    padding: 4px 8px;
    color: var(--danger);
    border: none;
    background: none;
}

.param-row button:hover {
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
}

/* ===== Runner ===== */
.runner-config {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.runner-form {
    display: flex;
    gap: 28px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.runner-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.runner-field > label:first-child {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.runner-filters {
    display: flex;
    gap: 8px;
}

.runner-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-top: 4px;
    border-top: 1px solid var(--border-light);
}

.run-case-count {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-secondary);
}

.progress-bar {
    height: 8px;
    background: var(--border-light);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}

.log-area {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: var(--bg);
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
}

.log-header div {
    display: flex;
    gap: 8px;
}

.log-container {
    height: 420px;
    overflow-y: auto;
    padding: 14px 18px;
    font-family: "SF Mono", "Menlo", "Monaco", "Cascadia Code", monospace;
    font-size: 12.5px;
    line-height: 1.7;
    background: #1a1b26;
    color: #c0caf5;
}

.log-container::-webkit-scrollbar {
    width: 6px;
}

.log-container::-webkit-scrollbar-track {
    background: transparent;
}

.log-container::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

.log-line {
    white-space: pre-wrap;
    word-break: break-all;
}

.log-line.info { color: #c0caf5; }
.log-line.warn { color: #e0af68; }
.log-line.error { color: #f7768e; }
.log-line.success { color: #9ece6a; }

/* ===== Detail ===== */
.detail-summary {
    display: flex;
    gap: 28px;
    margin-bottom: 20px;
    padding: 14px 18px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.detail-summary span {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Expandable cells in detail table */
.cell-expandable {
    max-width: 280px;
    padding: 0 !important;
}

.cell-expandable .cell-content {
    padding: 11px 14px;
    max-height: 3em;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    cursor: pointer;
    transition: max-height 0.25s ease;
    word-break: break-word;
    white-space: normal;
    position: relative;
}

.cell-expandable .cell-content:hover {
    background: var(--primary-light);
}

.cell-expandable .cell-content.expanded {
    max-height: 400px;
    -webkit-line-clamp: unset;
    overflow-y: auto;
    background: #f8f9ff;
}

.cell-error .cell-content {
    color: var(--danger);
}

/* ===== Pass/Fail badges ===== */
.badge-pass {
    color: var(--success);
    font-weight: 600;
}

.badge-fail {
    color: var(--danger);
    font-weight: 600;
}

/* ===== Checkbox ===== */
input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

input[type="radio"] {
    accent-color: var(--primary);
    cursor: pointer;
}

/* ===== Range ===== */
input[type="range"] {
    accent-color: var(--primary);
}

.slider-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-val {
    font-weight: 700;
    min-width: 24px;
    font-size: 15px;
    color: var(--primary);
}

.field-hint {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
    display: block;
}

/* ===== Scrollbar (global) ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.2);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        height: auto;
        padding: 14px 20px;
        gap: 12px;
    }
    .modal-content, .modal-wide {
        min-width: auto;
        max-width: 95vw;
        margin: 0 10px;
    }
    .toolbar {
        flex-direction: column;
        align-items: flex-start;
    }
    .tab-content {
        padding: 16px;
    }
    .detail-summary {
        flex-direction: column;
        gap: 8px;
    }
}


/* ===== Realtime Test Styles ===== */
.realtime-container {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: calc(100vh - 120px);
    min-height: 500px;
}

.realtime-container .realtime-config {
    flex-shrink: 0;
}

.realtime-container .realtime-chat {
    flex: 1;
    min-height: 200px;
}

.realtime-container .realtime-log-area {
    flex-shrink: 0;
}

.realtime-config {
    display: flex;
    gap: 20px;
    align-items: flex-end;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.realtime-config .form-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
}

.realtime-config label {
    font-weight: 500;
    color: #555;
    font-size: 14px;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-disconnected {
    background: #fee;
    color: #c33;
}

.status-connected {
    background: #efe;
    color: #3c3;
}

.realtime-chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    display: flex;
    max-width: 80%;
}

.chat-message.user {
    align-self: flex-end;
}

.chat-message.bot {
    align-self: flex-start;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-message.user .message-bubble {
    background: #1890ff;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.bot .message-bubble {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    border-top: 1px solid #e0e0e0;
    background: #fff;
}

.input-mode-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
}

.mode-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.2s;
}

.mode-tab:hover {
    background: #f5f5f5;
}

.mode-tab.active {
    color: #1890ff;
    border-bottom: 2px solid #1890ff;
    font-weight: 500;
}

.chat-input-box {
    display: flex;
    padding: 12px;
    gap: 10px;
}

.chat-input-box textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    min-height: 44px;
    max-height: 120px;
}

.chat-input-box textarea:focus {
    outline: none;
    border-color: #1890ff;
}

.chat-input-box button {
    padding: 10px 20px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-secondary.recording {
    background: #ff4d4f;
    color: white;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.realtime-log-area {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    height: 300px;
    display: flex;
    flex-direction: column;
}

.realtime-log-area .log-header {
    flex-shrink: 0;
}

.realtime-log-area .log-container {
    flex: 1;
    height: auto;
    min-height: 0;
}

.log-send { color: #1890ff; }
.log-recv { color: #52c41a; }
.log-error { color: #ff4d4f; }
.log-success { color: #52c41a; }
.log-info { color: #666; }

/* Tab button adjustment for new tab */
nav {
    display: flex;
    gap: 4px;
    overflow-x: auto;
}

nav button.tab {
    white-space: nowrap;
    padding: 10px 16px;
}


/* ===== Message Metrics (TTFT) ===== */
.message-metrics {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    padding: 0 4px;
    font-family: 'SF Mono', Monaco, monospace;
}

.chat-message.user .message-metrics {
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}

.chat-message.bot .message-metrics {
    text-align: left;
}
