/* ===========================
   TIFANY UI — 3-Panel Layout
   =========================== */

/* CSS Custom Properties — Light (default) */
:root {
    --t-primary: #1a73e8;
    --t-primary-dark: #1557b0;
    --t-bg-surface: #ffffff;
    --t-bg-workspace: #f8f9fa;
    --t-bg-input: #ffffff;
    --t-border: #e5e7eb;
    --t-text: #111827;
    --t-text-muted: #6b7280;
    --t-text-light: #9ca3af;
    --t-section-header: #1a73e8;
    --t-hover-bg: rgba(26, 115, 232, 0.07);
    --t-active-bg: rgba(26, 115, 232, 0.12);
    --t-toolbar-bg: #f0f4ff;
    --t-toolbar-border: rgba(79, 172, 254, 0.4);
    --t-header-height: 52px;
}

/* Dark Theme */
[data-theme="dark"] {
    --t-bg-surface: #252526;
    --t-bg-workspace: #1e1e1e;
    --t-bg-input: #2d2d30;
    --t-border: #3e3e42;
    --t-text: #d4d4d4;
    --t-text-muted: #9d9d9d;
    --t-text-light: #6a6a6a;
    --t-hover-bg: rgba(255, 255, 255, 0.06);
    --t-active-bg: rgba(255, 255, 255, 0.1);
    --t-toolbar-bg: rgba(79, 172, 254, 0.15);
    --t-toolbar-border: rgba(79, 172, 254, 0.3);
}

/* ===========================
   RESET (scoped to TIFANY)
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    background-color: var(--t-bg-workspace);
    color: var(--t-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13px;
    line-height: 1.5;
}

/* ===========================
   TIFANY HEADER
   =========================== */
.tifany-header {
    height: var(--t-header-height);
    background: var(--t-bg-surface);
    border-bottom: 1px solid var(--t-border);
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
}

.tifany-header .logo {
    flex-shrink: 0;
}

.tifany-header .logo h1 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.3px;
}

.tifany-header .nav {
    flex: 1;
    display: flex;
    gap: 2px;
    align-items: center;
}

.tifany-header .nav-link {
    font-size: 13px;
    color: var(--t-text-muted);
    padding: 5px 10px;
    border-radius: 6px;
    transition: all 150ms ease;
}

.tifany-header .nav-link:hover {
    color: var(--t-text);
    background: var(--t-hover-bg);
}

/* Theme toggle button */
.theme-toggle-btn {
    background: none;
    border: 1px solid var(--t-border);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--t-text-muted);
    font-size: 14px;
    transition: all 150ms ease;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    background: var(--t-hover-bg);
    color: var(--t-text);
}

/* ===========================
   3-PANEL APP LAYOUT
   =========================== */
.tifany-app {
    display: flex;
    flex-direction: row;
    height: calc(100vh - var(--t-header-height));
    overflow: hidden;
}

/* --- Icon nav rail --- */
.sidebar-nav-rail {
    width: 48px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-right: 1px solid var(--t-border);
    background: var(--t-bg-surface);
    padding: 8px 0;
    gap: 4px;
}

.sidebar-nav-rail a,
.sidebar-nav-rail button {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--t-text-muted);
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    transition: all 150ms ease;
}

.sidebar-nav-rail a:hover,
.sidebar-nav-rail button:hover {
    background: var(--t-hover-bg);
    color: var(--t-primary);
}

.sidebar-nav-rail a.active {
    color: var(--t-primary);
    background: var(--t-active-bg);
}

/* --- Left panel --- */
.tifany-left-panel {
    width: 264px;
    min-width: 200px;
    overflow-y: auto;
    border-right: 1px solid var(--t-border);
    background: var(--t-bg-surface);
    flex-shrink: 0;
}

/* --- Center panel --- */
.tifany-center-panel {
    flex: 1;
    min-width: 0;
    overflow: auto;
    background: var(--t-bg-workspace);
    display: flex;
    flex-direction: column;
}

