@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=Inter:wght@300;400;500;600&display=swap');

/* CSS Variables */
:root {
    --bg: #f4f6f9;
    --bg-card: #ffffff;
    --bg-hover: #f0f4ff;
    --bg-input: #ffffff;
    --border: #dde2ec;
    --border-focus: #4f74e3;
    --accent: #4f74e3;
    --accent-dark: #3a5bc7;
    --accent-light: #eef1fd;
    --text: #1a2035;
    --text-muted: #6b7592;
    --text-label: #4a5270;
    --danger: #d94f4f;
    --danger-bg: #fff0f0;
    --success: #2a9d5c;
    --radius: 10px;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.07);
    --shadow: 0 4px 16px rgba(0,0,0,0.09);
    --font-body: 'Inter', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    min-height: 100vh;
    background: #1e2a4a;
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 22px;
    color: #7fa4f5;
}

.logo-text {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #e8edf8;
}

.nav-links {
    list-style: none;
}

    .nav-links li a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 20px;
        color: #9aaacf;
        text-decoration: none;
        font-size: 13px;
        font-weight: 500;
        transition: all 0.15s;
    }

        .nav-links li a:hover {
            color: #fff;
            background: rgba(255,255,255,0.07);
        }

        .nav-links li a.active {
            color: #fff;
            background: rgba(255,255,255,0.1);
            border-left: 3px solid #7fa4f5;
        }

.nav-icon {
    font-size: 14px;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 32px 40px;
    max-width: 1400px;
    overflow-x: hidden;
}

/* Page Header */
.page-header {
    margin-bottom: 28px;
}

.page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--text-muted);
    margin-top: 4px;
    font-size: 13px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.step-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

    .step-header h2 {
        font-size: 15px;
        font-weight: 600;
        color: var(--text);
    }

.step-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-light);
    border: 1px solid #c7d4f8;
    border-radius: 4px;
    padding: 2px 8px;
}

/* Forms */
.form-group {
    margin-bottom: 14px;
}

    .form-group label {
        display: block;
        font-size: 11px;
        font-weight: 600;
        color: var(--text-label);
        margin-bottom: 5px;
        text-transform: uppercase;
        letter-spacing: 0.07em;
    }

.form-input, .select-input {
    width: 100%;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: 7px;
    padding: 9px 12px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
}

    .form-input:focus, .select-input:focus {
        outline: none;
        border-color: var(--border-focus);
        box-shadow: 0 0 0 3px rgba(79,116,227,0.12);
    }

    .form-input::placeholder {
        color: #b0b8d0;
    }

.code-input {
    font-family: var(--font-mono);
    font-size: 13px;
    background: #f8f9fc;
}

.select-input-sm {
    width: auto;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: 7px;
    color: var(--text);
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.report-description {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 10px;
}

/* Filters Grid */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px 24px;
    align-items: start;
}

.filter-field {
    position: relative;
}

    .filter-field.filter-date-range {
        grid-column: span 2;
    }

.filter-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-label);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.required {
    color: var(--danger);
    margin-left: 3px;
}

.range-inputs {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
}

    .range-inputs .form-input {
        min-width: 0;
    }

.range-sep {
    color: var(--text-muted);
    font-size: 16px;
    text-align: center;
}

.clear-btn {
    position: absolute;
    right: 10px;
    top: 32px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 5px;
    border-radius: 4px;
    line-height: 1;
}

    .clear-btn:hover {
        color: var(--danger);
        background: var(--danger-bg);
    }

/* Actions Row */
.action-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.page-size-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: 7px;
    padding: 9px 18px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

    .btn:disabled {
        opacity: 0.45;
        cursor: not-allowed;
    }

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 6px rgba(79,116,227,0.3);
}

    .btn-primary:hover:not(:disabled) {
        background: var(--accent-dark);
        box-shadow: 0 2px 10px rgba(79,116,227,0.4);
    }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1.5px solid var(--border);
}

    .btn-secondary:hover:not(:disabled) {
        border-color: var(--accent);
        color: var(--accent);
        background: var(--accent-light);
    }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
}

    .btn-ghost:hover:not(:disabled) {
        color: var(--text);
        border-color: #b0b8d0;
    }

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 7px;
    border-radius: 5px;
    color: var(--text-muted);
    font-size: 13px;
}

    .icon-btn.danger:hover {
        color: var(--danger);
        background: var(--danger-bg);
    }

