:root {
    --control-height: 38px;
    --control-padding-x: 0.75rem;
    --control-font-size: 1rem;
    --control-radius: 0.5rem;
    --app-bg: #f4f6f8;
    --app-bg-soft: #eef2f6;
    --app-surface: #ffffff;
    --app-surface-2: #f7f9fb;
    --app-text: #1f2937;
    --app-muted: #667085;
    --app-border: #d8dee6;
    --app-tab: #edf2f7;
    --app-tab-active: #ffffff;
    --app-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
    --app-danger-soft: rgba(220, 53, 69, 0.12);
    --app-warning-soft: rgba(253, 126, 20, 0.12);
}

.theme-dark {
    --app-bg: #10151c;
    --app-bg-soft: #151c24;
    --app-surface: #1a222d;
    --app-surface-2: #212b37;
    --app-text: #e5e7eb;
    --app-muted: #a0aec0;
    --app-border: #344152;
    --app-tab: #202938;
    --app-tab-active: #1a222d;
    --app-shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
    --app-danger-soft: rgba(248, 113, 113, 0.18);
    --app-warning-soft: rgba(251, 146, 60, 0.2);
}

#app-shell.theme-shell {
    min-height: 100vh;
    background: linear-gradient(180deg, var(--app-bg) 0%, var(--app-bg-soft) 100%);
    color: var(--app-text);
}

.theme-shell .app-page-shell {
    color: var(--app-text);
    padding-top: 0.75rem;
}

.theme-shell .app-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.9rem;
}

.theme-shell .app-brand,
.theme-shell .app-mode-badge,
.theme-shell .theme-toggle-btn {
    background: var(--app-surface) !important;
    color: var(--app-text) !important;
    border: 1px solid var(--app-border);
    box-shadow: var(--app-shadow);
}

.theme-shell .app-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 42px;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-weight: 700;
}

.theme-shell .app-brand-icon {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.theme-shell .app-top-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto;
}

.theme-shell .offline-download-btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    background: var(--app-surface) !important;
    color: var(--app-text) !important;
    border: 1px solid var(--app-border) !important;
    box-shadow: var(--app-shadow);
    font-weight: 600;
    text-decoration: none;
}

.theme-shell .offline-download-btn:hover,
.theme-shell .offline-download-btn:focus,
.theme-shell .offline-download-btn:active {
    background: var(--app-surface-2) !important;
    color: var(--app-text) !important;
    text-decoration: none;
}

.theme-shell .theme-toggle-btn {
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem;
    border-radius: 999px;
}

.theme-shell .theme-toggle-btn .theme-icon {
    display: inline-flex;
}

.theme-shell .theme-toggle-btn .theme-icon-moon,
.theme-dark .theme-toggle-btn .theme-icon-sun {
    display: none;
}

.theme-dark .theme-toggle-btn .theme-icon-moon {
    display: inline-flex;
}

.theme-shell .nav-tabs {
    gap: 0.35rem;
    padding: 0.35rem;
    margin-bottom: 0.85rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 0.75rem;
    box-shadow: var(--app-shadow);
}

.theme-shell .nav-tabs .nav-link {
    color: var(--app-muted);
    background: var(--app-tab);
    border: 1px solid transparent;
    border-radius: 0.55rem;
    font-weight: 600;
}

.theme-shell .nav-tabs .nav-link:hover,
.theme-shell .nav-tabs .nav-link.active {
    color: var(--app-text);
    background: var(--app-tab-active);
    border-color: var(--app-border);
}

.theme-shell .tab-content,
.theme-shell .container-fluid,
.theme-shell .text-muted,
.theme-shell .small,
.theme-shell small {
    color: var(--app-muted) !important;
}

.theme-shell .section-title {
    color: var(--app-text);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.theme-shell .tool-label-with-help {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
}

.theme-shell .tool-label-with-help > span:first-child {
    min-width: 0;
}

.theme-shell .tool-help-icon {
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--app-border);
    border-radius: 50%;
    background: var(--app-surface-2);
    color: var(--app-muted);
    cursor: help;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
}

.theme-shell .tool-help-icon:hover,
.theme-shell .tool-help-icon:focus {
    background: var(--app-surface);
    color: var(--app-text);
}

.tool-help-tooltip .tooltip-inner {
    max-width: 280px;
    text-align: left;
}

