:root {
    --se-bg-color: #f0f2f5;
    --se-toolbar-bg: #ffffff;
    --se-toolbar-border: #e0e0e0;
    --se-icon-color: #444;
    --se-icon-hover: #e8f0fe;
    --se-icon-active: #d2e3fc;
    --se-border-radius: 6px;
    --se-accent-color: #1a73e8;
}

/* Main Container */
.se-main-container {
    display: flex;
    flex-direction: column;
    border: 1px solid #ccc;
    background: var(--se-bg-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    height: 100%;
}

/* Full Screen Mode */
.se-main-container.se-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border: none;
    border-radius: 0;
}

/* Toolbar */
.se-toolbar-container {
    background: var(--se-toolbar-bg);
    border-bottom: 1px solid var(--se-toolbar-border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    z-index: 100;
    position: sticky;
    top: 0;
}

.se-toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding-right: 8px;
    border-right: 1px solid #eee;
    margin-right: 8px;
}

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

/* Buttons */
.se-btn-tool {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--se-border-radius);
    color: var(--se-icon-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.se-btn-tool:hover {
    background-color: var(--se-icon-hover);
    color: var(--se-accent-color);
}

.se-btn-tool.se-active,
.se-btn-tool:active {
    background-color: var(--se-icon-active);
    color: var(--se-accent-color);
}

.se-btn-tool i {
    font-size: 20px;
}

/* Custom Dropdown */
.se-dropdown {
    position: relative;
    display: inline-block;
}

.se-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 160px;
    max-height: 250px;
    overflow-y: auto;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: var(--se-border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    padding: 5px 0;
}

.se-dropdown-menu.show {
    display: block;
}

.se-dropdown-item {
    display: block;
    padding: 8px 16px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    font-family: 'Inter', sans-serif;
}

.se-dropdown-item:hover {
    background-color: #f5f5f5;
    color: var(--se-accent-color);
}

/* Scrollbar for dropdown */
.se-dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.se-dropdown-menu::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Adjust button inside dropdown toggle */
.se-dropdown-toggle {
    padding-right: 4px;
    /* Space for arrow */
}


/* Editor Area - wrapper */
.se-editor-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    background: #e6e6e6;
    /* Contrast background */
    scrollbar-width: thin;
}

/* The actual editable "page" */
.se-page-content {
    background: white;
    padding: 20px;
    outline: none;
    font-family: 'Calibri', sans-serif;
    font-size: 12pt;
    line-height: 1.5;
    box-sizing: border-box;
    width: 100%;
    /* Fluid by default */
    min-height: 200px;
}

/* Document Mode (A4 style default) */
.se-page-content.se-document-mode {
    width: 210mm;
    min-height: 297mm;
    padding: 25mm;
    margin: 0 auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
    transition: width 0.3s, min-height 0.3s, padding 0.3s;
}

/* Page Sizes */
.se-page-size-a4 {
    width: 210mm;
    min-height: 297mm;
}

.se-page-size-a5 {
    width: 148mm;
    min-height: 210mm;
}

.se-page-size-letter {
    width: 216mm;
    min-height: 279mm;
}

.se-page-size-legal {
    width: 216mm;
    min-height: 356mm;
}

/* Orientation */
.se-page-orientation-landscape.se-page-size-a4 {
    width: 297mm;
    min-height: 210mm;
}

.se-page-orientation-landscape.se-page-size-a5 {
    width: 210mm;
    min-height: 148mm;
}

.se-page-orientation-landscape.se-page-size-letter {
    width: 279mm;
    min-height: 216mm;
}

.se-page-orientation-landscape.se-page-size-legal {
    width: 356mm;
    min-height: 216mm;
}

/* Margins */
.se-page-margins-normal {
    padding: 25mm;
}

.se-page-margins-narrow {
    padding: 12.7mm;
}

.se-page-margins-wide {
    padding: 50mm;
}

