@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

/* Scope everything to .cam-editor-wrapper to prevent leaking and conflicts */
.cam-editor-wrapper {
    /* Variables */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --bg-body: #f8fafc;
    --bg-panel: rgba(255, 255, 255, 0.85);
    --bg-card: #ffffff;

    --text-main: #1e293b;
    --text-sub: #64748b;
    --text-light: #94a3b8;

    --border-color: #e2e8f0;
    --border-focus: #818cf8;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);

    --radius-sm: 0.375rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --header-height: 60px;

    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-main);
    /* Reset box sizing for children */
    box-sizing: border-box;
}

.cam-editor-wrapper *,
.cam-editor-wrapper *::before,
.cam-editor-wrapper *::after {
    box-sizing: border-box;
}

/* Layout */
.cam-editor-wrapper .app-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    width: 100%;
    /* Override max-width to fit container or be full width */
    max-width: 100%;
    height: calc(100vh - 80px);
    /* Fill screen minus header */
    min-height: 800px;
    background-color: var(--bg-body);
    /* Local background for the tool area */
    background-image:
        radial-gradient(at 0% 0%, rgba(79, 70, 229, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
    padding: 20px;
    /* Remove border and radius for full-screen feel */
    border-radius: 0;
    border: none;
}

/* Sidebar */
.cam-editor-wrapper .sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    padding-right: 4px;
}

.cam-editor-wrapper .brand {
    padding: 0 4px;
}

.cam-editor-wrapper .brand h1 {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0;
    line-height: 1.2;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

/* Main Content */
.cam-editor-wrapper .main-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    height: 100%;
    padding-bottom: 20px;
}

/* Panels */
.cam-editor-wrapper .panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glass);
    padding: 20px;
}

.cam-editor-wrapper .panel-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 0;
}

.cam-editor-wrapper .card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

/* Inputs */
.cam-editor-wrapper .input-group {
    margin-bottom: 16px;
}

.cam-editor-wrapper .input-group label {
    display: block;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.cam-editor-wrapper input[type="number"],
.cam-editor-wrapper input[type="text"],
.cam-editor-wrapper select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: all 0.2s;
    background: #fff;
    color: var(--text-main);
    margin: 0;
}

.cam-editor-wrapper input:focus,
.cam-editor-wrapper select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.cam-editor-wrapper .unit {
    color: var(--text-light);
    font-size: 0.75rem;
    margin-left: 4px;
}

.cam-editor-wrapper .info-text {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
}

/* Buttons */
.cam-editor-wrapper .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.9rem;
    width: 100%;
    line-height: 1.5;
}

.cam-editor-wrapper .btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.cam-editor-wrapper .btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 10px -2px rgba(79, 70, 229, 0.3);
}

.cam-editor-wrapper .btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}

.cam-editor-wrapper .btn-success:hover {
    background: #059669;
    transform: translateY(-1px);
}

.cam-editor-wrapper .btn-ghost {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.cam-editor-wrapper .btn-ghost:hover {
    background: var(--bg-body);
    border-color: var(--text-sub);
}

.cam-editor-wrapper .btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.cam-editor-wrapper .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.cam-editor-wrapper .button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

/* Top Row Layout */
.cam-editor-wrapper .top-row {
    display: grid;
    /* Use 2:1 ratio as requested */
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    align-items: start;
    width: 100%;
}

/* Graph Editor */
.cam-editor-wrapper .graph-section-large {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Flexbox fix */
}

/* Preview Section */
.cam-editor-wrapper .preview-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    /* Flexbox fix */
}

/* Canvas Containers */
.cam-editor-wrapper #graphEditorContainer {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    flex: 1;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.cam-editor-wrapper #profileGraphCanvas {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    display: block;
}

.cam-editor-wrapper .canvas-frame {
    width: 100%;
    height: 100%;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex: 1;
    min-height: 300px;
}

.cam-editor-wrapper .graph-controls {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Segments List */
.cam-editor-wrapper .segments-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: white;
}

.cam-editor-wrapper .segments-list table {
    width: 100%;
    border-collapse: collapse;
}

.cam-editor-wrapper .segments-list th,
.cam-editor-wrapper .segments-list td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.cam-editor-wrapper .segments-list th {
    background: var(--bg-body);
    font-weight: 600;
    position: sticky;
    top: 0;
}

/* Cam Preview & Kinematics */
.cam-editor-wrapper .canvas-wrapper {
    background: white;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    flex: 1;
}

.cam-editor-wrapper #camCanvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.cam-editor-wrapper .kinematics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.cam-editor-wrapper .chart-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px;
}

.cam-editor-wrapper .chart-card canvas {
    width: 100% !important;
    height: auto !important;
}

/* Result Data */
.cam-editor-wrapper #dataDisplay {
    background: #1e1e1e;
    color: #a9b7c6;
    font-family: 'JetBrains Mono', monospace;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    max-height: 300px;
}

/* Dialog */
.cam-editor-wrapper dialog {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0;
    max-width: 400px;
    width: 100%;
}

.cam-editor-wrapper dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.cam-editor-wrapper .dialog-content {
    padding: 24px;
}

.cam-editor-wrapper .dialog-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-main);
}

@media (max-width: 1024px) {
    .cam-editor-wrapper .app-container {
        grid-template-columns: 1fr;
        height: auto;
    }

    .cam-editor-wrapper .sidebar {
        padding-right: 0;
        overflow-y: visible;
    }

    .cam-editor-wrapper .main-content {
        overflow-y: visible;
    }

    .cam-editor-wrapper .top-row {
        grid-template-columns: 1fr;
    }

    .cam-editor-wrapper .split-view {
        grid-template-columns: 1fr;
    }
}

/* Groove Cam Toggle Button Styles */
.cam-editor-wrapper .btn-toggle {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
}

.cam-editor-wrapper .btn-toggle.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.cam-editor-wrapper .btn-toggle:hover:not(.active) {
    background: var(--primary-light);
    border-color: var(--primary);
}