/* --- Right panel --- */
.tifany-right-panel {
    width: 300px;
    min-width: 220px;
    overflow-y: auto;
    border-left: 1px solid var(--t-border);
    background: var(--t-bg-surface);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

/* ===========================
   LEFT PANEL SECTIONS
   =========================== */
.left-section-header {
    color: var(--t-section-header);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 10px 12px 6px;
    border-bottom: 1px solid var(--t-border);
    user-select: none;
}

.left-section-body {
    padding: 8px 12px 10px;
    border-bottom: 1px solid var(--t-border);
}

/* ===========================
   RIGHT PANEL SECTIONS (collapsible)
   =========================== */
.right-section {
    border-bottom: 1px solid var(--t-border);
}

.right-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    color: var(--t-section-header);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    background: var(--t-bg-surface);
    transition: background 150ms ease;
}

.right-section-header:hover {
    background: var(--t-hover-bg);
}

.right-section-chevron {
    font-size: 10px;
    color: var(--t-text-muted);
    transition: transform 150ms ease;
}

.right-section-body {
    padding: 10px 14px 12px;
    background: var(--t-bg-surface);
}

.right-section-body.collapsed {
    display: none;
}

/* Monaco editor container */
#monaco-editor-container {
    height: 480px;
    min-height: 180px;
    border: 1px solid var(--t-border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

/* Generate actions row */
.generate-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

/* ===========================
   CENTER — TABLE WRAPPER
   =========================== */
.center-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--t-text-muted);
    padding: 8px 14px;
    border-bottom: 1px solid var(--t-border);
    background: var(--t-bg-surface);
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.center-pos {
    font-size: 11px;
    color: var(--t-text-light);
}

.table-wrapper {
    background-color: var(--t-bg-workspace);
    flex: 1;
    text-align: center;
    cursor: pointer;
    position: relative;
    overflow: auto;
    padding: 16px;
    min-height: 200px;
}

/* ===========================
   MOBILE TOOLBAR (shown only on mobile)
   =========================== */
#tableViewer-mb {
    display: none;
}

.toolbar-container {
    display: flex;
    background-color: var(--t-bg-surface);
    border-bottom: 1px solid var(--t-border);
    padding: 6px 8px;
    overflow-x: auto;
    white-space: nowrap;
    gap: 4px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 8px;
    margin-right: 4px;
    border-right: 1px solid var(--t-border);
}

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

.toolbar-btn {
    background: var(--t-toolbar-bg);
    border: 1px solid var(--t-toolbar-border);
    color: var(--t-text);
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 11px;
    cursor: pointer;
    transition: all 200ms ease;
    white-space: nowrap;
    font-family: inherit;
}

.toolbar-btn:hover {
    background: var(--t-hover-bg);
    border-color: var(--t-primary);
    color: var(--t-primary);
}

.toolbar-btn.active {
    background: var(--t-active-bg);
    color: var(--t-primary);
    border-color: var(--t-primary);
}

/* ===========================
   LEGACY / COMPAT (Bootstrap accordion panels still used inside left sidebar)
   =========================== */
.panel {
    display: none;
    overflow: auto;
}

.accordion {
    background-color: #eee;
    color: #444;
    cursor: pointer;
    padding: 10px 14px;
    width: 100%;
    border: 1px solid var(--t-border);
    text-align: left;
    outline: none;
    font-size: 12px;
    transition: 0.3s;
    border-radius: 5px;
    font-family: inherit;
}

.accordion.active {
    background-color: #ddd;
}

.accordion::after {
    content: " \25BD";
    float: right;
}

.accordion.active::after {
    content: " \25B3";
}

.side-accordion {
    writing-mode: sideways-rl;
    align-content: space-around;
}

.ha-100.active {
    height: 100%;
}

.input-container {
    display: block;
    padding: 8px 0;
}

.sidebar-container {
    display: none; /* hidden on desktop — replaced by .tifany-left-panel */
}

.sidebar {
    width: 100%;
    padding: 5px;
    background: var(--t-bg-surface);
    overflow-y: auto;
}

.instructions {
    background: var(--t-bg-surface);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 11px;
    line-height: 1.6;
    color: var(--t-text-muted);
}