.theme-shell .section-subtitle {
    color: var(--app-muted);
    font-size: 0.9rem;
    line-height: 1.35;
}

.theme-shell .tool-section {
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
    padding: 0.9rem;
}

.theme-shell .tool-section + .tool-section {
    margin-top: 0.75rem;
}

.theme-shell .qcmb-batch-upload-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.theme-shell .accordion-title-with-action {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    min-width: 0;
    max-width: 100%;
    vertical-align: middle;
}

.theme-shell .qcmb-batch-upload-row-header {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    margin-bottom: 0;
    margin-left: 0;
}

.theme-shell .qcmb-batch-upload-row-header .qcmb-batch-upload-button {
    width: 1.75rem;
    height: 1.75rem;
    min-height: 1.75rem;
}

.theme-shell .bracos-validation-accordion .accordion-button .tool-help-icon {
    margin-left: 0.35rem;
}

.theme-shell .qcmb-batch-upload {
    display: inline-flex;
}

.theme-shell .qcmb-batch-upload-button {
    width: var(--control-height);
    height: var(--control-height);
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--app-border);
    border-radius: var(--control-radius);
    background: var(--app-surface-2);
    color: var(--app-text);
    cursor: pointer;
    font-weight: 700;
}

.theme-shell .qcmb-batch-upload-button svg {
    display: block;
}

.theme-shell .qcmb-batch-upload-button:hover {
    background: var(--app-surface);
}

