:root,
html[data-theme="light"] {
    --bg: #ebe7df;
    --bg-soft: #f6f3ec;
    --panel: rgba(255, 255, 255, 0.88);
    --panel-strong: rgba(255, 255, 255, 0.96);
    --panel-subtle: rgba(255, 255, 255, 0.68);
    --line: rgba(17, 37, 56, 0.14);
    --line-strong: rgba(17, 37, 56, 0.22);
    --text: #142433;
    --muted: #61707d;
    --brand: #0d7c8b;
    --brand-strong: #084c58;
    --warm: #d87a48;
    --danger: #b4413d;
    --input-bg: rgba(255, 255, 255, 0.92);
    --shadow: 0 12px 28px rgba(17, 37, 56, 0.10);
    --radius-lg: 10px;
    --radius-md: 8px;
    --radius-sm: 5px;
    --page-glow-a: rgba(13, 124, 139, 0.08);
    --page-glow-b: rgba(216, 122, 72, 0.08);
    --page-grad-a: #f2efe8;
    --page-grad-b: #edf2f1;
    --toast-bg: rgba(17, 37, 56, 0.94);
    --modal-backdrop: rgba(11, 20, 31, 0.52);
}

html[data-theme="dark"] {
    --bg: #141a1f;
    --bg-soft: #1b2329;
    --panel: rgba(24, 31, 37, 0.90);
    --panel-strong: rgba(28, 35, 41, 0.98);
    --panel-subtle: rgba(31, 39, 46, 0.78);
    --line: rgba(197, 213, 224, 0.14);
    --line-strong: rgba(197, 213, 224, 0.24);
    --text: #edf4f7;
    --muted: #9cafbc;
    --brand: #24a9b8;
    --brand-strong: #8de0e9;
    --warm: #e69a61;
    --danger: #de736d;
    --input-bg: rgba(19, 25, 30, 0.92);
    --shadow: 0 16px 34px rgba(0, 0, 0, 0.24);
    --page-glow-a: rgba(36, 169, 184, 0.07);
    --page-glow-b: rgba(230, 154, 97, 0.06);
    --page-grad-a: #11171b;
    --page-grad-b: #171f25;
    --toast-bg: rgba(8, 12, 16, 0.96);
    --modal-backdrop: rgba(0, 0, 0, 0.62);
}

body {
    min-height: 100vh;
    color: var(--text);
    font-family: "IBM Plex Sans", sans-serif;
    background:
        radial-gradient(circle at 12% 10%, var(--page-glow-a), transparent 20%),
        radial-gradient(circle at 84% 16%, var(--page-glow-b), transparent 18%),
        linear-gradient(160deg, var(--page-grad-a) 0%, var(--page-grad-b) 100%);
}

body.is-dragging,
body.is-panning {
    user-select: none;
}

body.has-modal {
    overflow: hidden;
}

.page-shell {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
}

.page-noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.04;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 22px 22px;
}

.screen {
    position: relative;
    z-index: 1;
}

.is-hidden {
    display: none !important;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--brand-strong);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    letter-spacing: -0.03em;
}

p {
    margin: 0;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-strong);
    color: var(--text);
    font-weight: 600;
    transition: transform 0.16s ease, border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

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

.button.primary {
    border-color: rgba(13, 124, 139, 0.16);
    background: var(--brand);
    color: #fff;
    box-shadow: none;
}

.button.ghost {
    background: var(--panel-subtle);
    border-color: var(--line);
}

.button.ghost.danger {
    color: var(--danger);
}

.button.ghost.is-active {
    border-color: rgba(13, 124, 139, 0.34);
    background: rgba(13, 124, 139, 0.08);
    color: var(--brand-strong);
}

.button.button-compact {
    min-height: 30px;
    padding: 5px 9px;
}

.button.wide {
    width: 100%;
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: rgba(13, 124, 139, 0.44);
    box-shadow: 0 0 0 3px rgba(13, 124, 139, 0.10);
}

.muted-text {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.stack-actions {
    display: grid;
    gap: 8px;
}

.compact-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.panel-copy {
    color: var(--muted);
    line-height: 1.4;
    font-size: 12px;
}

.toast-container {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 50;
    display: grid;
    gap: 10px;
}

.toast {
    min-width: 220px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--toast-bg);
    color: #fff;
    box-shadow: var(--shadow);
    transform: translateY(-6px);
    opacity: 0;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.is-visible {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    background: rgba(8, 76, 88, 0.96);
}

.toast-error {
    background: rgba(180, 65, 61, 0.96);
}

.theme-toggle {
    width: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-subtle);
    color: var(--text);
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-icon {
    width: 16px;
    height: 16px;
    display: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

.toolbar-note {
    color: var(--muted);
    font-size: 12px;
}

.action-grid {
    display: grid;
    gap: 6px;
}

.action-grid-office,
.action-grid-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.action-grid-office .button:first-child,
.action-grid-tools .button:first-child {
    grid-column: 1 / -1;
}

.shortcut-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.shortcut-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 22px;
    padding: 4px 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-subtle);
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
}

.keycap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    min-height: 18px;
    padding: 2px 4px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: var(--panel-strong);
    color: var(--text);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.zoom-level {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    min-height: 30px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-subtle);
    font-size: 13px;
    font-weight: 600;
}

.modal-root {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--modal-backdrop);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(100%, 440px);
    display: grid;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.modal-header {
    display: grid;
    gap: 4px;
}

.modal-text {
    color: var(--muted);
    line-height: 1.5;
    font-size: 14px;
}

.modal-alert {
    padding: 10px 12px;
    border: 1px solid rgba(180, 65, 61, 0.18);
    border-radius: var(--radius-sm);
    background: rgba(180, 65, 61, 0.10);
    color: var(--danger);
    font-size: 13px;
}

.modal-body,
.modal-form {
    display: grid;
    gap: 12px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-actions .button {
    flex: 1 1 0;
}

.selection-bulk {
    display: grid;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-subtle);
}

.editor-context-menu {
    position: fixed;
    z-index: 70;
    min-width: 190px;
    padding: 6px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.context-menu-section {
    display: grid;
    gap: 4px;
}

.context-menu-divider {
    height: 1px;
    margin: 6px 0;
    background: var(--line);
}

.context-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 30px;
    padding: 6px 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    text-align: left;
    font-size: 12px;
    font-weight: 600;
}

.context-menu-item:hover {
    background: rgba(13, 124, 139, 0.10);
}

.context-menu-item.is-danger {
    color: var(--danger);
}

@media (max-width: 720px) {
    .toast-container {
        right: 14px;
        left: 14px;
    }

    .toast {
        min-width: 0;
    }

    .compact-grid {
        grid-template-columns: 1fr;
    }
    
    .action-grid-office,
    .action-grid-tools {
        grid-template-columns: 1fr;
    }
}
