:root {
    --card-bg: var(--surface);
    --card-border: var(--border);
    --card-shadow: var(--shadow);
}

.editor-panel {
    max-width: 1200px;
    margin: 0 auto;
}

.app-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 25px;
    box-shadow: var(--card-shadow);
    overflow: visible;
}

.editor-card {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    border-radius: 25px 25px 0 0;
}

.card-header h3 {
    margin: 0 0 6px;
    font-size: 1.25rem;
}

.card-header p {
    margin: 0;
    color: var(--muted);
}

.chip {
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-weight: 700;
    color: var(--muted);
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    gap: 8px;
    position: sticky;
    top: 90px;
    z-index: 100;
}

.toolbar-break {
    flex-basis: 100%;
    height: 0;
    margin: 4px 0;
    border-bottom: 1px solid var(--border);
    opacity: 0.5;
}

.editor-toolbar.is-disabled .toolbar-group {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(0.5);
}

.toolbar-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    position: relative;
}

.toolbar-group:not(:last-child)::after {
    content: "";
    display: block;
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 8px;
}

.toolbar-group:last-of-type::after,
.toolbar-group:nth-last-child(2)::after {
    display: none;
}

.toolbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.expand-btn {
    position: absolute;
    top: 12px;
    right: 16px;
}

.tool-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    font-size: 1rem;
}

.tool-btn:hover {
    background: var(--surface);
    color: var(--text);
}

.tool-btn.is-active,
.tool-btn.active {
    background: rgba(106, 167, 255, 0.15);
    color: var(--primary);
    font-weight: bold;
}

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

.editor-toolbar .custom-select-wrapper::after {
    top: 14px;
    right: 12px;
}

.editor-toolbar .custom-select-wrapper:hover .select-selected {
    background-color: rgba(106, 167, 255, 0.05);
}

.color-input {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 2px solid var(--surface);
    outline: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.2s;
    margin: 0 2px;
}

.color-input:hover {
    transform: scale(1.1);
    outline-color: var(--primary);
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.modal-body .color-input {
    border-radius: 0 !important;
    overflow: visible !important;
}

.modal-body .color-input::-webkit-color-swatch {
    border-radius: 0 !important;
    border: 1px solid var(--border);
}

.modal-body .color-input::-moz-color-swatch {
    border-radius: 0 !important;
    border: 1px solid var(--border);
}

.color-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

.toolbar-group .color-control {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
}

.color-reset-btn {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    padding: 0;
}

.color-reset-btn:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--primary);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 24px;
}

.modal-overlay.is-hidden {
    display: none;
}

