:root {
    --as-primary: #4facfe;
    --as-secondary: #00f2fe;
    --as-bg: #121214;
    --as-toolbar-bg: rgba(18, 18, 20, 0.8);
    --as-border: rgba(255, 255, 255, 0.1);
    --as-text: #e0e0e0;
    --as-text-muted: #888;
    --as-accent-glow: rgba(79, 172, 254, 0.3);
    --as-btn-hover: rgba(255, 255, 255, 0.08);
}

.as-editor-container.as-light-mode {
    --as-bg: #ffffff;
    --as-toolbar-bg: rgba(248, 249, 250, 0.8);
    --as-border: rgba(0, 0, 0, 0.1);
    --as-text: #333333;
    --as-accent-glow: rgba(79, 172, 254, 0.15);
    --as-btn-hover: rgba(0, 0, 0, 0.05);
}

.as-editor-container {
    display: flex;
    flex-direction: column;
    border-radius: 14px;
    background: var(--as-bg);
    color: var(--as-text);
    transition: background 0.3s, color 0.3s;
    border: 1px solid var(--as-border);
    position: relative;
    overflow: hidden;
    resize: both;
    min-height: 300px;
    min-width: 400px;
}

/* Toolbar */
.as-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px;
    background: var(--as-toolbar-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--as-border);
    position: sticky;
    top: 0;
    z-index: 1000;
    flex-shrink: 0;
}

.as-toolbar-group {
    display: flex;
    gap: 1px;
    padding: 0 2px;
    border-right: 1px solid var(--as-border);
}

.as-toolbar-group:last-child {
    border-right: none;
}

.as-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--as-text);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.as-btn:hover {
    background: var(--as-btn-hover);
    color: var(--as-primary);
}

.as-btn.active {
    background: rgba(79, 172, 254, 0.15);
    color: var(--as-primary);
    box-shadow: inset 0 0 0 1px rgba(79, 172, 254, 0.2);
}

.as-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Font Controls Styling */
.as-font-dropdown-wrapper {
    position: relative;
    display: inline-block;
    margin-right: 4px;
}

.as-font-display {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--as-border);
    color: var(--as-text);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    min-width: 100px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.as-font-display::after {
    content: '▼';
    font-size: 8px;
    margin-left: 10px;
    opacity: 0.5;
}

.as-font-display:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--as-primary);
}

.as-font-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 200px;
    background: var(--as-bg);
    border: 1px solid var(--as-border);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    backdrop-filter: blur(20px);
}

.as-modal {
    position: absolute;
    background: var(--as-toolbar-bg);
    border: 1px solid var(--as-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    backdrop-filter: blur(15px);
    z-index: 5000;
    animation: asFadeIn 0.2s ease-out;
    display: none;
}

.as-modal.show {
    display: block !important;
}

.as-font-dropdown.show {
    display: flex;
}

.as-font-search {
    background: rgba(255, 255, 255, 0.03);
    border: none;
    border-bottom: 1px solid var(--as-border);
    color: var(--as-text);
    padding: 10px;
    font-size: 13px;
    outline: none;
}

.as-font-list-items {
    max-height: 250px;
    overflow-y: auto;
}

.as-font-item {
    padding: 10px 15px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.as-color-picker-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 220px;
    background: var(--as-bg);
    border: 1px solid var(--as-border);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    z-index: 2000;
    backdrop-filter: blur(20px);
}

.as-color-picker-dropdown.show {
    display: flex;
}

.as-color-section-title {
    font-size: 11px;
    color: var(--as-text-muted);
    margin: 8px 0 4px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.as-color-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
}

.as-color-cell {
    width: 18px;
    height: 18px;
    border: 1px solid rgba(255,255,255,0.1);
    cursor: pointer;
    border-radius: 2px;
    transition: transform 0.1s;
}

.as-color-cell:hover {
    transform: scale(1.2);
    border-color: #fff;
    z-index: 1;
}

.as-color-row {
    display: flex;
    gap: 2px;
    margin-bottom: 4px;
}

.as-color-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--as-border);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.as-color-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    font-size: 12px;
    color: var(--as-text);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

.as-color-action-btn:hover {
    background: var(--as-btn-hover);
}

.as-color-action-btn svg {
    width: 14px;
    height: 14px;
}

.as-color-picker-trigger {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.as-color-bar {
    width: 16px;
    height: 3px;
    background: red;
    margin-top: -4px;
    border-radius: 1px;
}

.as-highlighter-bar {
    background: yellow;
}

.as-spacing-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 250px;
    background: var(--as-bg);
    border: 1px solid var(--as-border);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    z-index: 2000;
    backdrop-filter: blur(20px);
    padding: 5px 0;
}

.as-spacing-dropdown.show {
    display: flex;
}

.as-spacing-item {
    padding: 8px 15px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--as-text);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.as-spacing-item:hover {
    background: var(--as-btn-hover);
}

.as-spacing-divider {
    height: 1px;
    background: var(--as-border);
    margin: 5px 0;
}

