/* زبان طراحی مستقل R2 برای محیط‌های تحلیل و محاسبات حرفه‌ای. */
:root {
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-dark: #6d28d9;
    --primary-soft: #f5f3ff;
    --accent: #db2777;
    --accent-soft: #fdf2f8;
    --info: #0284c7;
    --info-soft: #f0f9ff;
    --sidebar: #111827;
    --sidebar-raised: #182235;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --background: #f7f7fb;
    --surface: #ffffff;
    --surface-subtle: #fafafe;
    --text: #161a25;
    --muted: #667085;
    --muted-strong: #475467;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-sm: 0 2px 8px rgba(16, 24, 40, 0.06);
    --shadow: 0 12px 32px rgba(32, 22, 54, 0.07);
    --shadow-lg: 0 24px 64px rgba(32, 22, 54, 0.13);
    --radius-sm: 0.5rem;
    --radius: 0.75rem;
    --radius-lg: 1rem;
    --sidebar-width: 17rem;
}

[data-theme="dark"] {
    color-scheme: dark;
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-dark: #c4b5fd;
    --primary-soft: #2b2143;
    --accent: #f472b6;
    --accent-soft: #3c1930;
    --info: #38bdf8;
    --info-soft: #102b3b;
    --success: #34d399;
    --success-soft: #102d27;
    --warning: #fbbf24;
    --warning-soft: #362a10;
    --danger: #f87171;
    --danger-soft: #3b1d25;
    --background: #0b1020;
    --surface: #141b2d;
    --surface-subtle: #192237;
    --text: #eef2ff;
    --muted: #a8b2c5;
    --muted-strong: #ced5e2;
    --border: #2a3449;
    --border-strong: #3b4861;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.22);
    --shadow: 0 16px 38px rgba(0, 0, 0, 0.24);
    --shadow-lg: 0 28px 72px rgba(0, 0, 0, 0.4);
}

html {
    background: var(--background);
    scroll-behavior: smooth;
}

body {
    color: var(--text);
    background: var(--background);
    font-size: 0.9375rem;
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
}

::selection {
    color: var(--text);
    background: #e9d5ff;
}

a {
    color: var(--primary-hover);
    text-underline-offset: 0.2em;
}

a,
button,
input,
select,
textarea {
    transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

:focus-visible {
    outline: 3px solid rgba(124, 58, 237, 0.22);
    outline-offset: 2px;
}

.skip-link {
    z-index: 1000;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    color: var(--primary-hover);
    box-shadow: var(--shadow-sm);
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.app-sidebar {
    position: sticky;
    inset-block-start: 0;
    z-index: 40;
    display: flex;
    min-width: 0;
    height: 100vh;
    flex-direction: column;
    overflow-y: auto;
    color: #e5e7eb;
    background:
        radial-gradient(circle at 15% 8%, rgba(124, 58, 237, 0.18), transparent 25%),
        linear-gradient(180deg, #111827 0%, #0e1523 100%);
    scrollbar-width: thin;
    scrollbar-color: #344054 transparent;
}

.sidebar-brand {
    min-height: 5rem;
    padding: 1rem 1.25rem;
    border-block-end: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    color: #ffffff;
    text-decoration: none;
}

.brand:hover {
    color: #ffffff;
}

.brand-mark {
    width: 2.75rem;
    height: 2.75rem;
    flex: 0 0 auto;
    overflow: visible;
}

.mark-layer {
    fill: rgba(124, 58, 237, 0.2);
    stroke: #a78bfa;
    stroke-linejoin: round;
    stroke-width: 1.7;
}

.mark-layer-back {
    fill: rgba(2, 132, 199, 0.18);
    stroke: #38bdf8;
}

.mark-layer-front {
    fill: rgba(219, 39, 119, 0.2);
    stroke: #f472b6;
}

.mark-flow {
    fill: none;
    stroke: #ffffff;
    stroke-linecap: round;
    stroke-width: 1.5;
}

.mark-node {
    fill: #ffffff;
    stroke: var(--primary);
    stroke-width: 1.5;
}

.brand-copy {
    display: grid;
    line-height: 1.25;
}

.brand-copy strong {
    font-family: var(--r2-font-technical, monospace);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.brand-copy small {
    color: #98a2b3;
    font-size: 0.72rem;
    font-weight: 500;
}

.sidebar-context {
    display: grid;
    gap: 0.15rem;
    margin: 1.15rem 1rem 0.6rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    padding: 0.8rem 0.9rem;
    background: rgba(255, 255, 255, 0.035);
}

.sidebar-context span,
.nav-label {
    color: #7f8a9d;
    font-size: 0.7rem;
    font-weight: 600;
}

.sidebar-context strong {
    color: #f9fafb;
    font-size: 0.86rem;
    font-weight: 600;
}

.sidebar-nav {
    display: grid;
    gap: 0.3rem;
    padding: 0.7rem 0.75rem 1rem;
}

.nav-label {
    margin: 0.25rem 0.75rem 0.35rem;
}

.sidebar-nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.75rem;
    border: 1px solid transparent;
    border-radius: 0.65rem;
    padding: 0.55rem 0.75rem;
    color: #aeb7c6;
    font-size: 0.86rem;
    font-weight: 500;
    text-decoration: none;
}

.sidebar-nav a::before {
    position: absolute;
    inset-block: 0.6rem;
    inset-inline-start: -0.75rem;
    width: 0.2rem;
    border-radius: 0 99rem 99rem 0;
    background: transparent;
    content: "";
}

.sidebar-nav a:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.055);
}

.sidebar-nav a.is-active {
    border-color: rgba(167, 139, 250, 0.18);
    color: #ffffff;
    background: rgba(124, 58, 237, 0.16);
}

.sidebar-nav a.is-active::before {
    background: linear-gradient(180deg, var(--accent), #a78bfa);
}

.sidebar-nav svg,
.icon-button svg {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.65;
}

.sidebar-user {
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.65rem;
    margin-top: 0;
    padding: 1rem;
    border-block-start: 1px solid rgba(255, 255, 255, 0.08);
}

.user-avatar {
    display: grid;
    width: 2.25rem;
    height: 2.25rem;
    place-items: center;
    border: 1px solid rgba(196, 181, 253, 0.35);
    border-radius: 50%;
    color: #ede9fe;
    background: rgba(124, 58, 237, 0.2);
    font-family: var(--r2-font-technical, monospace);
    font-weight: 600;
}

.user-copy {
    display: grid;
    min-width: 0;
    line-height: 1.35;
}

.user-copy strong {
    overflow: hidden;
    color: #f9fafb;
    font-size: 0.78rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-copy small {
    color: #7f8a9d;
    font-size: 0.65rem;
}

.icon-button {
    display: inline-grid;
    width: 2.35rem;
    height: 2.35rem;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 0.6rem;
    padding: 0;
    color: inherit;
    background: transparent;
    cursor: pointer;
}

.logout-button {
    color: #8f9bad;
}

.logout-button:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.07);
}

.sidebar-tools {
    display: grid;
    gap: 0.55rem;
    margin-block-start: auto;
    padding: 0.75rem 1rem 0.2rem;
}

.runtime-state.sidebar-runtime {
    width: 100%;
    justify-content: flex-start;
    border-color: rgba(52, 211, 153, 0.18);
    color: #a7f3d0;
    background: rgba(5, 150, 105, 0.1);
}

.theme-toggle {
    display: inline-flex;
    min-height: 2.55rem;
    align-items: center;
    justify-content: flex-start;
    gap: 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    padding: 0.5rem 0.7rem;
    color: var(--muted-strong);
    background: var(--surface);
    font: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
}

.theme-toggle:hover {
    border-color: var(--border-strong);
    color: var(--text);
    background: var(--surface-subtle);
}

.sidebar-tools .theme-toggle {
    width: 100%;
    border-color: rgba(255, 255, 255, 0.09);
    color: #aeb7c6;
    background: rgba(255, 255, 255, 0.035);
}

.sidebar-tools .theme-toggle:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.07);
}

