/**
 * Table Display Styles
 * For blog post table insertion feature
 * IMPORTANT: Spacing must match gallery/callout spacing (27px = 1.6875rem)
 */

/* ============================================
   CSS CUSTOM PROPERTIES (VARIABLES)
   ============================================ */
:root {
    /* Color palette - from CLAUDE.md design system */
    --table-color-brand-brown: #5C4033;
    --table-color-brand-brown-dark: #4A3429;
    --table-color-accent-pink: #D88C9A;
    --table-color-text-primary: rgba(44, 44, 44, 0.95);
    --table-color-text-secondary: rgba(44, 44, 44, 0.85);
    --table-color-text-muted: rgba(44, 44, 44, 0.75);
    --table-color-text-light: rgba(44, 44, 44, 0.6);
    --table-color-text-lighter: rgba(44, 44, 44, 0.5);
    --table-color-white: #FFFFFF;
    --table-color-delete: #dc2626;

    /* Border colors */
    --table-border-primary: rgba(92, 64, 51, 0.3);
    --table-border-light: rgba(92, 64, 51, 0.2);
    --table-border-lighter: rgba(92, 64, 51, 0.15);

    /* Background colors */
    --table-bg-white: rgba(255, 255, 255, 0.95);
    --table-bg-header: rgba(92, 64, 51, 0.1);
    --table-bg-hover: rgba(92, 64, 51, 0.1);
    --table-bg-delete-hover: rgba(220, 38, 38, 0.1);
    --table-bg-striped: rgba(216, 140, 154, 0.05);
    --table-bg-warm: rgba(245, 241, 237, 0.3);
    --table-bg-light: rgba(250, 250, 250, 0.5);
    --table-bg-overlay: rgba(0, 0, 0, 0.5);

    /* Spacing values */
    --table-spacing-xs: 0.25rem;
    --table-spacing-sm: 0.375rem;
    --table-spacing-md: 0.5rem;
    --table-spacing-lg: 0.75rem;
    --table-spacing-xl: 1rem;
    --table-spacing-2xl: 1.5rem;
    --table-spacing-3xl: 2rem;
    --table-spacing-match-content: 1.6875rem; /* 27px - matches gallery/callout */

    /* Border radius */
    --table-radius-sm: 4px;
    --table-radius-md: 6px;
    --table-radius-lg: 8px;
    --table-radius-xl: 12px;

    /* Transitions */
    --table-transition-fast: 0.2s;

    /* Font families */
    --table-font-serif: 'Playfair Display', serif;
    --table-font-sans: 'Inter', sans-serif;

    /* Z-index */
    --table-z-modal: 10000;
}

/* ============================================
   VIEW VISIBILITY CONTROLS
   Following callout pattern: show editor view in admin, published view on blog
   ============================================ */

/* By default in admin editor: show editor view, hide published view */
.quill-table-block .table-editor-view {
    display: block;
}

.quill-table-block .table-published-view {
    display: none;
}

/* On published blog pages: hide editor view, show published view */
.post-content .quill-table-block .table-editor-view,
.prose .quill-table-block .table-editor-view,
article .quill-table-block .table-editor-view {
    display: none;
}

.post-content .quill-table-block .table-published-view,
.prose .quill-table-block .table-published-view,
article .quill-table-block .table-published-view {
    display: block;
}

/* ============================================
   EDITOR TABLE PREVIEW STYLES
   ============================================ */

.quill-table-block {
    margin: var(--table-spacing-xl) 0;
    padding: var(--table-spacing-xl);
    border: 2px solid var(--table-border-light);
    border-radius: var(--table-radius-lg);
    background: var(--table-bg-white);
    position: relative;
}

.quill-table-block .table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--table-spacing-lg);
    padding-bottom: var(--table-spacing-md);
    border-bottom: 1px solid var(--table-border-lighter);
}

.quill-table-block .table-icon {
    font-size: 1.25rem;
    margin-right: var(--table-spacing-md);
}

.quill-table-block .table-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--table-spacing-md);
}

.quill-table-block .table-size {
    font-size: 0.9rem;
    color: var(--table-color-text-muted);
    font-family: var(--table-font-sans);
}

.quill-table-block .table-controls {
    display: flex;
    gap: var(--table-spacing-md);
}

.quill-table-block .table-edit-btn,
.quill-table-block .table-delete-btn {
    padding: var(--table-spacing-sm) var(--table-spacing-lg);
    border: 1px solid var(--table-border-primary);
    background: var(--table-color-white);
    border-radius: var(--table-radius-sm);
    cursor: pointer;
    transition: all var(--table-transition-fast);
    display: flex;
    align-items: center;
    gap: var(--table-spacing-sm);
    font-size: 0.875rem;
    font-family: var(--table-font-sans);
    font-weight: 500;
}