/* Results */
.results-card {
    padding: 0;
    overflow: hidden;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: #fafbfd;
}

    .results-header h2 {
        font-size: 14px;
        font-weight: 600;
    }

.results-meta {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Table */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.edit-panel .table-wrapper {
    overflow-x: auto;
}

.data-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    border-bottom: 1.5px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: #fafbfd;
}

.sortable-th {
    cursor: pointer;
    user-select: none;
}

    .sortable-th:hover {
        color: var(--accent);
    }

.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid #eef0f5;
    color: var(--text);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

.data-table.compact th, .data-table.compact td {
    padding: 7px 12px;
}

.data-table code {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px;
    border-top: 1px solid var(--border);
    background: #fafbfd;
}

    .pagination .btn.active {
        background: var(--accent);
        color: #fff;
        border-color: var(--accent);
    }

/* Admin Layout */
.admin-layout {
    display: grid;
    grid-template-columns: minmax(320px, 38%) 1fr;
    gap: 16px;
    align-items: start;
}

.admin-full {
    display: block;
}

.card-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

    .card-toolbar h2 {
        font-size: 14px;
        font-weight: 600;
    }

.report-list {
    list-style: none;
}

.report-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.1s;
    margin-bottom: 2px;
}

    .report-list-item:hover {
        background: var(--bg-hover);
    }

    .report-list-item.active {
        background: var(--accent-light);
        border: 1px solid #c7d4f8;
    }

.report-list-name {
    font-size: 13px;
    font-weight: 500;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.filter-add-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    margin-bottom: 12px;
    cursor: pointer;
}

/* Toast / Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error {
    background: var(--danger-bg);
    border: 1px solid #f5c0c0;
    color: var(--danger);
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    z-index: 999;
    box-shadow: var(--shadow);
    animation: fadeIn 0.2s ease;
}

.toast-ok {
    background: var(--success);
    color: #fff;
}

.toast-error {
    background: var(--danger);
    color: #fff;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Spinners */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 10px;
}

.spinner-sm {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-state {
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
}

/* Misc */
.muted {
    color: var(--text-muted);
    font-size: 13px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.not-found {
    text-align: center;
    padding: 80px;
    color: var(--text-muted);
}

.alert-info {
    background: #eff4ff;
    border: 1px solid #c7d4f8;
    color: #3a5bc7;
}

/* Admin extras */
.edit-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 18px;
}

.report-list-type {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.section-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.hint-inline {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.text-muted {
    color: var(--text-muted);
}

.form-input-sm {
    width: 100%;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
}

    .form-input-sm:focus {
        outline: none;
        border-color: var(--border-focus);
    }

    .form-input-sm:disabled {
        background: #f4f6f9;
        color: var(--text-muted);
    }

.row-excluded td {
    opacity: 0.4;
}

/* Badges */
.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
}

.badge-ok {
    background: #e6f7ee;
    color: var(--success);
}

.badge-warn {
    background: #fff3e0;
    color: #e07b00;
}

/* Danger button */
.btn-danger {
    background: var(--danger);
    color: #fff;
}

    .btn-danger:hover:not(:disabled) {
        background: #b83a3a;
    }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px 32px;
    max-width: 440px;
    width: 100%;
    box-shadow: var(--shadow);
}

    .modal h3 {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 10px;
    }

    .modal p {
        font-size: 14px;
        color: var(--text-muted);
        margin-bottom: 20px;
    }

/* Function param name badge */
.param-name {
    font-family: var(--font-mono);
    font-size: 12px;
    color: #2a6db5;
    background: #e8f0fd;
    border: 1px solid #c7d4f8;
    border-radius: 4px;
    padding: 1px 6px;
}

/* Admin table overflow fixes */



.data-table.compact th,
.data-table.compact td {
    padding: 6px 8px;
    white-space: nowrap;
}

    .data-table.compact th:first-child,
    .data-table.compact td:first-child {
        width: 36px;
        text-align: center;
    }

.data-table.compact .form-input-sm {
    min-width: 90px;
    max-width: 160px;
}

.data-table.compact td:has(.form-input-sm[placeholder*="p_"]) .form-input-sm {
    max-width: 120px;
}

.data-table.compact input[type="number"].form-input-sm {
    min-width: 52px;
    max-width: 64px;
}

.data-table.compact td:last-child,
.data-table.compact th:last-child {
    text-align: center;
}

.edit-panel {
    min-width: 0;
    overflow: hidden;
}

    .edit-panel .card {
        min-width: 0;
        overflow: hidden;
    }

/* Function parameter add form */
.param-add-form {
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fc;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
}

.param-add-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 16px;
}