.theme-icon {
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
}

.theme-icon-sun {
    display: none;
}

[data-theme="dark"] .theme-icon-moon {
    display: none;
}

[data-theme="dark"] .theme-icon-sun {
    display: block;
}

.public-theme-toggle {
    position: fixed;
    inset-block-start: 1rem;
    inset-inline-end: 1rem;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.workspace-shell {
    display: flex;
    min-width: 0;
    min-height: 100vh;
    flex-direction: column;
}

.sidebar-toggle {
    display: none;
    border-color: var(--border);
    color: var(--muted-strong);
    background: var(--surface);
}

.mobile-sidebar-toggle {
    position: fixed;
    inset-block-start: 0.85rem;
    inset-inline-start: 0.85rem;
    z-index: 34;
    box-shadow: var(--shadow-sm);
}

.runtime-state {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid #d1fae5;
    border-radius: 99rem;
    padding: 0.35rem 0.7rem;
    color: #047857;
    background: var(--success-soft);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.runtime-state > span,
.auth-meta > span {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0.2rem rgba(5, 150, 105, 0.12);
}

.workspace-content {
    width: min(100%, 96rem);
    min-height: auto;
    margin-inline: auto;
    flex: 1 0 auto;
    padding: 1.5rem clamp(1rem, 3vw, 2rem) 3.5rem;
}

.breadcrumb {
    align-items: center;
    gap: 0.4rem;
    margin-block-end: 1.45rem;
    color: #98a2b3;
    font-size: 0.75rem;
}

.breadcrumb a {
    color: var(--muted);
    text-decoration: none;
}

.breadcrumb a:hover {
    color: var(--primary);
}

.breadcrumb [aria-current="page"] {
    color: var(--muted-strong);
    font-weight: 500;
}

.breadcrumb-separator {
    color: #c8ccd4;
    font-size: 1rem;
}

.site-footer {
    border: 0;
    padding: 1rem clamp(1rem, 3vw, 2rem) 1.5rem;
    color: #98a2b3;
    background: transparent;
    font-size: 0.68rem;
    text-align: center;
}

.page-heading {
    margin-block-end: 1.75rem;
}

.page-heading h1 {
    margin: 0.25rem 0 0.45rem;
    color: #101323;
    font-size: clamp(1.55rem, 3vw, 2.15rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.45;
}

.page-heading p:not(.eyebrow) {
    max-width: 54rem;
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--primary) !important;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.eyebrow::before {
    width: 1rem;
    height: 0.14rem;
    border-radius: 99rem;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    content: "";
}

.dashboard-heading {
    position: relative;
    overflow: hidden;
    border: 1px solid #e9e2ff;
    border-radius: var(--radius-lg);
    padding: clamp(1.35rem, 3vw, 2.25rem);
    background:
        linear-gradient(110deg, rgba(255, 255, 255, 0.96), rgba(245, 243, 255, 0.94)),
        var(--surface);
    box-shadow: var(--shadow-sm);
}

.dashboard-heading::after {
    position: absolute;
    inset-block-start: -5.5rem;
    inset-inline-end: -2.5rem;
    width: 15rem;
    height: 15rem;
    border: 1px solid rgba(124, 58, 237, 0.12);
    border-radius: 38% 62% 54% 46%;
    background: repeating-linear-gradient(135deg, transparent 0 12px, rgba(124, 58, 237, 0.035) 12px 13px);
    content: "";
    transform: rotate(18deg);
}

.dashboard-heading > * {
    position: relative;
    z-index: 1;
}

.card-grid {
    gap: 1rem;
}

.card,
.panel,
.form-panel,
.editor-shell,
.query-card,
.empty-state,
.auth-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

.card {
    position: relative;
    overflow: hidden;
    padding: 1.35rem;
}

.card::before {
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(124, 58, 237, 0.35), transparent);
    content: "";
    opacity: 0;
    transition: opacity 160ms ease;
}

.card:hover {
    border-color: #d8d0ed;
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.card:hover::before {
    opacity: 1;
}

.card h2,
.panel h2,
.form-panel h2,
.query-card h3 {
    color: #202333;
    font-weight: 700;
}

.card h2 {
    margin-block-end: 0.45rem;
    font-size: 1.03rem;
}

.card p,
.panel p,
.empty-state p,
.auth-panel > p {
    color: var(--muted);
}

.button,
.query-card button,
.secondary-button {
    display: inline-flex;
    min-height: 2.65rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--primary);
    border-radius: 0.6rem;
    padding: 0.55rem 1rem;
    color: #ffffff;
    background: var(--primary);
    box-shadow: 0 1px 2px rgba(109, 40, 217, 0.15);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
}

.button:hover,
.query-card button:hover {
    border-color: var(--primary-hover);
    color: #ffffff;
    background: var(--primary-hover);
    box-shadow: 0 5px 14px rgba(109, 40, 217, 0.18);
    transform: translateY(-1px);
}

.button:active,
.query-card button:active {
    transform: translateY(0);
}

.button-secondary,
.secondary-button,
.query-card .secondary-button {
    border-color: var(--border-strong);
    color: var(--muted-strong);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

.button-secondary:hover,
.secondary-button:hover,
.query-card .secondary-button:hover {
    border-color: #c4b5fd;
    color: var(--primary-hover);
    background: var(--primary-soft);
}

.danger-button,
.query-card .danger-button {
    border-color: #fecaca;
    color: var(--danger);
    background: var(--danger-soft);
}

.panel,
.form-panel,
.query-card {
    padding: 1.25rem;
}

.form-field {
    margin-block-end: 1.1rem;
}

.form-field label,
.search-form label,
.editor-pane > label,
.query-card label {
    display: block;
    margin-block-end: 0.4rem;
    color: #344054;
    font-size: 0.78rem;
    font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea,
.search-form input,
.query-card input,
.query-card select,
.query-card textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 0.6rem;
    padding: 0.62rem 0.75rem;
    color: var(--text);
    background: var(--surface);
    box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.025);
}

.form-field input:hover,
.form-field select:hover,
.form-field textarea:hover,
.search-form input:hover,
.query-card input:hover,
.query-card select:hover,
.query-card textarea:hover {
    border-color: #aeb4bf;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.search-form input:focus,
.query-card input:focus,
.query-card select:focus,
.query-card textarea:focus {
    border-color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.form-field small,
th small {
    color: var(--muted);
    font-size: 0.72rem;
}

.field-error,
.errorlist {
    margin: 0.35rem 0 0;
    padding: 0;
    color: var(--danger);
    font-size: 0.74rem;
    list-style: none;
}

.has-error input,
.has-error select,
.has-error textarea {
    border-color: #fca5a5;
    background: #fffafa;
}

.message-area {
    position: relative;
    z-index: 5;
    margin-block-end: 1rem;
}

.message {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border: 1px solid #bae6fd;
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.9rem;
    color: #075985;
    background: var(--info-soft);
    box-shadow: var(--shadow-xs);
    font-size: 0.8rem;
}

.message-success {
    border-color: #a7f3d0;
    color: #047857;
    background: var(--success-soft);
}

.message-error {
    border-color: #fecaca;
    color: #b91c1c;
    background: var(--danger-soft);
}

.message-warning {
    border-color: #fde68a;
    color: #b45309;
    background: var(--warning-soft);
}

.message-dismiss {
    font-size: 1.15rem;
    line-height: 1;
}

.table-wrap,
.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

table {
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
}

th,
td {
    border: 0;
    border-block-end: 1px solid var(--border);
    padding: 0.8rem 0.9rem;
}

th {
    color: var(--muted-strong);
    background: #fafafe;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

td {
    color: #344054;
    font-size: 0.8rem;
}

tbody tr:last-child td {
    border-block-end: 0;
}

tbody tr:hover td {
    background: #fcfcff;
}

.badge,
.status-pill,
.tag-list span {
    border: 1px solid #e9d5ff;
    border-radius: 99rem;
    padding: 0.2rem 0.6rem;
    color: var(--primary-hover);
    background: var(--primary-soft);
    font-size: 0.7rem;
    font-weight: 600;
}

.status-succeeded,
.status-ready {
    border-color: #a7f3d0;
    color: #047857;
    background: var(--success-soft);
}

.status-failed {
    border-color: #fecaca;
    color: #b91c1c;
    background: var(--danger-soft);
}

.empty-state {
    padding: clamp(2rem, 5vw, 4rem);
    background:
        radial-gradient(circle at 50% 0%, rgba(124, 58, 237, 0.06), transparent 42%),
        var(--surface);
    text-align: center;
}

.empty-state h1,
.empty-state h2 {
    color: #202333;
}

.dashboard-summary {
    border-color: var(--border);
    box-shadow: var(--shadow-xs);
}

.editor-shell {
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.editor-toolbar {
    background: #fafafe;
}

.editor-toolbar button {
    border-color: var(--border-strong);
    border-radius: 0.5rem;
    color: var(--muted-strong);
    background: var(--surface);
}

.editor-toolbar button:hover {
    border-color: #c4b5fd;
    color: var(--primary-hover);
    background: var(--primary-soft);
}

.save-status {
    border: 1px solid var(--border);
    border-radius: 99rem;
    font-size: 0.72rem;
}

.query-card {
    border-color: var(--border);
    border-radius: var(--radius);
}

.query-card:hover {
    border-color: #d8d0ed;
    box-shadow: var(--shadow-sm);
}

.esd-block-reference {
    border-color: #c4b5fd;
    color: var(--primary-hover);
    background: var(--primary-soft);
}

.public-shell,
.public-content,
.auth-shell {
    min-height: 100vh;
}

.public-content {
    width: 100%;
    padding: 0;
}

.auth-page {
    overflow-x: hidden;
    background: #f8f8fc;
}

.auth-page .public-shell {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 12%, rgba(124, 58, 237, 0.08), transparent 30rem),
        linear-gradient(180deg, #fbfbfe 0%, #f5f4fa 100%);
}

.auth-page .public-shell::before {
    position: absolute;
    z-index: -2;
    inset: 0;
    opacity: 0.48;
    background-image:
        linear-gradient(rgba(124, 58, 237, 0.055) 1px, transparent 1px),
        linear-gradient(90deg, rgba(124, 58, 237, 0.055) 1px, transparent 1px);
    background-position: center;
    background-size: 64px 64px;
    content: "";
    -webkit-mask-image: radial-gradient(circle at center, #000 0, transparent 72%);
    mask-image: radial-gradient(circle at center, #000 0, transparent 72%);
}

.auth-page .public-shell::after {
    position: absolute;
    z-index: -1;
    inset-block-start: 8%;
    inset-inline-start: 50%;
    width: min(84vw, 58rem);
    height: min(84vw, 58rem);
    border: 1px solid rgba(124, 58, 237, 0.08);
    border-radius: 42% 58% 48% 52%;
    content: "";
    transform: translateX(50%) rotate(25deg);
}

.auth-shell {
    display: grid;
    place-items: center;
    padding: clamp(1.25rem, 4vw, 3rem) 1rem;
}

.auth-panel {
    width: min(100%, 28.5rem);
    margin: 0;
    border-color: rgba(218, 213, 229, 0.95);
    border-radius: 1.15rem;
    padding: clamp(1.5rem, 5vw, 2.25rem);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.8) inset;
    backdrop-filter: blur(16px);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-block-end: 1.75rem;
}

.auth-mark {
    display: grid;
    width: 3.25rem;
    height: 3.25rem;
    place-items: center;
    border: 1px solid #e5ddf7;
    border-radius: 0.9rem;
    background: linear-gradient(145deg, #ffffff, var(--primary-soft));
    box-shadow: var(--shadow-sm);
}

.auth-mark .brand-mark {
    width: 2.7rem;
    height: 2.7rem;
}

.auth-mark .mark-layer {
    fill: rgba(124, 58, 237, 0.09);
    stroke: var(--primary);
}

.auth-mark .mark-layer-back {
    fill: rgba(2, 132, 199, 0.08);
    stroke: var(--info);
}

.auth-mark .mark-layer-front {
    fill: rgba(219, 39, 119, 0.08);
    stroke: var(--accent);
}

.auth-mark .mark-flow {
    stroke: #5b21b6;
}

.auth-brand > span:last-child {
    display: grid;
    line-height: 1.2;
}

.auth-brand strong {
    color: #242033;
    font-family: var(--r2-font-technical, monospace);
    font-size: 1.25rem;
    letter-spacing: 0.05em;
}

.auth-brand small {
    color: var(--muted);
    font-size: 0.7rem;
}

.auth-heading {
    margin-block-end: 1.5rem;
}

.auth-heading .eyebrow {
    margin: 0 0 0.35rem;
}

.auth-heading h1 {
    margin: 0;
    color: #171426;
    font-size: clamp(1.55rem, 5vw, 1.85rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.5;
}

.auth-heading > p:last-child {
    margin: 0.45rem 0 0;
    color: var(--muted);
    font-size: 0.79rem;
    line-height: 1.85;
}

.auth-field {
    margin-block-end: 1rem;
}

.auth-field label {
    margin-block-end: 0.45rem;
    color: #344054;
    font-size: 0.77rem;
}

.input-frame {
    position: relative;
    display: block;
}

.input-frame > svg {
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 0.85rem;
    z-index: 1;
    width: 1.15rem;
    height: 1.15rem;
    fill: none;
    stroke: #98a2b3;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.6;
    transform: translateY(-50%);
    pointer-events: none;
}

.auth-field input {
    min-height: 3rem;
    border-color: #d7d9e0;
    border-radius: 0.68rem;
    padding: 0.7rem 2.7rem 0.7rem 0.85rem;
    font-size: 0.84rem;
}

.auth-field input::placeholder {
    color: #a0a7b3;
}

.auth-field.is-focused input,
.auth-field:focus-within input {
    border-color: var(--primary);
    background: #fefeff;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12), 0 4px 12px rgba(124, 58, 237, 0.06);
}

.auth-field.is-focused .input-frame > svg,
.auth-field:focus-within .input-frame > svg {
    stroke: var(--primary);
}

.auth-field.has-error input {
    border-color: #fca5a5;
    background: #fffafa;
}

.auth-error {
    display: flex;
    gap: 0.65rem;
    margin-block-end: 1.1rem;
    border: 1px solid #fecaca;
    border-radius: 0.65rem;
    padding: 0.7rem 0.8rem;
    color: #b91c1c;
    background: var(--danger-soft);
    font-size: 0.72rem;
}

.auth-error > svg {
    width: 1.2rem;
    height: 1.2rem;
    flex: 0 0 auto;
    margin-block-start: 0.1rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 1.7;
}

.auth-error strong {
    display: block;
    margin-block-end: 0.1rem;
}

.auth-error .errorlist {
    color: inherit;
    font-size: inherit;
}

.auth-submit {
    width: 100%;
    min-height: 3rem;
    margin-block-start: 0.35rem;
    border-radius: 0.68rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    box-shadow: 0 7px 18px rgba(109, 40, 217, 0.2);
    font-size: 0.83rem;
}

.auth-submit:hover {
    box-shadow: 0 9px 22px rgba(109, 40, 217, 0.26);
}

.auth-submit:disabled {
    cursor: wait;
    opacity: 0.82;
}

.button-loading {
    display: none;
    align-items: center;
    gap: 0.55rem;
}

.button-loading i {
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-block-start-color: #ffffff;
    border-radius: 50%;
    animation: r2-spin 700ms linear infinite;
}

.auth-submit.is-loading .button-label {
    display: none;
}

.auth-submit.is-loading .button-loading {
    display: inline-flex;
}

.auth-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    margin: 1.5rem 0 0 !important;
    padding-block-start: 1rem;
    border-block-start: 1px solid #eef0f3;
    color: #7c8492 !important;
    font-size: 0.68rem;
}

.sidebar-backdrop {
    display: none;
}

[data-theme="dark"] ::selection {
    color: var(--text);
    background: #49307a;
}

[data-theme="dark"] .workspace-content a:not(.button),
[data-theme="dark"] .public-content a:not(.button) {
    color: #c4b5fd;
}

[data-theme="dark"] .eyebrow {
    color: #c4b5fd !important;
}

[data-theme="dark"] .badge,
[data-theme="dark"] .status-pill,
[data-theme="dark"] .tag-list span {
    color: #c4b5fd;
}

[data-theme="dark"] .page-heading h1,
[data-theme="dark"] .card h2,
[data-theme="dark"] .panel h2,
[data-theme="dark"] .form-panel h2,
[data-theme="dark"] .query-card h3,
[data-theme="dark"] .empty-state h1,
[data-theme="dark"] .empty-state h2,
[data-theme="dark"] .auth-brand strong,
[data-theme="dark"] .auth-heading h1 {
    color: var(--text);
}

[data-theme="dark"] .dashboard-heading {
    border-color: #3a3154;
    background:
        linear-gradient(110deg, rgba(20, 27, 45, 0.98), rgba(38, 29, 61, 0.94)),
        var(--surface);
}

[data-theme="dark"] .card:hover,
[data-theme="dark"] .query-card:hover {
    border-color: #4c4265;
}

[data-theme="dark"] .form-field label,
[data-theme="dark"] .search-form label,
[data-theme="dark"] .editor-pane > label,
[data-theme="dark"] .query-card label,
[data-theme="dark"] td,
[data-theme="dark"] .auth-field label {
    color: var(--muted-strong);
}

[data-theme="dark"] .form-field input:hover,
[data-theme="dark"] .form-field select:hover,
[data-theme="dark"] .form-field textarea:hover,
[data-theme="dark"] .search-form input:hover,
[data-theme="dark"] .query-card input:hover,
[data-theme="dark"] .query-card select:hover,
[data-theme="dark"] .query-card textarea:hover {
    border-color: #596781;
}

[data-theme="dark"] .has-error input,
[data-theme="dark"] .has-error select,
[data-theme="dark"] .has-error textarea,
[data-theme="dark"] .auth-field.has-error input {
    background: var(--danger-soft);
}

[data-theme="dark"] .message {
    border-color: #22536a;
    color: #bae6fd;
}

[data-theme="dark"] .message-success {
    border-color: #23664f;
    color: #a7f3d0;
}

[data-theme="dark"] .message-error,
[data-theme="dark"] .auth-error {
    border-color: #743744;
    color: #fecdd3;
}

[data-theme="dark"] .message-warning {
    border-color: #765820;
    color: #fde68a;
}

[data-theme="dark"] th,
[data-theme="dark"] .editor-toolbar {
    background: var(--surface-subtle);
}

[data-theme="dark"] tbody tr:hover td {
    background: #192238;
}

[data-theme="dark"] .badge,
[data-theme="dark"] .status-pill,
[data-theme="dark"] .tag-list span {
    border-color: #59467d;
}

[data-theme="dark"] .status-succeeded,
[data-theme="dark"] .status-ready {
    border-color: #23664f;
    color: #a7f3d0;
}

[data-theme="dark"] .status-failed {
    border-color: #743744;
    color: #fecdd3;
}

[data-theme="dark"] .auth-page,
[data-theme="dark"] .auth-page .public-shell {
    background: var(--background);
}

[data-theme="dark"] .auth-page .public-shell {
    background:
        radial-gradient(circle at 50% 12%, rgba(167, 139, 250, 0.12), transparent 30rem),
        linear-gradient(180deg, #0d1324 0%, #090e1b 100%);
}

[data-theme="dark"] .auth-panel {
    border-color: var(--border);
    background: rgba(20, 27, 45, 0.96);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.035) inset;
}

[data-theme="dark"] .auth-mark {
    border-color: #4b3c6a;
    background: linear-gradient(145deg, #192238, var(--primary-soft));
}

[data-theme="dark"] .auth-mark .mark-flow {
    stroke: #ddd6fe;
}

[data-theme="dark"] .auth-field.is-focused input,
[data-theme="dark"] .auth-field:focus-within input {
    background: #172035;
}

[data-theme="dark"] .auth-meta {
    border-block-start-color: var(--border);
    color: var(--muted) !important;
}

[data-theme="dark"] .preview-surface pre,
[data-theme="dark"] .esd-block-reference {
    background: var(--primary-soft);
}

[data-theme="dark"] .query-resource-list li,
[data-theme="dark"] .js-query-result th,
[data-theme="dark"] .js-query-result td {
    border-color: var(--border);
}

[data-theme="dark"] .esd-block-reference.is-ready {
    border-color: #23664f;
    background: var(--success-soft);
}

[data-theme="dark"] .esd-block-reference.is-error,
[data-theme="dark"] .esd-block-reference.is-stale {
    border-color: #743744;
    background: var(--danger-soft);
}

[data-theme="dark"] .save-status.is-dirty {
    color: #fde68a;
    background: var(--warning-soft);
}

[data-theme="dark"] .save-status.is-conflict {
    background: var(--danger-soft);
}

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

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media (max-width: 960px) {
    .app-shell {
        display: block;
    }

    .app-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        width: min(var(--sidebar-width), calc(100vw - 3.5rem));
        transform: translateX(105%);
        transition: transform 220ms ease;
    }

    .sidebar-open {
        overflow: hidden;
    }

    .sidebar-open .app-sidebar {
        box-shadow: -18px 0 48px rgba(17, 24, 39, 0.24);
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 35;
        inset: 0;
        display: block;
        border: 0;
        padding: 0;
        background: rgba(17, 24, 39, 0.42);
        cursor: default;
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    .sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-toggle {
        display: inline-grid;
    }

    .workspace-content {
        padding-block-start: 4.5rem;
    }
}

@media (max-width: 720px) {
    .page-heading h1 {
        font-size: 1.45rem;
    }

    .page-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .page-actions > .button,
    .page-actions > form,
    .page-actions .search-form {
        width: 100%;
    }

    .auth-panel {
        border-radius: 1rem;
    }

    .public-theme-toggle {
        min-width: 2.65rem;
        justify-content: center;
        padding-inline: 0.65rem;
    }

    .public-theme-toggle .theme-label {
        display: none;
    }
}

@media (max-width: 420px) {
    .auth-shell {
        padding: 0.75rem;
    }

    .auth-panel {
        padding: 1.35rem;
    }

    .auth-brand {
        margin-block-end: 1.35rem;
    }
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    clip-path: inset(50%) !important;
}

.editor-heading {
    align-items: center;
    margin-block-end: 1rem;
}

.editor-heading h1 {
    max-width: min(60vw, 48rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-heading-actions,
.editor-mode-switch,
.editor-format-actions,
.block-picker-heading,
.block-picker-actions,
.editor-drawer-heading {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.editor-heading-actions {
    justify-content: flex-end;
}

.editor-review-action {
    padding: 0.42rem 0.75rem;
    font-size: 0.76rem;
    white-space: nowrap;
}

.editor-shell {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.editor-toolbar {
    position: sticky;
    z-index: 25;
    inset-block-start: 0;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.45rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.42rem;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    box-shadow: var(--shadow-xs);
    scrollbar-width: thin;
    backdrop-filter: blur(12px);
}

.editor-mode-switch,
.editor-format-actions {
    flex: 0 0 auto;
}

.editor-toolbar button {
    min-height: 2.15rem;
    padding: 0.3rem 0.62rem;
    font-size: 0.75rem;
    white-space: nowrap;
}

.editor-toolbar button[aria-pressed="true"] {
    border-color: var(--primary);
    color: var(--primary-hover);
    background: var(--primary-soft);
    box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.08) inset;
}

.editor-toolbar button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.editor-toolbar-separator {
    width: 1px;
    height: 1.55rem;
    flex: 0 0 1px;
    background: var(--border);
}

.editor-preview-error {
    width: min(100%, 46rem);
    margin: 0.65rem auto 0;
    border: 1px solid #fecaca;
    border-radius: 0.55rem;
    padding: 0.45rem 0.7rem;
    background: var(--danger-soft);
    font-size: 0.78rem;
}

.editor-stage {
    min-height: max(38rem, calc(100vh - 16rem));
    padding-block: clamp(1.1rem, 3vw, 2.4rem) 4rem;
}

.editor-column {
    width: min(100%, 46rem);
    margin-inline: auto;
}

.editor-pane {
    min-width: 0;
    border: 0;
    padding: 0;
}

.editor-pane[hidden],
.editor-reading-view[hidden],
.editor-drawer[hidden] {
    display: none !important;
}

.js-markdown-source {
    min-height: 38rem;
}

.editor-column .cm-editor {
    min-height: max(38rem, calc(100vh - 19rem));
    border: 0;
    direction: rtl;
    color: var(--text);
    background: transparent;
    font-size: 1rem;
    text-align: right;
}

.editor-column .cm-editor.cm-focused {
    outline: 0;
}

.editor-column .cm-scroller {
    overflow: visible;
    font-family: var(--r2-font-body, Tahoma, Arial, sans-serif);
    line-height: 1.95;
}

.editor-column .cm-content {
    min-height: max(38rem, calc(100vh - 19rem));
    padding: 0.8rem 0.35rem 5rem;
    caret-color: var(--primary);
}

.editor-column .cm-line {
    padding-inline: 0.35rem;
    unicode-bidi: plaintext;
}

.editor-column .cm-gutters {
    border-inline-end: 1px solid var(--border);
    border-inline-start: 0;
    color: var(--muted);
    background: transparent;
}

.cm-live-preview-block {
    width: 100%;
    min-width: 0;
    border-radius: 0.45rem;
    padding: 0.2rem 0.35rem;
    cursor: text;
    outline: none;
}

.cm-live-preview-block:hover,
.cm-live-preview-block:focus-visible {
    background: color-mix(in srgb, var(--primary-soft) 55%, transparent);
}

.cm-live-preview-block > :first-child,
.editor-reading-view > :first-child {
    margin-block-start: 0;
}

.cm-live-preview-block > :last-child,
.editor-reading-view > :last-child {
    margin-block-end: 0;
}

.cm-live-preview-block h1,
.cm-live-preview-block h2,
.cm-live-preview-block h3,
.cm-live-preview-block h4,
.cm-live-preview-block h5,
.cm-live-preview-block h6 {
    margin-block: 0.35rem;
    line-height: 1.5;
}

.cm-live-preview-block p,
.cm-live-preview-block blockquote,
.cm-live-preview-block ul,
.cm-live-preview-block ol,
.cm-live-preview-block pre,
.cm-live-preview-block table {
    margin-block: 0.25rem;
}

.preview-surface code,
.preview-surface pre,
.preview-surface kbd,
.preview-surface samp,
.esd-block-reference {
    direction: ltr;
    unicode-bidi: isolate;
}

.preview-surface a {
    unicode-bidi: plaintext;
}

.preview-surface table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.preview-surface img {
    height: auto;
    border-radius: 0.45rem;
}

.editor-reading-view {
    min-height: max(38rem, calc(100vh - 19rem));
    padding: 0.8rem 0.7rem 5rem;
    color: var(--text);
}

.esd-block-reference {
    display: block;
    width: 100%;
    min-height: 4rem;
    margin-block: 0.55rem;
    border-style: solid;
    border-radius: 0.65rem;
    padding: 0.8rem;
    text-align: right;
    cursor: pointer;
}

.esd-block-state {
    display: block;
    direction: rtl;
    unicode-bidi: plaintext;
    font-weight: 600;
}

.esd-block-reference.is-ready {
    border-color: #a7f3d0;
    color: #047857;
    background: var(--success-soft);
}

.esd-block-reference.is-stale {
    border-color: #fcd34d;
    color: #92400e;
    background: var(--warning-soft);
}

.esd-block-reference.is-error {
    border-color: #fecaca;
    color: #b91c1c;
    background: var(--danger-soft);
}

.esd-chart-canvas {
    min-height: 18rem;
    margin-block-start: 0.65rem;
    direction: ltr;
}

.save-status {
    margin: 0;
    padding: 0.3rem 0.62rem;
    white-space: nowrap;
}

.save-status.is-saved {
    border-color: #a7f3d0;
    color: #047857;
    background: var(--success-soft);
}

.save-status.is-saving {
    color: var(--primary-hover);
    background: var(--primary-soft);
}

.save-status.is-retry {
    color: #92400e;
    background: var(--warning-soft);
}

.block-picker {
    width: min(34rem, calc(100vw - 2rem));
    max-height: min(42rem, calc(100vh - 2rem));
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    padding: 1rem;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.block-picker::backdrop {
    background: rgba(17, 24, 39, 0.46);
    backdrop-filter: blur(2px);
}

.block-picker-heading,
.editor-drawer-heading {
    justify-content: space-between;
}

.block-picker-heading h2,
.editor-drawer-heading h2 {
    margin: 0;
    font-size: 1.1rem;
}

.block-picker-list {
    display: grid;
    max-height: 23rem;
    overflow-y: auto;
    gap: 0.45rem;
    margin-block: 0.8rem;
}

.block-picker-item {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    padding: 0.65rem;
    color: var(--text);
    background: var(--surface-subtle);
    text-align: right;
    cursor: pointer;
}

.block-picker-item:hover,
.block-picker-item:focus-visible {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.editor-drawer {
    position: fixed;
    z-index: 70;
    inset: 0;
}

.editor-drawer-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    border: 0;
    background: rgba(17, 24, 39, 0.44);
    cursor: default;
    backdrop-filter: blur(2px);
}

.editor-drawer-panel {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 0;
    width: min(58rem, 94vw);
    overflow-y: auto;
    border-inline-start: 1px solid var(--border);
    padding: 1rem clamp(0.8rem, 2vw, 1.4rem) 2rem;
    background: var(--background);
    box-shadow: var(--shadow-lg);
}

.editor-drawer-heading {
    position: sticky;
    z-index: 2;
    inset-block-start: -1rem;
    margin: -1rem calc(clamp(0.8rem, 2vw, 1.4rem) * -1) 1rem;
    border-block-end: 1px solid var(--border);
    padding: 0.75rem clamp(0.8rem, 2vw, 1.4rem);
    background: var(--surface);
}

.editor-drawer .query-workspace {
    margin: 0;
}

.editor-drawer-open {
    overflow: hidden;
}

[data-theme="dark"] .editor-toolbar {
    background: color-mix(in srgb, var(--surface-subtle) 94%, transparent);
}

[data-theme="dark"] .editor-column .cm-editor,
[data-theme="dark"] .editor-column .cm-gutters,
[data-theme="dark"] .block-picker-item {
    color: var(--text);
    background: transparent;
}

[data-theme="dark"] .save-status.is-saved {
    border-color: #23664f;
    color: #a7f3d0;
    background: var(--success-soft);
}

[data-theme="dark"] .save-status.is-retry,
[data-theme="dark"] .esd-block-reference.is-stale {
    border-color: #765820;
    color: #fde68a;
    background: var(--warning-soft);
}

@media (max-width: 720px) {
    .editor-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .editor-heading h1 {
        max-width: calc(100vw - 2rem);
    }

    .editor-heading-actions {
        width: 100%;
        justify-content: space-between;
    }

    .editor-toolbar {
        margin-inline: -0.4rem;
        border-radius: 0.55rem;
    }

    .editor-stage {
        min-height: calc(100vh - 14rem);
        padding-block-start: 0.8rem;
    }

    .editor-column .cm-editor,
    .editor-column .cm-content,
    .editor-reading-view {
        min-height: calc(100vh - 16rem);
    }

    .editor-column .cm-content {
        padding-inline: 0;
    }

    .editor-drawer-panel {
        width: 100%;
    }

    .editor-drawer .query-grid {
        grid-template-columns: 1fr;
    }
}

/* پنجرهٔ سه‌مرحله‌ای جدول داده‌ای و اجزای مشترک پنجره‌های ویرایشگر */
.esd-block-reference.is-running {
    border-color: var(--warning);
    background: var(--warning-soft);
}

.block-picker,
.data-table-dialog {
    direction: rtl;
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

.block-picker-heading .eyebrow,
.data-table-dialog-heading .eyebrow,
.editor-drawer-heading .eyebrow {
    margin: 0 0 0.15rem;
}

.block-picker > p,
.block-picker-actions {
    color: var(--muted);
    font-size: 0.82rem;
}

.block-picker-actions {
    justify-content: flex-end;
    border-block-start: 1px solid var(--border);
    padding-block-start: 0.85rem;
}

.data-table-dialog {
    width: min(70rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0;
    background: var(--surface);
}

.data-table-dialog::backdrop {
    background: rgb(11 16 32 / 72%);
    backdrop-filter: blur(3px);
}

.data-table-dialog-heading,
.data-table-dialog-actions {
    position: sticky;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(12px);
}

.data-table-dialog-heading {
    inset-block-start: 0;
    border-block-end: 1px solid var(--border);
    box-shadow: 0 1px 0 rgb(15 23 42 / 2%);
}

.data-table-dialog-heading h2 {
    margin: 0;
    font-size: 1.2rem;
}

.data-table-dialog-actions {
    inset-block-end: 0;
    justify-content: flex-end;
    margin-inline: -1.25rem;
    border-block-start: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgb(15 23 42 / 5%);
}

.data-table-dialog form,
.data-table-status,
.data-table-steps {
    margin-inline: 1.25rem;
}

.data-table-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
    margin-block: 0;
    padding: 1rem 0 0;
    counter-reset: table-step;
    list-style: none;
}

.data-table-steps li {
    display: flex;
    min-height: 3rem;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.65rem 0.8rem;
    color: var(--muted);
    background: var(--surface-subtle);
    font-size: 0.8rem;
    font-weight: 650;
}

.data-table-steps li.is-active {
    border-color: color-mix(in srgb, var(--primary) 38%, var(--border));
    color: var(--primary-hover);
    background: var(--primary-soft);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 8%, transparent);
}

.data-table-steps li.is-complete {
    border-color: color-mix(in srgb, var(--success) 28%, var(--border));
    color: var(--success);
    background: var(--success-soft);
}

.data-table-step {
    min-height: 26rem;
    padding-block: 1.1rem 1.75rem;
}

.data-table-step[hidden] {
    display: none !important;
}

.data-table-step > h3 {
    margin: 0 0 0.25rem;
    color: var(--text);
    font-size: 1.05rem;
}

.data-table-step > h3 + p {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
}

.data-table-field-grid,
.controlled-query-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: 0.85rem 1rem;
}

.data-table-field-grid {
    margin-block: 1rem;
}

.data-table-field,
.controlled-query-grid label {
    display: grid;
    min-width: 0;
    align-content: start;
    gap: 0.38rem;
}

.data-table-field > label,
.controlled-query-grid label,
.js-r-calculation > label {
    color: var(--muted-strong);
    font-size: 0.77rem;
    font-weight: 650;
}

.data-table-dialog input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]),
.data-table-dialog select,
.data-table-dialog textarea {
    width: 100%;
    min-height: 2.65rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.6rem;
    padding: 0.58rem 0.72rem;
    color: var(--text);
    background: var(--surface);
    box-shadow: inset 0 1px 2px rgb(16 24 40 / 3%);
}

.data-table-dialog textarea {
    min-height: 12rem;
    resize: vertical;
}

.data-table-dialog textarea[dir="ltr"],
.data-table-dialog input[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

.data-table-dialog input[readonly] {
    color: var(--muted);
    background: var(--surface-subtle);
}

.data-table-dialog input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]):hover,
.data-table-dialog select:hover,
.data-table-dialog textarea:hover {
    border-color: #aeb4bf;
}

.data-table-dialog input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]):focus,
.data-table-dialog select:focus,
.data-table-dialog textarea:focus {
    border-color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgb(124 58 237 / 12%);
}

.data-table-dialog input[type="radio"],
.data-table-dialog input[type="checkbox"] {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin: 0.18rem 0 0;
    accent-color: var(--primary);
}

.dataset-choice-list,
.column-choice-grid,
.table-presentation-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13.75rem, 1fr));
    gap: 0.7rem;
    margin-block: 1rem;
}

.dataset-choice-list {
    max-height: min(18rem, 36vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 0.7rem;
    background: var(--background);
}

.dataset-choice {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    gap: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.8rem;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}

.dataset-choice:hover,
.dataset-choice:focus-within {
    border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
    background: var(--primary-soft);
}

.dataset-choice:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 9%, transparent);
}

.dataset-choice > span {
    display: grid;
    min-width: 0;
    gap: 0.15rem;
}

.dataset-choice strong,
.dataset-choice small {
    overflow-wrap: anywhere;
}

.dataset-choice strong {
    color: var(--text);
    font-size: 0.84rem;
}

.dataset-choice small {
    display: block;
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.7;
}

.data-table-advanced,
.data-table-panel,
.data-table-mode-switch {
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface-subtle);
}

.data-table-advanced {
    margin-block-start: 1rem;
    padding: 0.75rem 0.9rem;
}

.data-table-advanced summary {
    color: var(--muted-strong);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
}

.data-table-advanced[open] summary {
    margin-block-end: 0.8rem;
}

.data-table-panel,
.data-table-mode-switch {
    min-width: 0;
    margin: 1rem 0;
    padding: 0.9rem;
}

.data-table-panel legend,
.data-table-mode-switch legend {
    padding-inline: 0.35rem;
    color: var(--muted-strong);
    font-size: 0.78rem;
    font-weight: 700;
}

.data-table-mode-switch {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.data-table-mode-switch label,
.column-choice-grid label,
.auto-preview-option {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.48rem;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.55rem 0.65rem;
    color: var(--muted-strong);
    background: var(--surface);
    font-size: 0.76rem;
    cursor: pointer;
}

.data-table-mode-switch label:has(input:checked),
.column-choice-grid label:has(input:checked),
.auto-preview-option:has(input:checked) {
    border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
    color: var(--primary-hover);
    background: var(--primary-soft);
}

.data-table-contract-help {
    margin-block: 1rem 0.75rem;
    border: 1px solid var(--border);
    border-inline-start: 0.25rem solid var(--primary);
    border-radius: 0.6rem;
    padding: 0.75rem 0.85rem;
    color: var(--muted-strong);
    background: var(--surface-subtle);
    font-size: 0.78rem;
}

.js-r-calculation textarea {
    margin-block-start: 0.35rem;
    direction: ltr;
    font-family: var(--r2-font-technical, monospace);
    line-height: 1.65;
    text-align: left;
    tab-size: 4;
}

.operation-help,
.operation-section-heading p,
.operation-library > p,
.basic-query-controls small {
    margin: 0;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.8;
}

.operation-section {
    margin-block: 1rem;
}

.operation-section-heading,
.operation-card-heading,
.operation-add-row,
.chart-option-row,
.presentation-order-actions,
.r-state-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.operation-section-heading h4,
.operation-card-heading h5,
.r-schema-panel h4 {
    margin: 0;
}

.operation-list {
    display: grid;
    gap: 0.75rem;
    margin-block-start: 0.75rem;
}

.operation-card {
    border: 1px solid var(--border);
    border-inline-start: 0.22rem solid var(--primary);
    border-radius: 0.7rem;
    padding: 0.8rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.operation-card-heading {
    align-items: flex-start;
}

.operation-card-heading p,
.operation-card-heading small {
    display: block;
    margin: 0.15rem 0 0;
    color: var(--muted);
    font-size: 0.7rem;
}

.operation-card-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.7rem;
    margin-block-start: 0.75rem;
}

.operation-card-controls > label,
.operation-card-controls > div > label,
.operation-add-row > label,
.chart-advanced-json > label {
    display: grid;
    gap: 0.35rem;
    color: var(--muted-strong);
    font-size: 0.74rem;
    font-weight: 650;
}

.operation-add-row {
    justify-content: flex-start;
}

.operation-add-row select {
    width: min(22rem, 100%);
}

.r-editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(15rem, 0.7fr);
    gap: 1rem;
    align-items: stretch;
}

.r-editor-column > label {
    display: block;
    margin-block-end: 0.35rem;
    color: var(--muted-strong);
    font-size: 0.77rem;
    font-weight: 650;
}

.r-code-editor {
    min-height: 22rem;
    overflow: hidden;
    direction: ltr;
    border: 1px solid var(--border-strong);
    border-radius: 0.65rem;
    background: #111827;
    color: #e5e7eb;
    text-align: left;
}

.r-code-editor .cm-editor {
    min-height: 22rem;
    direction: ltr;
    color: inherit;
    background: inherit;
    font-family: var(--r2-font-technical, monospace);
    font-size: 0.82rem;
}

.r-code-editor .cm-scroller {
    min-height: 22rem;
    overflow: auto;
}

.r-code-editor .cm-gutters {
    color: #9ca3af;
    border-inline-end: 1px solid #374151;
    background: #1f2937;
}

.r-code-editor .cm-content,
.r-code-editor .cm-line {
    direction: ltr;
    text-align: left;
}

.r-code-editor .cm-editor.cm-focused {
    outline: 3px solid rgb(124 58 237 / 20%);
}

.r-schema-panel {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.85rem;
    background: var(--surface-subtle);
}

.r-schema-panel > p {
    margin: 0.25rem 0 0.65rem;
    color: var(--muted);
    font-size: 0.7rem;
}

.js-r-source-schema {
    display: grid;
    gap: 0.5rem;
    max-height: 22rem;
    overflow: auto;
}

.r-schema-column {
    display: grid;
    gap: 0.12rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    padding: 0.55rem;
    background: var(--surface);
}

.r-schema-column strong {
    overflow-wrap: anywhere;
    font-size: 0.76rem;
}

.r-schema-column span,
.r-schema-column small {
    color: var(--muted);
    font-size: 0.68rem;
    overflow-wrap: anywhere;
}

.r-state-strip {
    justify-content: flex-start;
    margin-block-start: 0.75rem;
}

.r-state-strip span {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.55rem;
    color: var(--muted-strong);
    background: var(--surface-subtle);
    font-size: 0.68rem;
}

.r-state-strip .is-success {
    border-color: color-mix(in srgb, var(--success) 35%, var(--border));
    color: var(--success);
    background: var(--success-soft);
}

.r-state-strip .is-error {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
    color: var(--danger);
    background: var(--danger-soft);
}

.r-state-strip .is-warning,
.r-state-strip .is-loading {
    border-color: color-mix(in srgb, var(--warning) 35%, var(--border));
    color: var(--warning-strong, var(--text));
    background: var(--warning-soft);
}

.presentation-column-row {
    display: grid;
    grid-template-columns: minmax(9rem, 0.8fr) minmax(13rem, 1.2fr) minmax(12rem, 1fr) auto;
    gap: 0.75rem;
    align-items: end;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    padding: 0.7rem;
    background: var(--surface);
}

.presentation-column-row > label,
.presentation-column-name {
    display: grid;
    gap: 0.3rem;
    color: var(--muted-strong);
    font-size: 0.72rem;
    font-weight: 650;
}

.presentation-column-name > label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.presentation-order-actions {
    flex-wrap: nowrap;
}

.chart-dialog {
    width: min(76rem, calc(100vw - 2rem));
}

.chart-steps {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.chart-template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 0.75rem;
    margin-block: 1rem;
}

.chart-template-choice {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.8rem;
    background: var(--surface);
    cursor: pointer;
}

.chart-template-choice:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 9%, transparent);
}