/* Print Media Query */
@media print {
    body * {
        visibility: hidden;
    }

    .se-page-content.se-document-mode,
    .se-page-content.se-document-mode * {
        visibility: visible;
    }

    .se-page-content.se-document-mode {
        position: absolute;
        left: 0;
        top: 0;
        margin: 0;
        padding: 0;
        /* Reset padding for print, browser handles margins mostly, or we force it? */
        /* Actually, for print we want to keep padding as 'margins' on the sheet if we are simulating paper */
        box-shadow: none;
        border: none;
        width: 100%;
        min-height: 100%;
    }

    @page {
        size: auto;
        /* Let browser handle or override in specific classes */
        margin: 0;
    }

    /* Force size on print if supported */
    .se-page-size-a4 {
        size: A4 portrait;
    }

    .se-page-orientation-landscape.se-page-size-a4 {
        size: A4 landscape;
    }

    .se-page-size-a5 {
        size: A5 portrait;
    }

    .se-page-orientation-landscape.se-page-size-a5 {
        size: A5 landscape;
    }

    .se-page-size-letter {
        size: Letter portrait;
    }

    .se-page-orientation-landscape.se-page-size-letter {
        size: Letter landscape;
    }

    .se-page-size-legal {
        size: Legal portrait;
    }

    .se-page-orientation-landscape.se-page-size-legal {
        size: Legal landscape;
    }
}

/* Content Styles inside Page */
.se-page-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

.se-page-content table,
.se-page-content th,
.se-page-content td {
    border: 1px solid black;
}

.se-page-content td,
.se-page-content th {
    padding: 8px;
    min-width: 20px;
}

.se-page-content a {
    color: var(--se-accent-color);
    text-decoration: underline;
    cursor: pointer;
}

.se-page-content img {
    max-width: 100%;
    height: auto;
}

/* Source View Textarea */
.se-source-view {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    padding: 20px;
    padding-top: 50px; /* Space for toolbar */
    border: 1px solid #ddd;
    resize: none;
    outline: none;
    min-height: 200px;
}

/* Source View Toolbar */
.se-source-toolbar {
    position: absolute;
    top: 10px;
    right: 25px; /* Scrollbar space */
    display: flex;
    gap: 8px;
    z-index: 100;
}

.se-btn-source-action {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    font-family: sans-serif;
    color: #333;
    display: flex;
    align-items: center;
    gap: 5px;
}

.se-btn-source-action:hover {
    background: #e0e0e0;
    border-color: #bbb;
}

/* Responsive */
@media (max-width: 850px) {
    .se-page-content {
        width: 100%;
        margin: 0;
        box-shadow: none;
    }

    .se-editor-wrapper {
        padding: 10px;
    }
}

@media (max-width: 600px) {
    .se-toolbar-container {
        padding: 4px 8px;
        gap: 4px;
    }

    .se-toolbar-group {
        border-right: none;
        padding-right: 2px;
        margin-right: 2px;
    }

    .se-btn-tool {
        padding: 4px;
    }
}

/* Active Button State */
.se-btn-tool.se-active {
    background-color: #e8f0fe;
    color: #1a73e8;
    border-color: #d2e3fc;
}

/* Page Break Visualization */
.se-page-break,
hr.se-page-break {
    border: 0;
    border-top: 1px dashed #999;
    height: 1px;
    margin: 20px 0;
    position: relative;
    page-break-after: always;
    /* For printing */
}

.se-page-break::after {
    content: "Page Break";
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    color: #999;
    padding: 0 10px;
    font-size: 12px;
    text-transform: uppercase;
}

/* Document Mode Page Break */
.se-document-mode .se-page-break {
    margin: 30px -40px;
    /* Extend to edges in doc mode */
}

/* Unified Popup */
.se-popup {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 8px;
    /* Compact padding */
    z-index: 10000;
    border-radius: 4px;
    font-family: sans-serif;
    font-size: 13px;
    width: auto; /* Allow auto width for toolbar */
    min-width: 200px;
    /* Compact width */
    display: none;
}

.se-popup.visible {
    display: block;
}

.se-popup input[type="text"],
.se-popup input[type="number"] {
    width: 100%;
    padding: 4px 6px;
    /* Compact padding */
    margin-bottom: 6px;
    /* Compact margin */
    border: 1px solid #ccc;
    border-radius: 3px;
    box-sizing: border-box;
    font-size: 13px;
}