.quill-table-block .table-edit-btn:hover {
    background: var(--table-bg-hover);
    border-color: var(--table-color-brand-brown);
}

.quill-table-block .table-delete-btn:hover {
    background: var(--table-bg-delete-hover);
    border-color: var(--table-color-delete);
}

.quill-table-block .table-edit-btn svg {
    color: var(--table-color-brand-brown);
}

.quill-table-block .table-delete-btn svg {
    color: var(--table-color-delete);
}

.quill-table-block .table-preview {
    overflow-x: auto;
}

/* ============================================
   PUBLISHED TABLE STYLES
   CRITICAL: 27px spacing to match gallery/callout
   ============================================ */

.published-table {
    margin: var(--table-spacing-match-content) 0; /* 27px to match paragraph spacing */
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.published-table table {
    width: 100%;
    border-collapse: collapse;
    background: var(--table-color-white);
    font-family: var(--table-font-sans);
    font-size: 1rem;
}

.published-table th,
.published-table td {
    padding: var(--table-spacing-lg);
    text-align: left;
    border: 1px solid var(--table-border-primary);
    vertical-align: top;
}

.published-table th {
    background: var(--table-bg-header);
    font-weight: 600;
    font-family: var(--table-font-serif);
    color: var(--table-color-text-primary);
}

.published-table td {
    color: var(--table-color-text-secondary);
}

/* No borders variant */
.published-table.no-borders table,
.published-table.no-borders th,
.published-table.no-borders td {
    border: none;
}

.published-table.no-borders th {
    border-bottom: 2px solid var(--table-border-primary);
}

/* Striped rows variant */
.published-table.striped tbody tr:nth-child(even) {
    background: var(--table-bg-striped);
}

/* Compact mode variant */
.published-table.compact th,
.published-table.compact td {
    padding: var(--table-spacing-sm) var(--table-spacing-md);
    font-size: 0.9rem;
}

/* Text alignment variants */
.published-table th.align-left,
.published-table td.align-left {
    text-align: left;
}

.published-table th.align-center,
.published-table td.align-center {
    text-align: center;
}

.published-table th.align-justify,
.published-table td.align-justify {
    text-align: justify;
}

/* ============================================
   TABLE MODAL STYLES
   ============================================ */

.table-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--table-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--table-z-modal);
    padding: var(--table-spacing-xl);
}

.table-modal {
    background: var(--table-color-white);
    border-radius: var(--table-radius-xl);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.table-modal .modal-header {
    padding: var(--table-spacing-2xl);
    border-bottom: 1px solid var(--table-border-lighter);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table-modal .modal-header h2 {
    margin: 0;
    font-family: var(--table-font-serif);
    font-size: 1.5rem;
    color: var(--table-color-text-primary);
}

.table-modal .close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--table-color-text-lighter);
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--table-transition-fast);
}

.table-modal .close-btn:hover {
    color: var(--table-color-text-secondary);
}

.table-modal .modal-body {
    padding: var(--table-spacing-2xl);
    overflow-y: auto;
    flex: 1;
}

.table-modal .modal-body section {
    margin-bottom: var(--table-spacing-3xl);
}

.table-modal .modal-body h3 {
    margin: 0 0 var(--table-spacing-xl) 0;
    font-family: var(--table-font-serif);
    font-size: 1.125rem;
    color: var(--table-color-text-primary);
}

/* Dimensions Section */
.dimensions-section .dimension-inputs {
    display: flex;
    gap: var(--table-spacing-xl);
    align-items: flex-end;
    flex-wrap: wrap;
}

.dimensions-section .input-group {
    flex: 1;
    min-width: 120px;
}

.dimensions-section label {
    display: block;
    margin-bottom: var(--table-spacing-sm);
    font-weight: 500;
    color: var(--table-color-text-secondary);
    font-size: 0.9rem;
}

.dimensions-section .dimension-input {
    width: 100%;
    padding: var(--table-spacing-md);
    border: 1px solid var(--table-border-primary);
    border-radius: var(--table-radius-md);
    font-size: 1rem;
    font-family: var(--table-font-sans);
}

.dimensions-section small {
    display: block;
    margin-top: var(--table-spacing-xs);
    font-size: 0.75rem;
    color: var(--table-color-text-light);
}

