:root {
    /* Colors derived from intai style */
    --bg-app: #f5f7fa;
    --bg-white: #ffffff;
    --text-main: #334155;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --danger: #ef4444;

    --sidebar-width: 340px;
    --header-height: 50px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    color: var(--text-main);
    background-color: var(--bg-app);
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.03);
}

.brand {
    height: 60px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.brand-mark {
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: 4px;
}

.brand-title {
    font-weight: 700;
    font-size: 16px;
    color: #1e293b;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    background-color: var(--primary-light);
    color: var(--primary);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Panel */
.panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.panel.active {
    display: block;
}

.section {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.section:last-child {
    border-bottom: none;
}

.section h2 {
    font-size: 13px;
    margin: 0 0 12px 0;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    width: 100%;
}

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

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

.btn.ghost {
    background: white;
    border-color: var(--border);
    color: var(--text-main);
}

.btn.ghost:hover {
    background: var(--bg-app);
    border-color: var(--text-muted);
}

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

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--bg-white);
    min-width: 180px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 8px 0;
    z-index: 1000;
    border: 1px solid var(--border);
    margin-top: 8px;
    list-style: none;
    overflow: hidden;
    animation: dropdownIn 0.2s ease;
}

@keyframes dropdownIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown.active .dropdown-menu {
    display: block;
}

.dropdown-menu li a {
    display: block;
    padding: 10px 16px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.dropdown-menu li a:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.dropdown-menu li a.disabled {
    color: var(--text-muted);
    background: transparent;
    cursor: default;
    opacity: 0.6;
}

.dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
}


.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.field span {
    font-size: 13px;
    font-weight: 600;
}

select,
input[type="text"] {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    width: 100%;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--primary);
}

.row.gap {
    display: flex;
    gap: 8px;
}

.section-row {
    flex-wrap: wrap;
}

.row.space-between {
    justify-content: space-between;
    align-items: center;
}

.btn.sm {
    padding: 4px 8px;
    font-size: 12px;
    width: auto;
}

.series-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    position: relative;
}

.series-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
    background: none;
    border: none;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.series-remove:hover {
    opacity: 1;
}

/* File Upload */
.file-upload-wrapper {
    position: relative;
    width: 100%;
}

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

.file-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-color: var(--bg-app);
    border: 2px dashed var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.file-upload-label:hover,
.file-upload-wrapper.dragover .file-upload-label {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

.file-upload-label i {
    font-size: 24px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Status Card */
.status-card {
    background: var(--bg-app);
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.status-card .label {
    color: var(--text-muted);
}

.status-card span:last-child {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

/* Chart Type Grid */
.chart-type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.chart-option input {
    display: none;
}

.chart-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    background: linear-gradient(to bottom, #fff, #f8fafc);
}

.chart-card i {
    font-size: 20px;
    margin-bottom: 6px;
}

.chart-card span {
    font-size: 12px;
    font-weight: 600;
}

.chart-option input:checked+.chart-card {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Main Content - Free Canvas Layout */
.main-content {
    flex: 1;
    position: relative;
    background-color: #f1f5f9;
    padding: 0;
    /* Remove padding to be edge-to-edge canvas */
    overflow: hidden;
    /* Handle internal scroll */
}

.canvas-area {
    width: 100%;
    height: 100%;
    position: relative;
    /* Grid Pattern Background */
    background-image:
        linear-gradient(rgba(203, 213, 225, 0.4) 1px, transparent 1px),
        linear-gradient(90deg, rgba(203, 213, 225, 0.4) 1px, transparent 1px);
    background-size: 40px 40px;
    overflow: auto;
}

/* Draggable/Resizable Graph Container */
.graph-wrapper {
    position: absolute;
    top: 50px;
    left: 50px;
    width: 600px;
    height: 400px;
    background: white;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    /* For Interact.js touch-action */
    touch-action: none;
    box-sizing: border-box;
    /* Default Z-index */
    z-index: 100;
}

.graph-wrapper.hidden {
    display: none !important;
}

.graph-header-handle {
    height: 32px;
    background-color: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    cursor: move;
    /* Drag cursor */
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    color: var(--text-muted);
    gap: 8px;
    font-size: 13px;
    user-select: none;
}

.graph-header-handle i {
    color: #cbd5e1;
}

.plot-content {
    flex: 1;
    width: 100%;
    height: 100%;
    /* Important for Plotly to fill */
    overflow: hidden;
    position: relative;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-weight: 600;
    pointer-events: none;
    /* Let clicks pass through if needed */
}

/* Interact.js Resize Handles (Optional visual hint, interact.js creates virtual ones but we can style boundaries) */
.graph-wrapper:hover {
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 10px 10px -5px rgb(0 0 0 / 0.04);
}

.hidden {
    display: none !important;
}