/* Design Tokens */
:root {
    /* Colors */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #22c55e;

    /* Spacing */
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 2rem;
    --space-xl: 4rem;

    /* Layout */
    --sidebar-width: 250px;
    --header-height: 64px;
    --radius: 8px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-body);
    color: var(--text-main);
}

/* Layout Structure */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-lg);
}

/* Components */
.logo {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 var(--space-lg);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    text-decoration: none;
}

.nav-links {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.nav-item {
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: var(--radius);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background: #eff6ff;
    color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-body);
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-lg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Grid for Widgets */
.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.widget-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-lg);
    transition: transform 0.2s, box-shadow 0.2s;
}

.widget-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-simple {
    background: #e0f2fe;
    color: #0369a1;
}

.badge-extended {
    background: #f0fdf4;
    color: #15803d;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s;
    margin-bottom: 0;
}

.form-group .form-control {
    margin-bottom: 0px;
}

.form-group small {
    display: block;
    margin-top: 0.5rem;
}

/* Invalid State */
.form-control.invalid,
.form-control:invalid {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 1px var(--danger);
    background-color: #fef2f2;
    /* Light red background for extra visibility */
}


/* Widget Type Selector */
.widget-type-card {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
}

.widget-type-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.widget-type-summary {
    flex: 1;
    /* Pushes the 'Learn more' button down if heights differ */
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 1rem 0;
}

.widget-type-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.1);
}

.widget-type-card.selected {
    border-color: var(--primary);
    background: #eff6ff;
}

.widget-type-card input[type="radio"] {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.widget-type-content h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-main);
    font-size: 1.1rem;
}

.widget-type-summary {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 1rem 0;
}

.learn-more-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
    font-weight: 500;
    text-decoration: underline;
}

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

.widget-type-details {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.widget-type-details p {
    margin: 0.5rem 0;
}

/* Code Editor & Preview Layout */
.code-editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 600px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: white;
}

.code-editor-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.code-editor-header,
.preview-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-editor-header h3,
.preview-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.code-editor {
    flex: 1;
    overflow: auto;
    background: #1e293b;
    color: #e2e8f0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
}

.code-editor pre {
    margin: 0;
    padding: 1.5rem;
}

.code-editor code {
    display: block;
}

/* Code Syntax Highlighting */
.code-comment {
    color: #94a3b8;
    font-style: italic;
}

.code-tag {
    color: #38bdf8;
}

.code-attr {
    color: #a78bfa;
}

.code-string {
    color: #34d399;
}

.code-editable {
    background: rgba(251, 191, 36, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    display: inline-block;
}

.code-input {
    background: #334155;
    border: 1px solid #475569;
    color: #34d399;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: inherit;
    font-size: inherit;
    min-width: 200px;
}

.code-color-input {
    min-width: 60px;
    height: 28px;
    padding: 2px;
    cursor: pointer;
}

/* Preview Panel */
.preview-panel {
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

.preview-container {
    flex: 1;
    padding: 2rem;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#preview-widget {
    width: auto;
    max-width: 100%;
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 1rem;
}

.flash {
    padding: 1rem;
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    color: #92400e;
    margin-bottom: 0.5rem;
}

/* Modal Confirmation Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease-out;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: var(--space-lg);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    transform: scale(0.95);
    animation: scaleIn 0.15s ease-out forwards;
    border: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-main);
    font-size: 1.25rem;
}

.modal-body p {
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0 0 1.5rem 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

@keyframes scaleIn {
    to {
        transform: scale(1);
    }
}