.btn-generate {
    padding: var(--table-spacing-md) 1.25rem;
    background: var(--table-color-brand-brown);
    color: var(--table-color-white);
    border: none;
    border-radius: var(--table-radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--table-transition-fast);
    font-family: var(--table-font-sans);
    white-space: nowrap;
}

.btn-generate:hover {
    background: var(--table-color-brand-brown-dark);
}

/* Options Section */
.options-section .options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--table-spacing-lg);
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--table-color-text-secondary);
}

.checkbox-label input[type="checkbox"] {
    margin-right: var(--table-spacing-md);
    cursor: pointer;
}

/* Cell Editor Section */
.cell-editor-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--table-border-light);
    border-radius: var(--table-radius-md);
    padding: var(--table-spacing-xl);
    background: var(--table-bg-warm);
}

.cell-editor-grid {
    display: grid;
    gap: var(--table-spacing-md);
}

.cell-editor-grid .placeholder-text {
    text-align: center;
    color: var(--table-color-text-lighter);
    padding: var(--table-spacing-3xl);
}

.cell-input-wrapper {
    display: block;
}

.cell-input-wrapper.header-cell .cell-input {
    background: rgba(92, 64, 51, 0.05);
    font-weight: 600;
}

.cell-input {
    width: 100%;
    padding: var(--table-spacing-md);
    border: 1px solid var(--table-border-primary);
    border-radius: var(--table-radius-sm);
    font-size: 0.9rem;
    font-family: var(--table-font-sans);
}

.cell-input:focus {
    outline: none;
    border-color: var(--table-color-brand-brown);
    box-shadow: 0 0 0 3px rgba(92, 64, 51, 0.1);
}

/* Preview Section */
.preview-section .table-preview {
    border: 1px solid var(--table-border-light);
    border-radius: var(--table-radius-md);
    padding: var(--table-spacing-xl);
    background: var(--table-bg-light);
    overflow-x: auto;
}

.preview-section .preview-placeholder {
    text-align: center;
    padding: var(--table-spacing-3xl);
    color: var(--table-color-text-lighter);
}

/* Modal Footer */
.table-modal .modal-footer {
    padding: var(--table-spacing-2xl);
    border-top: 1px solid var(--table-border-lighter);
    display: flex;
    gap: var(--table-spacing-xl);
    justify-content: flex-end;
}

.table-modal .btn-cancel,
.table-modal .btn-insert {
    padding: 0.625rem var(--table-spacing-2xl);
    border-radius: var(--table-radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--table-transition-fast);
    font-family: var(--table-font-sans);
}

.table-modal .btn-cancel {
    background: var(--table-color-white);
    color: var(--table-color-text-secondary);
    border: 1px solid var(--table-border-primary);
}

.table-modal .btn-cancel:hover {
    background: rgba(92, 64, 51, 0.05);
}

.table-modal .btn-insert {
    background: var(--table-color-brand-brown);
    color: var(--table-color-white);
    border: none;
}

.table-modal .btn-insert:hover {
    background: var(--table-color-brand-brown-dark);
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 640px) {
    .published-table {
        margin: var(--table-spacing-match-content) 0; /* Keep same 27px spacing on mobile */
    }

    .table-modal {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 0;
    }

    .dimensions-section .dimension-inputs {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-generate {
        width: 100%;
    }

    .options-section .options-grid {
        grid-template-columns: 1fr;
    }

    .cell-editor-grid {
        gap: var(--table-spacing-sm);
    }

    .cell-input {
        font-size: 0.85rem;
        padding: var(--table-spacing-sm);
    }

    .table-modal .modal-footer {
        flex-direction: column-reverse;
    }

    .table-modal .btn-cancel,
    .table-modal .btn-insert {
        width: 100%;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .published-table {
        break-inside: avoid;
    }

    .published-table table {
        page-break-inside: avoid;
    }
}

/* ============================================
   TABLE LINK STYLES (PUBLISHED VIEW)
   ============================================ */

.published-table a {
    color: var(--table-color-brand-brown);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    transition: all var(--table-transition-fast);
}

.published-table a:hover {
    color: var(--table-color-accent-pink);
    text-decoration-thickness: 2px;
}

.published-table a:active {
    color: var(--table-color-brand-brown-dark);
}

/* Ensure links work on published blog posts */
.post-content .published-table a,
.prose .published-table a,
article .published-table a {
    pointer-events: auto;
}

/* Prevent link clicks in preview (editor) */
.table-preview .published-table a {
    pointer-events: none;
    cursor: default;
}