.se-popup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.se-btn-primary,
.se-btn-danger,
.se-btn-secondary {
    padding: 6px 12px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.se-btn-primary {
    background: #007bff;
    color: white;
}

.se-btn-primary:hover {
    background: #0056b3;
}

.se-btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.se-btn-secondary:hover {
    background: #e0e0e0;
}

.se-btn-danger {
    background: #dc3545;
    color: white;
}

.se-btn-danger:hover {
    background: #bd2130;
}

.se-popup-tools {
    display: flex;
    gap: 8px;
    align-items: center;
}

.se-popup-preview {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #007bff;
    text-decoration: underline;
    margin-right: 8px;
    max-width: 180px;
}

/* Selection Markers (v3 Sticky Anchors) */
#se-start-marker,
#se-end-marker {
    display: inline-block !important;
    width: 0 !important;
    height: 0 !important;
    line-height: 0 !important;
    overflow: hidden !important;
    vertical-align: middle !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Visual Selection Guide */
#se-visual-guide,
.se-visual-guide-part {
    background-color: #b3d4fc !important;
    /* Standard selection blue */
    color: inherit !important;
    text-decoration: inherit !important;
    display: inline;
}

/* Table Hover Effects */
.se-page-content table.se-table-hover {
    outline: 2px solid #ffca28; /* Yellow outline */
    position: relative;
    cursor: default;
}

/* Paragraph Insertion Handles */
.se-table-handle {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 101;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    color: #444;
}

.se-table-handle:hover {
    background: #f0f0f0;
    color: #1a73e8;
}

.se-table-handle-top {
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
}

.se-table-handle-bottom {
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
}

.se-table-handle-menu {
    top: -12px;
    left: -12px;
}

/* Enhanced Popup Menus */
.se-popup-menu-list {
    display: flex;
    flex-direction: column;
    width: 200px;
}

.se-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #333;
    border-radius: 3px;
}

.se-menu-item:hover {
    background-color: #f5f5f5;
    color: #1a73e8;
}

.se-menu-item svg {
    margin-right: 8px;
    flex-shrink: 0;
}

.se-menu-arrow {
    margin-left: auto;
    color: #999;
}

/* Horizontal Table Toolbar (New) */
.se-table-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: #fff;
    border-radius: 4px;
    /* width: auto;  Let it grow */
    width: max-content; 
}

.se-toolbar-group-btn {
    display: flex;
    align-items: center;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
    color: #555;
    transition: background 0.2s;
}

.se-toolbar-group-btn:hover {
    background-color: #f0f0f0;
    color: #1a73e8;
}

.se-toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
    color: #555;
    transition: background 0.2s;
}

.se-toolbar-btn:hover {
    background-color: #f0f0f0;
    color: #1a73e8;
}

.se-toolbar-arrow {
    font-size: 10px;
    margin-left: 4px;
    color: #999;
}

.se-toolbar-separator {
    width: 1px;
    height: 20px;
    background: #eee;
    margin: 0 4px;
}

.se-menu-back {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    margin-bottom: 4px;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
}

.se-menu-back:hover {
    background-color: #f5f5f5;
    color: #333;
}

.se-menu-divider {
    height: 1px;
    background: #eee;
    margin: 4px 0;
}

/* Properties Form Grid */
.se-props-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.se-props-row {
    grid-column: span 2;
}

.se-props-label {
    font-size: 11px;
    font-weight: 600;
    color: #666;
    margin-bottom: 2px;
    display: block;
}

/* Color Picker Input */
input[type="color"].se-color-input {
    padding: 0;
    border: none;
    height: 30px;
    width: 100%;
    cursor: pointer;
    background: none;
}

/* Toggle Switch (iOS style) */
.se-toggle-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
}

.se-toggle-label {
    font-size: 13px;
    color: #333;
}

/* The Switch Container */
.se-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

/* Hide default HTML checkbox */
.se-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The Slider */
.se-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 18px;
}

.se-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .se-slider {
  background-color: #4CAF50; /* Green */
}

input:focus + .se-slider {
  box-shadow: 0 0 1px #4CAF50;
}

input:checked + .se-slider:before {
  transform: translateX(14px);
}

/* Table Caption */
.se-table-caption {
    caption-side: top;
    text-align: center;
    padding: 8px;
    font-weight: bold;
    color: #333;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-radius: 4px;
    margin-bottom: 5px;
    border: 1px solid #ddd;
}