.theme-shell .tool-upload {
    min-height: 82px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem;
    border: 1px dashed var(--app-border);
    border-radius: 0.5rem;
    background: var(--app-surface-2);
    color: var(--app-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.theme-shell .tool-upload:hover {
    background: var(--app-surface);
    color: var(--app-text);
}

.theme-shell .tool-upload-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    text-align: center;
}

.theme-shell .upload-filename {
    color: var(--app-muted);
    overflow-wrap: anywhere;
}

.theme-shell .tool-result-table-shell {
    overflow: hidden;
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    background: var(--app-surface-2);
}

.theme-shell .tool-result-table.table {
    margin-bottom: 0;
    --bs-table-bg: transparent;
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
    --bs-table-striped-bg: transparent;
    --bs-table-striped-color: var(--app-text);
    --bs-table-hover-bg: transparent;
    --bs-table-hover-color: var(--app-text);
}

.theme-shell .tool-result-table.table > :not(caption) > * > * {
    padding: 0.45rem 0.55rem;
    border-color: var(--app-border);
    background: transparent;
}

.theme-shell .tool-result-table thead th {
    background: var(--app-surface);
    color: var(--app-text);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.theme-shell .tool-result-table th:not(:first-child),
.theme-shell .tool-result-table td:not(:first-child) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.theme-shell .tool-button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.theme-shell .tool-button-group.btn-group {
    display: flex;
}

.theme-shell .tool-button-group .btn {
    flex: 1 1 auto;
}

.sober-btn,
.sober-danger-btn {
    min-height: var(--control-height);
    padding: 0.375rem var(--control-padding-x);
    font-size: var(--control-font-size);
    font-weight: 600;
    border-radius: var(--control-radius) !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.theme-shell .sober-btn {
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
    border-color: var(--app-border) !important;
}

.theme-shell .sober-btn:hover,
.theme-shell .sober-btn:active,
.theme-shell .sober-btn:focus,
.theme-shell .sober-btn:focus-visible {
    background-color: var(--app-surface-2) !important;
    color: var(--app-text) !important;
}

.theme-shell .sober-danger-btn {
    background-color: var(--app-danger-soft) !important;
    color: var(--app-text) !important;
    border-color: color-mix(in srgb, var(--app-border) 55%, #dc3545) !important;
}

.theme-shell .sober-danger-btn:hover,
.theme-shell .sober-danger-btn:active,
.theme-shell .sober-danger-btn:focus,
.theme-shell .sober-danger-btn:focus-visible {
    background-color: color-mix(in srgb, var(--app-danger-soft) 82%, var(--app-surface)) !important;
    color: var(--app-text) !important;
}

.theme-shell .tool-workspace-row {
    --tool-workspace-height: max(560px, calc(100vh - 9rem));
    align-items: stretch;
}

.theme-shell .verpos-workspace {
    --tool-workspace-height: max(600px, calc(100vh - 8.5rem));
}

.theme-shell .tool-controls-column,
.theme-shell .tool-graph-column {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.theme-shell .tool-controls-column,
.theme-shell .tool-graph-column,
.theme-shell .tool-graph-shell {
    min-height: var(--tool-workspace-height);
}

.theme-shell .tool-graph-column,
.theme-shell .tool-graph-shell {
    height: var(--tool-workspace-height);
}

.theme-shell .tool-graph-shell {
    flex: 1 1 auto;
    overflow: hidden;
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.theme-shell .tool-graph,
.theme-shell .tool-graph .js-plotly-plot {
    width: 100%;
    height: 100%;
}

.theme-shell .tool-graph-actions,
.theme-shell .tide-graph-actions,
.theme-shell .bracos-graph-actions {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.theme-shell .bracos-graph-view-box {
    width: 9rem;
    flex: 0 0 auto;
}

.theme-shell .bracos-graph-view-select {
    min-width: 9rem;
}

.theme-shell .tool-controls-collapsed,
.theme-shell .tide-controls-collapsed,
.theme-shell .bracos-controls-collapsed {
    display: none;
}

.theme-shell .tool-graph-column.tool-graph-expanded,
.theme-shell .tide-graph-column.tide-graph-expanded,
.theme-shell .tool-graph-column.tide-graph-expanded,
.theme-shell .bracos-graph-column.bracos-graph-expanded,
.theme-shell .tool-graph-column.bracos-graph-expanded {
    flex: 0 0 100%;
    max-width: 100%;
}

.theme-shell .tool-graph-column.tool-graph-expanded,
.theme-shell .tool-graph-column.tool-graph-expanded .tool-graph-shell,
.theme-shell .tide-graph-column.tide-graph-expanded,
.theme-shell .tide-graph-column.tide-graph-expanded .tool-graph-shell,
.theme-shell .tool-graph-column.tide-graph-expanded,
.theme-shell .tool-graph-column.tide-graph-expanded .tool-graph-shell,
.theme-shell .bracos-graph-column.bracos-graph-expanded,
.theme-shell .bracos-graph-column.bracos-graph-expanded .tool-graph-shell,
.theme-shell .tool-graph-column.bracos-graph-expanded,
.theme-shell .tool-graph-column.bracos-graph-expanded .tool-graph-shell {
    --tool-workspace-height: max(640px, calc(100vh - 9rem));
}

.theme-shell .tool-stat-tile {
    height: 100%;
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    background: var(--app-surface-2);
    padding: 0.7rem;
}

.theme-shell .tool-stat-label {
    color: var(--app-muted);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
}

.theme-shell .bracos-verification-table td,
.theme-shell .bracos-verification-table th {
    vertical-align: middle;
}

.theme-shell .bracos-row-ok td {
    background: rgba(25, 135, 84, 0.08) !important;
}

.theme-shell .bracos-row-warning td {
    background: rgba(220, 53, 69, 0.09) !important;
}

.theme-shell .bracos-cell-ok {
    background: rgba(25, 135, 84, 0.14) !important;
    color: var(--app-text) !important;
    font-weight: 700;
}

.theme-shell .bracos-cell-warning {
    background: rgba(220, 53, 69, 0.16) !important;
    color: var(--app-text) !important;
    font-weight: 700;
}

.theme-shell .bracos-accordion-warning-icon {
    color: #dc3545;
    flex-shrink: 0;
}

.theme-shell .bracos-accordion-ok-icon {
    color: #198754;
    flex-shrink: 0;
}

.theme-shell .bracos-toggle .form-check-label {
    color: var(--app-text);
}

.theme-shell .bracos-toggle .form-check-input {
    background-color: var(--app-surface-2);
    border-color: var(--app-border);
}

.theme-shell .bracos-toggle .form-check-input:checked {
    background-color: #198754;
    border-color: #198754;
}

.theme-shell .bracos-toggle .form-check-input:focus {
    border-color: #198754;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.18);
}

.theme-shell .tool-stat-value {
    color: var(--app-text);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.theme-shell .asvp-coefficient-input,
.theme-shell .tool-number-input {
    min-height: var(--control-height);
    font-variant-numeric: tabular-nums;
}

.theme-shell .asvp-coefficient-input[type="number"],
.theme-shell .tool-number-input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.theme-shell .asvp-coefficient-input[type="number"]::-webkit-outer-spin-button,
.theme-shell .asvp-coefficient-input[type="number"]::-webkit-inner-spin-button,
.theme-shell .tool-number-input[type="number"]::-webkit-outer-spin-button,
.theme-shell .tool-number-input[type="number"]::-webkit-inner-spin-button {
    margin: 0;
    appearance: none;
}

.theme-shell .asvp-coefficient-line + .asvp-coefficient-line {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--app-border);
}

.theme-shell .asvp-coefficient-line-title,
.theme-shell .tool-field-label {
    color: var(--app-text);
    font-weight: 700;
    line-height: 1.2;
}

.theme-shell .asvp-coefficient-line-help,
.theme-shell .asvp-note {
    color: var(--app-muted);
    font-size: 0.85rem;
    line-height: 1.3;
}

.theme-shell .asvp-preset-select,
.theme-shell .tide-select,
.theme-shell .tool-controls-column .form-control,
.theme-shell .tool-controls-column .form-select {
    background-color: var(--app-surface-2) !important;
    color: var(--app-text) !important;
    border-color: var(--app-border) !important;
}

.theme-shell .tool-controls-column .form-control::placeholder {
    color: var(--app-muted) !important;
}

.theme-shell .tide-filter-checklist {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem 0.75rem;
    color: var(--app-text);
}

.theme-shell .tide-filter-checklist .form-check {
    min-width: 0;
}

.theme-shell .tool-controls-column .form-control:focus,
.theme-shell .tool-controls-column .form-select:focus,
.theme-shell .asvp-preset-select:focus,
.theme-shell .tide-select:focus {
    box-shadow: 0 0 0 0.15rem color-mix(in srgb, var(--app-border) 50%, transparent) !important;
}

.theme-shell .qcmb-results-grid > .row > .d-flex > .qcmb-result-card {
    width: 100%;
}

.theme-shell .qcmb-result-card .tool-result-table-shell {
    flex: 1 1 auto;
}

.theme-shell .qcmb-result-card .table-responsive,
.theme-shell .qcmb-result-card .table {
    height: 100%;
}

.theme-shell .tool-controls-column {
    min-width: 0;
    overflow: visible;
}

.theme-shell .tool-section,
.theme-shell .accordion-body {
    min-width: 0;
    overflow: visible;
}

.theme-shell .tool-result-table-shell .table-responsive {
    overflow-x: visible;
}

.theme-shell .tool-result-table {
    width: 100%;
    table-layout: fixed;
}

.theme-shell .tool-result-table th,
.theme-shell .tool-result-table td {
    overflow-wrap: anywhere;
}

.theme-shell .accordion-item,
.theme-shell .accordion-button,
.theme-shell .accordion-button:not(.collapsed) {
    background: var(--app-surface);
    color: var(--app-text);
    border-color: var(--app-border);
}

.theme-shell .accordion-button:not(.collapsed) {
    background: var(--app-surface-2);
    box-shadow: inset 0 -1px 0 var(--app-border);
}

.theme-dark .accordion-button::after {
    filter: invert(92%) sepia(9%) saturate(527%) hue-rotate(176deg) brightness(95%) contrast(92%);
    opacity: 0.9;
}

.theme-dark .accordion-button:hover::after,
.theme-dark .accordion-button:not(.collapsed)::after {
    filter: invert(100%) sepia(6%) saturate(159%) hue-rotate(177deg) brightness(99%) contrast(91%);
    opacity: 1;
}

.theme-shell .qcmb-upload-accordion .accordion-body {
    padding: 0.75rem;
}


@media (max-width: 767.98px) {
    .theme-shell .tool-workspace-row {
        --tool-workspace-height: auto;
    }

    .theme-shell .app-page-header {
        align-items: stretch;
    }

    .theme-shell .app-brand,
    .theme-shell .app-top-controls {
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .theme-shell .tool-graph-column,
    .theme-shell .tool-graph-shell {
        height: auto;
        min-height: 420px;
    }

    .theme-shell .tool-graph {
        min-height: 420px;
    }

    .theme-shell .tool-button-group .btn {
        flex-basis: 100%;
    }
}