.param-add-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}

/* Filter input loading state */
.select-loading {
    padding: 9px 12px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 13px;
}

/* PDF Preview Page */
.pdf-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
    align-items: start;
}

.pdf-config-card {
    position: sticky;
    top: 20px;
}

.pdf-preview-card {
    padding: 0;
    overflow: hidden;
    min-height: 600px;
}

.pdf-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

    .pdf-preview-header h2 {
        font-size: 14px;
        font-weight: 600;
    }

.pdf-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.pdf-placeholder-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.pdf-iframe {
    width: 100%;
    border: none;
}

    .pdf-iframe.portrait {
        height: 800px;
    }

    .pdf-iframe.landscape {
        height: 560px;
    }

/* Orientation picker */
.orientation-picker {
    display: flex;
    gap: 12px;
}

.orientation-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    transition: all 0.15s;
    flex: 1;
    text-align: center;
}

    .orientation-option input {
        display: none;
    }

    .orientation-option.selected {
        border-color: var(--accent);
        background: var(--accent-light);
        color: var(--accent);
    }

    .orientation-option:hover {
        border-color: var(--accent);
    }

.page-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1.5px solid currentColor;
    font-size: 14px;
    font-weight: 700;
    color: inherit;
}

.portrait-icon {
    width: 28px;
    height: 38px;
}

.landscape-icon {
    width: 38px;
    height: 28px;
}

/* PDF summary box */
.pdf-summary {
    margin-top: 20px;
    padding: 14px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 4px 0;
    color: var(--text-muted);
}

    .summary-row strong {
        color: var(--text);
    }

/* Error code badge in alerts */
.alert-code {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: rgba(217, 79, 79, 0.12);
    color: var(--danger);
    border-radius: 4px;
    padding: 1px 6px;
    margin-bottom: 4px;
}

/* Tab Bar */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 10px 18px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    border-radius: 6px 6px 0 0;
}

    .tab-btn:hover {
        color: var(--text);
        background: var(--bg-hover);
    }

    .tab-btn.active {
        color: var(--accent);
        border-bottom-color: var(--accent);
        background: var(--accent-light);
    }

.tab-badge {
    background: var(--border);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 20px;
    font-family: var(--font-mono);
}

.tab-btn.active .tab-badge {
    background: rgba(79,116,227,0.15);
    color: var(--accent);
}

/* Admin report/filtertypes table */
.admin-report-table {
    width: 100%;
    table-layout: auto;
}

    .admin-report-table td {
        vertical-align: middle;
        white-space: nowrap;
    }

    .admin-report-table th {
        white-space: nowrap;
    }

    .admin-report-table .report-table-name {
        white-space: normal;
        min-width: 140px;
    }

    .admin-report-table tr.row-selected td {
        background: var(--accent-light);
    }

/* Make table cards in admin use full card width */
.admin-full .card {
    width: 100%;
}

.admin-full .table-wrapper {
    overflow-x: auto;
    width: 100%;
}

.admin-layout .table-wrapper {
    overflow-x: auto;
    width: 100%;
}

.report-table-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--text);
}

.report-table-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.text-center {
    text-align: center;
}

/* Query / data-source type badge */
.query-type-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
}

    .query-type-badge.raw_sql {
        background: #e8f5e9;
        color: #2e7d32;
    }

    .query-type-badge.function {
        background: #e8eaf6;
        color: #3949ab;
    }

    .query-type-badge.procedure {
        background: #fce4ec;
        color: #c62828;
    }

    .query-type-badge.sql {
        background: #e8eaf6;
        color: #3949ab;
    }

    .query-type-badge.json {
        background: #fff8e1;
        color: #f57f17;
    }
