/* ============================================
   Blood Gas Data Viewer - Dark Theme
   Matches DAT Workspace design language
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-input: #2a2e3f;
    --border: #2e3348;
    --text-primary: #f5f6fa;
    --text-secondary: #cdd1e0;
    --text-muted: #a0a4b8;
    --accent: #6c8cff;
    --accent-hover: #8ba4ff;
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);

    --header-height: 52px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ---------- Header ---------- */
.header {
    background: rgba(15, 17, 23, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(108, 140, 255, 0.1);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 100;
}

.header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.header__back:hover {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-primary);
}

.header__back svg {
    width: 20px;
    height: 20px;
}

.header__title {
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent) 0%, hsla(270, 50%, 65%, 1) 50%, hsla(40, 80%, 60%, 1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.header__group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header__label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.header__input,
.header__select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.header__select {
    min-width: 130px;
    cursor: pointer;
}

.header__input:focus,
.header__select:focus {
    outline: none;
    border-color: var(--accent);
}

.header__nav {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

/* ---------- Buttons ---------- */
.btn {
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.2s, opacity 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn--primary {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-secondary);
    border: 1px solid rgba(108, 140, 255, 0.2);
}

.btn--primary:hover:not(:disabled) {
    background: rgba(108, 140, 255, 0.25);
    color: var(--text-primary);
}

.btn--success {
    background: rgba(74, 222, 128, 0.2);
    color: var(--green);
    border: 1px solid rgba(74, 222, 128, 0.25);
}

.btn--success:hover:not(:disabled) {
    background: rgba(74, 222, 128, 0.3);
}

.btn__icon {
    font-size: 1rem;
}

/* ---------- Main Layout ---------- */
.main {
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* ---------- Panel Base ---------- */
.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel__header {
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.panel__title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.panel__placeholder {
    flex: 1;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 10px;
    text-align: center;
    padding: 20px;
}

.panel__placeholder.is-visible {
    display: flex;
}

.panel__placeholder small {
    opacity: 0.7;
}

.panel__icon {
    width: 48px;
    height: 48px;
    opacity: 0.3;
}

.panel__loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 40px;
    color: var(--text-muted);
}

.panel__loading.is-visible {
    display: flex;
}

.panel__iframe {
    display: none;
    flex: 1;
    border: none;
    background: #111318;
}

.panel__iframe.is-visible {
    display: block;
}

/* ---------- PDF Panel ---------- */
.panel--pdf {
    flex: 1;
    min-width: 45%;
    background: #111318;
}

/* ---------- Data Panel ---------- */
.panel--data {
    flex: 1;
    min-width: 55%;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
}

/* ---------- Status Messages ---------- */
.status {
    padding: 8px 16px;
    font-size: 0.85rem;
    display: none;
    border-bottom: 1px solid transparent;
}

.status.is-visible {
    display: block;
}

.status--success {
    background: rgba(74, 222, 128, 0.1);
    color: var(--green);
    border-color: rgba(74, 222, 128, 0.2);
}

.status--error {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border-color: rgba(248, 113, 113, 0.2);
}

/* ---------- Table Container ---------- */
.table-container {
    flex: 1;
    overflow: auto;
}

/* ---------- Table ---------- */
.table {
    border-collapse: collapse;
    font-size: 0.85rem;
    display: none;
    table-layout: fixed;
}

.table.is-visible {
    display: table;
}

.table th,
.table td {
    padding: 7px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
}

.table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Field name column (first column) — sticky */
.table th:first-child,
.table td:first-child {
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-secondary);
    position: sticky;
    left: 0;
    z-index: 5;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.table th:first-child {
    z-index: 15;
}

.table tbody tr:hover td {
    background: rgba(108, 140, 255, 0.04);
}

.table tbody tr:hover td:first-child {
    background: var(--bg-card);
}

/* ---------- Table Input ---------- */
.table__input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: inherit;
    background: transparent;
    color: var(--text-primary);
    transition: border-color 0.15s, background 0.15s;
}

.table__input:hover {
    border-color: var(--border);
    background: var(--bg-input);
}

.table__input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-input);
    box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.15);
}

.table__input--modified {
    background: rgba(250, 204, 21, 0.1) !important;
    border-color: rgba(250, 204, 21, 0.4) !important;
    color: var(--yellow) !important;
}

/* ---------- Spinner ---------- */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .header {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 15px;
        gap: 8px;
    }

    .main {
        flex-direction: column;
        height: calc(100vh - 90px);
    }

    .panel--pdf,
    .panel--data {
        min-width: 100%;
        height: 50%;
    }
}

@media (max-width: 600px) {
    .header__title {
        width: 100%;
    }

    .header__nav {
        margin-left: auto;
    }
}
