:root {
    --bg-dark: #0f1115;
    --bg-panel: #161920;
    --bg-panel-light: #1f232b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #8b5cf6;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #2d3139;
    --border-hover: #4b5563;
    --success: #10b981;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    height: 70px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-main);
    background: linear-gradient(90deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo svg {
    stroke: var(--primary);
}

.nav-links {
    list-style: none;
    padding: 24px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-item:hover {
    background-color: var(--bg-panel-light);
    color: var(--text-main);
}

.nav-item.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

/* Main Content Area */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.view-section {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 32px;
    overflow-y: auto;
}

.view-section.active {
    opacity: 1;
    pointer-events: all;
}

.view-header {
    margin-bottom: 24px;
}

.view-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.view-header p {
    color: var(--text-muted);
}

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

.actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background-color: var(--bg-panel-light);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--border);
}

/* Editor */
.editor-container {
    flex: 1;
    display: flex;
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

#template-sections-container {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: transparent;
}

.template-section {
    background-color: var(--bg-panel-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    /* Prevent squishing when there are many sections */
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
}

.section-header-left {
    display: flex;
    align-items: center;
}

.section-meta {
    display: flex;
    gap: 24px;
    align-items: center;
}

.meta-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.meta-field label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.meta-field input,
.meta-field select {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.85rem;
}

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

.section-controls {
    display: flex;
    gap: 4px;
}

.section-body {
    display: flex;
    flex-direction: column;
}

.section-body.hidden {
    display: none;
}

.section-notes-container {
    padding: 12px 16px 0 16px;
}

.section-notes {
    width: 100%;
    min-height: 48px;
    background-color: var(--bg-dark);
    border: 1px dashed var(--border);
    color: var(--text-main);
    padding: 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}

.section-notes:focus {
    border-color: var(--primary);
}

.section-editor {
    width: 100%;
    min-height: 150px;
    background-color: transparent;
    border: none;
    padding: 16px;
    color: #e5e7eb;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
}

.section-editor:focus {
    background-color: rgba(255, 255, 255, 0.02);
}



/* Table */
.table-container {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: auto;
    flex: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th,
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

th {
    background-color: var(--bg-panel-light);
    font-weight: 500;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    z-index: 10;
}

.col-header-input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.875rem;
    width: 100%;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.col-header-input:hover,
.col-header-input:focus {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--border-hover);
    outline: none;
}

.col-header-container {
    display: flex;
    align-items: center;
    gap: 4px;
    resize: horizontal;
    overflow: hidden;
    min-width: 120px;
    padding-right: 4px;
}

.col-delete-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.col-delete-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.cell-input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    font-family: 'Fira Code', monospace;
    font-size: 0.875rem;
    padding: 8px;
    border-radius: 4px;
}

.cell-input:focus {
    background-color: var(--bg-dark);
    border-color: var(--primary);
    outline: none;
}

.row-delete {
    color: var(--danger);
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-delete:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

/* Empty State */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 1.125rem;
    border: 1px dashed var(--border);
    border-radius: 8px;
}

/* Generator Output Grid */
.output-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 24px;
    overflow-y: auto;
    padding-bottom: 40px;
}

.config-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 400px;
}

.config-card-header {
    padding: 12px 16px;
    background-color: var(--bg-panel-light);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.copy-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

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

.config-card pre {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    font-family: 'Fira Code', monospace;
    font-size: 13px;
    color: #a7f3d0;
    line-height: 1.5;
    white-space: pre-wrap;
    background-color: #0d1117;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Context Menu */
.context-menu {
    position: absolute;
    background-color: var(--bg-panel-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    width: 240px;
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.context-menu.hidden {
    display: none;
}

.context-menu-header {
    padding: 10px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.context-menu-list {
    max-height: 200px;
    overflow-y: auto;
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--text-main);
    transition: background-color 0.15s;
    user-select: none;
}

.context-menu-item:hover {
    background-color: var(--primary);
    color: white;
}

.context-menu-divider {
    height: 1px;
    background-color: var(--border);
}

.context-menu-new {
    padding: 12px;
    display: flex;
    gap: 8px;
    background-color: var(--bg-panel);
}

.context-menu-new input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    outline: none;
}

.context-menu-new input:focus {
    border-color: var(--primary);
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.75rem;
}

/* Sidebar Footer */
.sidebar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sidebar-footer {
    margin-top: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-top: 1px solid var(--border);
}

.sidebar-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 10px 16px;
    background-color: transparent;
    border: 1px solid transparent;
}

.sidebar-btn:hover {
    background-color: var(--bg-panel-light);
    border-color: var(--border);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-content.large-modal {
    max-width: 90vw;
    width: 800px;
    height: 80vh;
    resize: both;
    overflow: hidden;
    min-width: 400px;
    min-height: 400px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-field label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.modal-field input {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.875rem;
}

.modal-field input:focus {
    border-color: var(--primary);
    outline: none;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Device Cell Button */
.device-cell-btn {
    width: 100%;
    justify-content: center;
}