.chart-template-choice > span {
    display: grid;
    gap: 0.2rem;
}

.chart-template-choice small {
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.7;
}

.chart-mapping-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 0.85rem;
    margin-block: 1rem;
}

.chart-mapping-field {
    display: grid;
    gap: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    padding: 0.7rem;
    background: var(--surface-subtle);
}

.chart-mapping-field > span {
    color: var(--text);
    font-weight: 700;
}

.chart-mapping-field > small {
    color: var(--muted);
    font-size: 0.7rem;
}

.chart-mapping-field select[multiple] {
    min-height: 8.5rem;
}

.chart-option-row {
    justify-content: flex-start;
    margin-block: 1rem;
}

.chart-option-row label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.55rem 0.7rem;
    background: var(--surface-subtle);
}

.chart-preview-canvas {
    min-height: 28rem;
    margin-block: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.75rem;
    background: var(--surface);
}

.chart-json-tools > summary {
    cursor: pointer;
    color: var(--muted-strong);
    font-weight: 700;
}

@media (max-width: 760px) {
    .r-editor-layout,
    .presentation-column-row {
        grid-template-columns: 1fr;
    }

    .chart-steps {
        grid-template-columns: 1fr;
    }
}

.auto-preview-option {
    width: fit-content;
    margin-block-start: 1rem;
}

