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

:root {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --table-bg: #1e293b;
    --text: #f1f5f9;
    --text-muted: #cbd5e1;
    --text-dim: #94a3b8;
    --text-dimmer: #64748b;
    --border: #334155;
    --hover-bg: #273548;
    --btn-color: #94a3b8;
    --btn-hover-bg: #334155;
    --btn-hover-color: #e2e8f0;
    --copy-color: #64748b;
    --copy-hover-color: #cbd5e1;
    --spinner-border: #475569;
    --spinner-top: #94a3b8;
    --scroll-track: #0f172a;
    --scroll-thumb: #334155;
    --scroll-thumb-hover: #475569;
    --no-data-color: #64748b;
    --error-type: #f472b6;
    --error-time: #64748b;
    --error-path: #94a3b8;
    --error-msg: #e2e8f0;
    --error-stack: #94a3b8;
    --status-color: #64748b;
    --ettn-item-bg: #0f172a;
    --ettn-key: #94a3b8;
    --search-bg: #1e293b;
    --search-border: #334155;
    --search-focus-border: #64748b;
    --search-placeholder: #64748b;
    --chart-bg: #1e293b;
    --version-color: #64748b;
    --header-text: #cbd5e1;
    --section-title: #94a3b8;
    --stat-value: #f8fafc;
    --table-header-bg: rgba(30, 41, 59, 0.8);
    --table-header-text: #94a3b8;
    --grid-line: #1e293b;
    --chart-pending: #60a5fa;
    --chart-failed: #f87171;
    --chart-done: #4ade80;
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --table-bg: #ffffff;
    --text: #334155;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --text-dimmer: #64748b;
    --border: #e2e8f0;
    --hover-bg: #f1f5f9;
    --btn-color: #64748b;
    --btn-hover-bg: #e2e8f0;
    --btn-hover-color: #334155;
    --copy-color: #94a3b8;
    --copy-hover-color: #334155;
    --spinner-border: #cbd5e1;
    --spinner-top: #64748b;
    --scroll-track: #f1f5f9;
    --scroll-thumb: #cbd5e1;
    --scroll-thumb-hover: #94a3b8;
    --no-data-color: #94a3b8;
    --error-type: #be185d;
    --error-time: #94a3b8;
    --error-path: #64748b;
    --error-msg: #334155;
    --error-stack: #94a3b8;
    --status-color: #94a3b8;
    --ettn-item-bg: #f1f5f9;
    --ettn-key: #94a3b8;
    --search-bg: #ffffff;
    --search-border: #cbd5e1;
    --search-focus-border: #64748b;
    --search-placeholder: #94a3b8;
    --chart-bg: #e2e8f0;
    --version-color: #94a3b8;
    --header-text: #64748b;
    --section-title: #94a3b8;
    --stat-value: #0f172a;
    --table-header-bg: rgba(248, 250, 252, 0.8);
    --table-header-text: #64748b;
    --grid-line: #e2e8f0;
    --chart-pending: #3b82f6;
    --chart-failed: #ef4444;
    --chart-done: #22c55e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 17px;
    padding: 24px 24px 60px;
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-muted);
    letter-spacing: -0.28px;
}

h1 span {
    color: var(--text);
    font-weight: 600;
}

.section {
    margin-bottom: 32px;
}

h2 {
    font-size: 1.1rem;
    color: var(--section-title);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: -0.12em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 16px;
}

.stat-card .label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-card .value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--stat-value);
}

.stat-card .value.warn {
    color: #fbbf24;
}

.stat-card .value.danger {
    color: #ef4444;
}

.stat-card.critical {
    border-left: 3px solid var(--text-dim);
}

.stat-card.critical .value.danger {
    border-left-color: #ef4444;
}

.stat-card.critical .value.warn {
    border-left-color: #fbbf24;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th.col-type {
    width: 14%;
}

th.col-msg {
    width: auto;
}

th.col-path {
    width: 25%;
}

th.col-time {
    width: 13%;
}

th.col-actions {
    width: 5%;
}

td.col-type, td.col-path, td.col-time, td.col-actions {
    min-width: 80px;
}