/* Table Picker Grid */
.as-table-picker {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    background: var(--as-bg);
    border: 1px solid var(--as-border);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    z-index: 2000;
    backdrop-filter: blur(20px);
}

.as-table-picker.show {
    display: flex;
}

.as-table-grid-title {
    font-size: 12px;
    margin-bottom: 8px;
    color: var(--as-text);
    font-weight: 600;
    text-align: center;
}

.as-table-grid-container {
    display: grid;
    grid-template-columns: repeat(10, 18px);
    grid-template-rows: repeat(10, 18px);
    gap: 2px;
    padding: 2px;
}

.as-table-grid-cell {
    width: 18px;
    height: 18px;
    border: 1px solid var(--as-border);
    cursor: pointer;
    transition: all 0.1s;
}

.as-table-grid-cell.highlighted {
    background: rgba(79, 172, 254, 0.4);
    border-color: var(--as-primary);
}

.as-table-picker-footer {
    margin-top: 10px;
    padding-top: 5px;
    border-top: 1px solid var(--as-border);
}

.as-size-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--as-border);
    color: var(--as-text);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 50px;
    margin-right: 2px;
}

.as-size-select:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--as-primary);
}

.as-size-select:focus {
    border-color: var(--as-primary);
    box-shadow: 0 0 0 2px var(--as-accent-glow);
    background: rgba(0, 0, 0, 0.3);
}

.as-font-select option, .as-size-select option {
    background: #1a1a1e;
    color: #fff;
}

.as-font-btn svg {
    width: 20px;
    height: 20px;
}

/* Tooltip (Simple pure CSS) */
.as-btn::after {
    content: attr(data-title);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: #000;
    color: #fff;
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.2s ease;
}

.as-btn:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Editable Area */
.as-content {
    flex: 1;
    padding: 20px;
    min-height: 300px;
    outline: none;
    line-height: 1.6;
    overflow-y: auto;
    position: relative;
    color: var(--as-text);
}

.as-editor-footer {
    padding: 6px 12px;
    border-top: 1px solid var(--as-border);
    background: var(--as-toolbar-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--as-text-muted);
    flex-shrink: 0;
}

.as-theme-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--as-border);
    transition: all 0.2s;
    color: var(--as-text);
}

.as-light-mode .as-theme-toggle {
    background: rgba(0, 0, 0, 0.05);
}

.as-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--as-primary);
}

.as-theme-toggle svg {
    width: 14px;
    height: 14px;
}

.as-content p, .as-content div, .as-content li {
    margin: 0;
    padding: 0;
}

.as-content h1, .as-content h2, .as-content h3 {
    margin-top: 10px;
    margin-bottom: 5px;
    line-height: 1.2;
    color: var(--as-primary);
}

.as-content b, .as-content strong {
    color: inherit;
    font-weight: 700;
}

/* Table normalization — equal padding, no browser quirks */
.as-content table {
    border-collapse: collapse !important;
    table-layout: fixed;
}

.as-content th,
.as-content td {
    padding: 6px 8px !important;
    box-sizing: border-box !important;
    text-align: left;
    vertical-align: top;
    border: 1px solid #555 !important;
    min-width: 60px;
}

.as-content td:hover {
    background: rgba(79, 172, 254, 0.04);
}

.as-cell-selected {
    background: rgba(79, 172, 254, 0.2) !important;
    outline: 2px solid #4facfe !important;
}

/* Placeholder */
.as-content:empty:before {
    content: attr(data-placeholder);
    color: var(--as-text-muted);
    font-style: italic;
    pointer-events: none;
}

/* Scrollbar styling */
.as-content::-webkit-scrollbar {
    width: 6px;
}

.as-content::-webkit-scrollbar-track {
    background: transparent;
}

.as-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.as-content::-webkit-scrollbar-thumb:hover {
    background: var(--as-primary);
}

/* Tables */
.as-content table {
    width: auto;
    min-width: 100px;
    max-width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    border: 1px solid var(--as-border);
    table-layout: auto;
}

.as-content th, .as-content td {
    border: 1px solid var(--as-border);
    padding: 2px 8px;
    text-align: left;
    min-width: 20px;
    position: relative;
    word-break: break-word;
    line-height: 1.2;
}

.as-content th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

.as-content tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.as-light-mode .as-content tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

/* Table Quick Insert UI */
.as-table-insert-handler {
    position: absolute;
    z-index: 2500;
    pointer-events: none;
    display: none;
}

.as-table-insert-handler.show {
    display: block;
}

.as-table-insert-btn {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #4facfe;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.5);
    pointer-events: auto;
    transition: transform 0.1s;
}

.as-table-insert-btn:hover {
    transform: scale(1.2);
}

.as-table-insert-line {
    position: absolute;
    background: #4facfe;
    opacity: 0.5;
}

.as-table-insert-handler.row .as-table-insert-line {
    height: 2px;
    width: 100%;
}

.as-table-insert-handler.col .as-table-insert-line {
    width: 2px;
    height: 100%;
}

/* Global Table Resize Handle */
.as-table-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 1px solid #4facfe;
    z-index: 2600;
    cursor: nwse-resize;
    display: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.as-table-resize-handle.show {
    display: block;
}