.field-help {
    margin-block: 0.45rem 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.data-table-status {
    min-height: 2.2rem;
    margin-block: 0.65rem 0;
    border: 1px solid transparent;
    border-radius: 0.6rem;
    padding: 0.4rem 0.65rem;
    color: var(--muted);
    font-size: 0.78rem;
}

.data-table-status:empty {
    min-height: 0;
    margin-block: 0;
    padding-block: 0;
}

.data-table-status.is-loading,
.data-table-status.is-error,
.data-table-status.is-success {
    margin-block: 0.65rem 0;
}

.data-table-status.is-loading {
    border-color: var(--border);
    background: var(--surface-subtle);
}

.data-table-status.is-error {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
    color: var(--danger);
    background: var(--danger-soft);
}

.data-table-status.is-success {
    border-color: color-mix(in srgb, var(--success) 30%, var(--border));
    color: var(--success);
    background: var(--success-soft);
}

.data-table-step .query-result-card {
    margin-block: 0.8rem 1rem;
    padding: 1rem;
}

.data-table-step .query-result-card > p {
    margin-block-start: 0;
    color: var(--muted-strong);
    font-size: 0.8rem;
}

.js-table-preview {
    width: 100%;
    min-width: 30rem;
}

.table-schema-list {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.35rem 0.8rem;
    margin-block-end: 0;
    border-block-start: 1px solid var(--border);
    padding-block-start: 0.8rem;
    font-size: 0.75rem;
}

.table-schema-list dt {
    color: var(--muted-strong);
    font-weight: 700;
}

.table-schema-list dd {
    min-width: 0;
    margin: 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.table-presentation-columns {
    grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
}

.presentation-column-row {
    display: grid;
    grid-template-columns: minmax(9rem, 0.8fr) minmax(13rem, 1.2fr) minmax(12rem, 1fr) auto;
    align-items: end;
    gap: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    padding: 0.65rem;
    background: var(--surface);
}

.presentation-column-row label {
    display: grid;
    min-width: 0;
    align-items: start;
    gap: 0.45rem;
    overflow-wrap: anywhere;
    font-size: 0.76rem;
}

.presentation-column-row select {
    min-width: 0;
}

.table-history {
    margin-block-start: 1.25rem;
    border-block-start: 1px solid var(--border);
    padding-block-start: 1rem;
}

.table-history h4 {
    margin: 0 0 0.7rem;
    font-size: 0.9rem;
}

.table-history p,
.history-row {
    margin: 0;
    border-block-end: 1px solid var(--border);
    padding: 0.65rem 0;
    color: var(--muted);
    font-size: 0.74rem;
}

.history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.history-row .secondary-button {
    min-height: 2.2rem;
    flex: 0 0 auto;
    padding: 0.38rem 0.7rem;
}

.history-source {
    border-block-start: 1px solid var(--border);
    padding-block-start: 0.55rem;
}

.history-source > summary {
    cursor: pointer;
    color: var(--muted-strong);
    font-weight: 650;
}

.history-source pre {
    max-height: 18rem;
    margin-block-end: 0;
    overflow: auto;
    direction: ltr;
    border-radius: 0.55rem;
    padding: 0.7rem;
    color: #e5e7eb;
    background: #111827;
    text-align: left;
}

.r2-data-table {
    max-width: 100%;
    margin-block: 1rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface);
    cursor: pointer;
}

.r2-data-table table {
    width: 100%;
    border-collapse: collapse;
}

.r2-data-table caption {
    padding: 0.85rem;
    font-weight: 700;
    text-align: start;
}

.r2-data-table th,
.r2-data-table td {
    border-block-start: 1px solid var(--border);
    padding: 0.65rem 0.8rem;
    text-align: start;
    white-space: nowrap;
}

@media (max-width: 720px) {
    .data-table-dialog {
        width: calc(100vw - 0.75rem);
        max-height: calc(100dvh - 0.75rem);
        border-radius: 0.85rem;
    }

    .data-table-dialog-heading,
    .data-table-dialog-actions {
        padding-inline: 0.85rem;
    }

    .data-table-dialog form,
    .data-table-status,
    .data-table-steps {
        margin-inline: 0.85rem;
    }

    .data-table-dialog-actions {
        margin-inline: -0.85rem;
        flex-wrap: wrap;
    }

    .data-table-dialog-actions .button,
    .data-table-dialog-actions .secondary-button {
        flex: 1 1 auto;
    }

    .data-table-steps {
        grid-template-columns: 1fr;
    }

    .data-table-steps li {
        min-height: 2.4rem;
        padding-block: 0.45rem;
    }

    .data-table-field-grid,
    .controlled-query-grid,
    .dataset-choice-list,
    .column-choice-grid,
    .table-presentation-columns {
        grid-template-columns: 1fr;
    }

    .dataset-choice-list {
        max-height: 16rem;
    }

    .presentation-column-row {
        grid-template-columns: 1fr;
    }

    .history-row {
        align-items: stretch;
        flex-direction: column;
    }
}