th {
    text-align: left;
    padding: 10px 12px;
    background: var(--table-header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--table-header-text);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: -0.12em;
    font-size: 0.7rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

td {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    vertical-align: top;
}

tr:hover td {
    background: var(--hover-bg);
}

.table-container {
    max-height: 500px;
    overflow-y: auto;
    border-radius: 4px;
}

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

.table-container::-webkit-scrollbar-track {
    background: var(--scroll-track);
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 3px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: var(--scroll-thumb-hover);
}

.table-container.fullscreen {
    max-height: none;
    position: fixed;
    top: 60px;
    left: 24px;
    right: 24px;
    bottom: 60px;
    z-index: 100;
    overflow-y: auto;
    background: var(--bg);
}

.fullscreen-hint {
    display: none;
    text-align: center;
    padding: 8px;
    font-size: 0.7rem;
    color: var(--text-dim);
}

.table-container.fullscreen .fullscreen-hint {
    display: block;
}

.show-more-wrap {
    text-align: center;
    margin-top: 8px;
}

.show-more-wrap.hidden {
    display: none;
}

.show-more-wrap .expand-btn {
    font-size: 0.8rem;
    padding: 6px 16px;
}

.error-type {
    color: var(--error-type);
    font-family: monospace;
    font-size: 0.8rem;
}

.error-count-badge {
    display: inline-block;
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 4px;
    font-weight: 600;
}

.error-time {
    color: var(--error-time);
    font-size: 0.75rem;
    white-space: nowrap;
}

.error-path {
    color: var(--error-path);
    font-family: monospace;
}

.error-msg {
    color: var(--error-msg);
    line-height: 1.4;
    max-width: 60ch;
    word-break: break-word;
}

.error-stack {
    color: var(--error-stack);
    font-family: monospace;
    font-size: 0.75rem;
    max-width: 60ch;
    white-space: pre-wrap;
    word-break: break-word;
}

.status-bar {
    position: fixed;
    bottom: 12px;
    right: 24px;
    left: 24px;
    font-size: 0.7rem;
    color: var(--status-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#refreshTimer {
    width: 160px;
    text-align: right;
    flex-shrink: 0;
}

#versionInfo {
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-controls {
    display: flex;
    gap: 16px;
    align-items: center;
    min-width: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}

.status-dot.ok {
    background: #22c55e;
}

.status-dot.err {
    background: #ef4444;
}

.status-dot-inline {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.expand-btn,
.export-btn {
    color: var(--btn-color);
    cursor: pointer;
    border: none;
    background: none;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.expand-btn:hover,
.export-btn:hover {
    background: var(--btn-hover-bg);
    color: var(--btn-hover-color);
}

.expand-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

.copy-btn {
    color: var(--copy-color);
    font-size: 0.65rem;
}

.copy-btn:hover {
    color: var(--copy-hover-color);
}

.refresh-spinner {
    width: 10px;
    height: 10px;
    border: 2px solid var(--spinner-border);
    border-top-color: var(--spinner-top);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: none;
}

.refresh-spinner.active {
    display: inline-block;
}

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

.status-paused .refresh-spinner {
    display: none !important;
}

.error-stack.collapsed {
    display: none;
}

.no-data {
    color: var(--no-data-color);
    font-style: italic;
    padding: 12px;
}

.hidden {
    display: none !important;
}

.ettn-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.ettn-status-item {
    background: var(--ettn-item-bg);
    border-radius: 6px;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
}

.ettn-status-item .key {
    color: var(--ettn-key);
}

.ettn-status-item .val {
    color: var(--text);
    font-weight: 500;
}

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

.search-input {
    flex: 1;
    max-width: 320px;
    padding: 6px 10px;
    background: var(--search-bg);
    border: 1px solid var(--search-border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8rem;
    outline: none;
}

.search-input:focus {
    border-color: var(--search-focus-border);
}

.search-input::placeholder {
    color: var(--search-placeholder);
}

.toggle-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 4px;
}

.toggle-label input {
    accent-color: #64748b;
}

#historyChart {
    width: 100%;
    height: 180px;
    border-radius: 6px;
    background: var(--chart-bg);
}

.version-footer {
    text-align: center;
    padding: 16px 0 8px;
    font-size: 0.7rem;
    color: var(--version-color);
}

@media (max-width: 600px) {
    body {
        padding: 12px 12px 60px;
    }

    h1 {
        font-size: 1.2rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .status-bar {
        bottom: 8px;
        right: 12px;
        left: 12px;
        justify-content: space-between;
    }

    .status-controls {
        gap: 8px;
    }

    .error-msg,
    .error-stack {
        max-width: 30ch;
    }

    #historyChart {
        height: 140px;
    }

    .table-controls,
    #sortBtn,
    #fullscreenBtn {
        display: none;
    }
}

/* --- Print styles --- */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
        padding: 0 !important;
    }

    h1, h2 {
        color: #000 !important;
    }

    .stat-card,
    .ettn-status-item {
        background: #fff !important;
        border: 1px solid #ccc !important;
    }

    .stat-card .label,
    .ettn-status-item .key {
        color: #333 !important;
    }

    .stat-card .value,
    .ettn-status-item .val {
        color: #000 !important;
    }

    table {
        font-size: 9pt !important;
    }

    th, td {
        border-color: #ccc !important;
        color: #000 !important;
    }

    th {
        background: #f5f5f5 !important;
    }

    tr:hover td {
        background: transparent !important;
    }

    .error-stack.collapsed {
        display: block !important;
    }

    .status-bar,
    .table-controls,
    .show-more-wrap,
    .search-row {
        display: none !important;
    }

    .table-container {
        max-height: none !important;
        overflow: visible !important;
    }

    .section {
        page-break-inside: avoid;
    }

    #historyChart {
        display: none !important;
    }
}

/* --- Search history dropdown --- */
#searchHistoryDropdown {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    position: absolute;
    top: 100%;
    left: 0;
    right: 320px;
    background: var(--card-bg);
    border: 1px solid var(--search-border);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.search-history-item {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 3px;
}

.search-history-item:hover,
.search-history-item:focus {
    background: var(--hover-bg);
}

/* --- Responsive table wrapper for mobile --- */
.table-container {
    overflow-x: auto;
}

/* --- Loading skeleton animation --- */
@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.stat-card.loading .value {
    background: linear-gradient(90deg, var(--card-bg) 25%, var(--hover-bg) 50%, var(--card-bg) 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
}