.modal {
    width: min(560px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.modal-footer {
    border-top: 1px solid var(--border);
    border-bottom: none;
    justify-content: flex-end;
    gap: 10px;
}

.modal-title {
    margin: 0;
    font-size: 1.05rem;
}

.modal-body {
    padding: 20px;
    display: grid;
    gap: 14px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-field {
    display: grid;
    gap: 8px;
}

.modal-label {
    font-size: 0.9rem;
    color: var(--muted);
    font-weight: 600;
}

.modal-input {
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 0 14px;
    font-size: 0.95rem;
}

.modal-textarea {
    min-height: 120px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 12px 14px;
    font-size: 0.95rem;
    resize: vertical;
}

.modal-hint {
    font-size: 0.85rem;
    color: var(--muted);
}

.dropzone {
    border: 1px dashed var(--border);
    border-radius: 14px;
    padding: 18px;
    text-align: center;
    color: var(--muted);
    background: var(--surface-2);
    display: grid;
    gap: 8px;
}

.dropzone.is-dragover {
    border-color: var(--primary);
    color: var(--text);
    background: rgba(106, 167, 255, 0.08);
}

.dropzone input[type="file"] {
    display: none;
}

.dropzone .ghost-btn {
    justify-self: center;
}

.icon-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

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

.editor-table td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    min-width: 48px;
    vertical-align: top;
}

.table-preview {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: var(--surface-2);
    overflow: auto;
}

.table-preview-shell {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    grid-template-rows: 34px minmax(0, 1fr) 34px;
    grid-template-areas:
        ". top ."
        "left center right"
        ". bottom .";
    gap: 8px 16px;
    align-items: center;
    justify-items: center;
}

.table-preview-stack {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.table-preview-stack.is-top {
    grid-area: top;
    flex-direction: row;
}

.table-preview-stack.is-bottom {
    grid-area: bottom;
    flex-direction: row;
}

.table-preview-stack.is-left {
    grid-area: left;
    flex-direction: column;
}

.table-preview-stack.is-right {
    grid-area: right;
    flex-direction: column;
}

.table-preview-shell .table-preview {
    grid-area: center;
    width: 100%;
}

.table-preview-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px dashed var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 700;
}

.table-preview-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(106, 167, 255, 0.12);
}

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

.table-preview-btn[data-action*="delete"],
.table-preview-btn[data-edit-delete] {
    border-style: solid;
    color: var(--muted);
}

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

.table-preview td {
    border: 1px dashed var(--border);
    padding: 6px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
}

.table-preview td.is-selected {
    background: rgba(106, 167, 255, 0.2);
    color: var(--text);
    border-color: var(--primary);
}

.table-preview td.is-merged {
    background: rgba(106, 167, 255, 0.08);
    border-style: solid;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    justify-content: center;
    flex-direction: column;
}

.table-action-buttons {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.table-action-buttons .ghost-btn:disabled,
.table-actions .ghost-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.table-action-buttons .ghost-btn:disabled:hover,
.table-actions .ghost-btn:disabled:hover {
    background: transparent;
    border-color: var(--border);
    transform: none;
}

.editor-card .ghost-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.table-edit-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.editor-code {
    position: relative;
    background: #101521;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 66px 14px 12px;
    margin: 12px 0 12px;
    overflow: auto;
    color: #e6edf3;
    font-size: 0.95rem;
}

.editor-code .code-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    background: #101521;
    padding-bottom: 8px;
    z-index: 1;
    position: absolute;
    width: calc(100% - 28px);
    top: 16px;
}

.editor-code .code-lang {
    font-size: 0.75rem;
    font-weight: 700;
    color: #7f8ea3;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.editor-code .code-copy {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: #e6edf3;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
}

.editor-code code {
    display: block;
    font-family: "Consolas", "Courier New", monospace;
    white-space: pre;
}

.editor-code .token-keyword {
    color: #7dd3fc;
}

.editor-code .token-string {
    color: #fda4af;
}

.editor-code .token-comment {
    color: #94a3b8;
    font-style: italic;
}

.editor-code .token-tag {
    color: #a78bfa;
}

.editor-code .token-attr {
    color: #fcd34d;
}

body.editor-expanded .container {
    max-width: 100%;
}

body.editor-expanded .editor-panel {
    max-width: none;
}

.mode-toggle {
    display: inline-flex;
    background: var(--surface-2);
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--border);
    gap: 4px;
}

.mode-btn {
    border: none;
    background: transparent;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--muted);
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.mode-btn.is-active {
    background: var(--surface);
    color: var(--text);
}

.mode-btn:hover {
    color: var(--text);
}

.editor-workspace {
    padding: 24px;
    background: transparent;
    min-height: 360px;
    border-bottom: 1px dashed var(--border);
    display: flex;
}

.visual-editor,
.source-editor {
    width: 100%;
    min-height: 360px;
    padding: 0;
    outline: none;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.3rem;
    line-height: 1.7;
    resize: vertical;
    font-family: inherit;
}

.source-editor {
    font-family: "Consolas", "Monaco", "Courier New", monospace;
}

.editor-placeholder {
    color: var(--muted);
    font-weight: 300;
}

.visual-editor p {
    margin-bottom: 1em;
}

.visual-editor h1,
.visual-editor h2,
.visual-editor h3 {
    margin-bottom: 0.5em;
    margin-top: 1em;
}

.visual-editor ul,
.visual-editor ol {
    margin-left: 1.5em;
    margin-bottom: 1em;
}

.visual-editor blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 1em;
    margin-left: 0;
    color: var(--muted);
}

.editor-footnotes {
    margin-top: 28px;
    padding-top: 12px;
    color: var(--muted);
}

.editor-footnotes .footnote-list {
    margin: 12px 0 0 18px;
    display: grid;
    gap: 8px;
}

.editor-footnotes .footnote-item {
    font-size: 0.95rem;
    line-height: 1.6;
}

.footnote-ref a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.footnote-backref {
    margin-left: 6px;
    font-size: 0.85rem;
    color: var(--muted);
    text-decoration: none;
}

.visual-editor a {
    color: var(--primary);
    text-decoration: underline;
}

.visual-editor img {
    max-width: 100%;
    height: auto;
}

.editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px 20px;
    background: var(--surface);
    border-radius: 0 0 25px 25px;
}

.editor-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--muted);
    font-size: 0.9rem;
    flex-wrap: wrap;
}


.action-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

@media (max-width: 840px) {
    .editor-toolbar {
        align-items: stretch;
    }

    .toolbar-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
    }

    .editor-footer {
        flex-direction: column;
        align-items: flex-start;
    }
}