.control-group {
    margin-bottom: 12px;
    padding: 8px;
    border-radius: 8px;
}

.control-group h3 {
    margin-bottom: 8px;
    color: var(--t-text);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-style {
    border: 1px solid var(--t-border);
    border-radius: 8px;
    margin-top: 5px;
    padding: 12px;
}

.style-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 8px 0;
}

.button-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: space-between;
    min-width: 100%;
}

.sp-class:hover {
    transition: all 200ms ease;
    transform: scale(1.05);
}

/* ===========================
   DARK MODE — Bootstrap 4 overrides
   =========================== */
[data-theme="dark"] body {
    background-color: var(--t-bg-workspace);
    color: var(--t-text);
}

[data-theme="dark"] .tifany-header {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
}

[data-theme="dark"] .tifany-left-panel,
[data-theme="dark"] .tifany-right-panel {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
}

[data-theme="dark"] .left-section-header,
[data-theme="dark"] .right-section-header {
    border-color: var(--t-border);
}

[data-theme="dark"] .left-section-body,
[data-theme="dark"] .right-section-body {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
}

[data-theme="dark"] .right-section {
    border-color: var(--t-border);
}

[data-theme="dark"] .accordion {
    background: #333;
    color: #ccc;
    border-color: var(--t-border);
}

[data-theme="dark"] .accordion.active {
    background: #3a3a3a;
}

[data-theme="dark"] .panel {
    background: var(--t-bg-surface);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] select,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] textarea {
    background-color: var(--t-bg-input) !important;
    color: var(--t-text) !important;
    border-color: var(--t-border) !important;
}

[data-theme="dark"] .btn-outline-primary {
    color: #6ab0f5;
    border-color: #6ab0f5;
}

[data-theme="dark"] .btn-outline-secondary {
    color: #ccc;
    border-color: #555;
}

[data-theme="dark"] .btn-outline-danger {
    color: #f87171;
    border-color: #f87171;
}

[data-theme="dark"] .modal-content {
    background-color: var(--t-bg-surface);
    color: var(--t-text);
    border-color: var(--t-border);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
    border-color: var(--t-border);
}

[data-theme="dark"] .close {
    color: var(--t-text);
}

[data-theme="dark"] label {
    color: var(--t-text-muted);
}

[data-theme="dark"] .cell-controls {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
    color: var(--t-text);
}

[data-theme="dark"] .toolbar-container {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
}

[data-theme="dark"] .center-header {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
}

[data-theme="dark"] .sidebar-nav-rail {
    background: var(--t-bg-surface);
    border-color: var(--t-border);
}

/* ===========================
   MOBILE LAYOUT
   Mobile stack order (top → bottom):
   1. Text Input
   2. Instruction
   3. Toolbar + Table Viewer
   4. Generate Code
   =========================== */
@media (max-width: 768px) {
    .tifany-app {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - var(--t-header-height));
        overflow: visible;
    }

    /* Hide desktop-only elements on mobile */
    #sidebar-nav-mount,
    .tifany-left-panel {
        display: none;
    }

    /* Right panel: show stacked at top on mobile */
    .tifany-right-panel {
        width: 100%;
        border-left: none;
        border-bottom: 1px solid var(--t-border);
        order: 1;
    }

    /* Move Text Input section to top */
    .right-section[data-mobile-order="1"] { order: 1; }
    /* Move Instruction section second */
    .right-section[data-mobile-order="2"] { order: 2; }
    /* Move Generate Code section last */
    .right-section[data-mobile-order="3"] { order: 3; }

    /* Center (toolbar + table) in the middle */
    .tifany-center-panel {
        width: 100%;
        order: 2;
        height: auto;
        overflow: visible;
    }

    /* Show mobile toolbar */
    #tableViewer-mb {
        display: block;
    }

    /* Table wrapper takes natural height on mobile */
    .table-wrapper {
        height: auto;
        min-height: 300px;
    }

    /* Monaco editor smaller on mobile */
    #monaco-editor-container {
        height: 200px;
    }
}

@media (max-width: 480px) {
    .tifany-header .nav {
        display: none;
    }
}