.as-table-resize-handle:hover {
    background: #4facfe;
}

/* Table Move Handle */
.as-table-move-handle {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #fff;
    border: 1px solid #4facfe;
    border-radius: 4px;
    z-index: 2600;
    cursor: move;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    color: #4facfe;
}

.as-table-move-handle.show {
    display: flex;
}

.as-table-move-handle:hover {
    background: #4facfe;
    color: #fff;
}

/* Compact Image Dropdown */
.as-image-dropdown {
    width: 220px;
    padding: 10px;
}

.as-drop-zone {
    border: 1px dashed var(--as-border);
    border-radius: 6px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.as-drop-zone i {
    font-size: 18px;
    color: #4facfe;
    display: block;
    margin-bottom: 4px;
}

.as-drop-zone p {
    font-size: 11px;
    color: var(--as-text);
    margin: 0;
    opacity: 0.7;
}

.as-image-url-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--as-border);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--as-text);
    font-size: 12px;
    margin-bottom: 8px;
    outline: none;
}

.as-image-url-input:focus {
    border-color: #4facfe;
}

.as-image-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.as-image-btn {
    padding: 6px 15px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    border: none;
    transition: 0.2s;
}

.as-image-btn.cancel {
    background: transparent;
    color: var(--as-text);
    opacity: 0.6;
}

.as-image-btn.insert {
    background: #4facfe;
    color: #fff;
}

.as-image-btn:hover {
    opacity: 0.8;
}

.as-modal {
    position: absolute;
    background: var(--as-toolbar-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--as-border);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    z-index: 100;
    display: none;
}

/* Image Interactions */
.as-image-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
    user-select: none;
    cursor: move;
    margin: 5px;
}

.as-image-wrapper img {
    border: 2px solid transparent;
    transition: border-color 0.2s;
    pointer-events: none;
}

.as-image-wrapper.selected img {
    border-color: #4facfe;
}

.as-image-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #4facfe;
    border-radius: 50%;
    z-index: 5100;
    display: none;
}

.as-image-wrapper.selected .as-image-handle {
    display: block;
}

.as-image-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.as-image-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.as-image-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.as-image-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.as-image-handle.n { top: -5px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.as-image-handle.s { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.as-image-handle.e { top: 50%; right: -5px; transform: translateY(-50%); cursor: e-resize; }
.as-image-handle.w { top: 50%; left: -5px; transform: translateY(-50%); cursor: w-resize; }

.as-image-rotate-handle {
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 24px;
    background: #fff;
    border: 2px solid #4facfe;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    z-index: 5100;
}

.as-image-rotate-handle::before {
    content: '';
    position: absolute;
    bottom: -11px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 10px;
    background: #4facfe;
}

.as-image-wrapper.selected .as-image-rotate-handle {
    display: flex;
}

.as-image-layout-btn {
    position: absolute;
    top: 5px;
    right: -35px;
    width: 30px;
    height: 30px;
    background: var(--as-toolbar-bg);
    border: 1px solid var(--as-border);
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5100;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.as-image-wrapper.selected .as-image-layout-btn {
    display: flex;
}

.as-image-transparency-btn {
    position: absolute;
    top: 40px;
    right: -35px;
    width: 30px;
    height: 30px;
    background: var(--as-toolbar-bg);
    border: 1px solid var(--as-border);
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5100;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.as-image-wrapper.selected .as-image-transparency-btn {
    display: flex;
}

.as-image-layout-btn svg, .as-image-transparency-btn svg {
    width: 18px;
    height: 18px;
    fill: #4facfe;
}

/* Layout & Transparency Options Dropdown */
.as-layout-options-dropdown, .as-transparency-dropdown {
    position: absolute;
    background: var(--as-toolbar-bg);
    border: 1px solid var(--as-border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35);
    backdrop-filter: blur(15px);
    z-index: 9999;
    padding: 8px;
    animation: asFadeIn 0.15s ease-out;
}
.as-img-inline { display: inline-block; float: none; vertical-align: middle; }
.as-img-left   { float: left;  margin: 10px 20px 10px 0; }
.as-img-right  { float: right; margin: 10px 0 10px 20px; }
.as-img-block  { display: block; margin: 20px auto; }
.as-img-front  { position: absolute; z-index: 500; cursor: move; float: none; }

/* Layout Options Modal */
.as-layout-options {
    width: 180px;
    padding: 10px;
}

.as-layout-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: 0.2s;
    color: var(--as-text);
}

.as-layout-option:hover {
    background: rgba(79, 172, 254, 0.1);
}

.as-layout-option svg {
    width: 18px;
    height: 18px;
    fill: #4facfe;
}

/* Transparency Dropdown Specifics */
.as-transparency-dropdown {
    width: 150px;
    padding: 12px;
}

.as-transparency-label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--as-text-muted);
    margin-bottom: 8px;
}

.as-transparency-slider {
    width: 100%;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    height: 4px;
    border-radius: 2px;
    outline: none;
}

.as-transparency-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: #4facfe;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(79, 172, 254, 0.5);
}
