/* Design Tokens - Adapted from Design Handoff */
:root {
    /* Base Colors - HSL/Okaylab Approximations */
    --background: #ffffff;
    --foreground: #02020a;

    --card: #ffffff;
    --card-foreground: #02020a;

    --popover: #ffffff;
    --popover-foreground: #02020a;

    --primary: #030213;
    --primary-foreground: #ffffff;

    --secondary: #eef1f6;
    --secondary-foreground: #030213;

    --muted: #ececf0;
    --muted-foreground: #717182;

    --accent: #e9ebef;
    --accent-foreground: #030213;

    --destructive: #d4183d;
    --destructive-foreground: #ffffff;

    --border: rgba(0, 0, 0, 0.1);
    --input: transparent;
    --input-background: #f3f3f5;
    --ring: rgba(0, 0, 0, 0.2);

    --radius: 0.625rem;

    /* Spacing & Layout */
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 2rem;
    --space-xl: 4rem;
    --sidebar-width: 280px;
    --header-height: 72px;

    /* Typography */
    --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
}

body {
    font-family: var(--font-sans);
    background: var(--background);
    color: var(--foreground);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

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

.sidebar {
    width: var(--sidebar-width);
    background: #f8fafc;
    /* Slightly distinct from main bg */
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    padding: var(--space-md);
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 3rem;
    max-width: 1400px;
}

/* Components */
.logo {
    display: flex;
    align-items: center;
    padding: 0.5rem var(--space-md);
    text-decoration: none;
    margin-bottom: var(--space-md);
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

.nav-item:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.nav-item.active {
    background: var(--secondary);
    color: var(--secondary-foreground);
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    background: var(--primary);
    color: var(--primary-foreground);
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--text-sm);
    line-height: 1.5;
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

.btn-outline:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

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

/* Typography Helpers */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0 0 1rem 0;
    font-weight: 600;
    color: var(--foreground);
}

p {
    line-height: 1.6;
    color: #4b5563;
    /* slightly lighter than foreground */
    margin-bottom: 1rem;
}

/* 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(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.widget-card:hover {
    transform: translateY(-2px);
    border-color: var(--ring);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge-simple {
    background: var(--secondary);
    color: var(--secondary-foreground);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.badge-extended {
    background: #dcfce7;
    color: #166534;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

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

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: var(--text-sm);
    color: var(--foreground);
}

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

.form-control:focus {
    outline: none;
    background: var(--background);
    border-color: var(--ring);
    box-shadow: 0 0 0 2px var(--accent);
}

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

.form-group small {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--muted-foreground);
}


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


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

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

.widget-type-card:hover {
    border-color: var(--ring);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

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

.widget-type-card input[type="radio"] {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

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

.widget-type-summary {
    color: var(--muted-foreground);
    font-size: 0.9rem;
    margin: 0 0 1rem 0;
    flex: 1;
    min-height: 3rem; /* Ensure equal height for 2 lines of text */
}

.learn-more-btn {
    background: none;
    border: none;
    color: var(--primary);
    /* using primary for link color */
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.widget-type-details {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--muted-foreground);
    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: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
}

.code-editor {
    flex: 1;
    overflow: auto;
    background: #0f172a;
    /* Slate 900 for editor bg */
    color: #e2e8f0;
    font-family: 'JetBrains Mono', 'Fira Code', 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: #64748b;
    font-style: italic;
}

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

.code-attr {
    color: #a78bfa;
}

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

.code-editable {
    background: rgba(251, 191, 36, 0.15);
    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: #fefce8;
    border: 1px solid #fde047;
    border-radius: var(--radius);
    color: #854d0e;
    margin-bottom: 0.5rem;
    font-size: var(--text-sm);
}

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

.modal-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.95);
    animation: scaleIn 0.15s ease-out forwards;
    border: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0 0 0.75rem 0;
    color: var(--foreground);
    font-size: 1.25rem;
}

.modal-body p {
    color: var(--muted-foreground);
    line-height: 1.6;
    margin: 0 0 2rem 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Landing Page - Benefits Grid Responsive */
@media (max-width: 768px) {
    .benefits-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Auth Pages Responsive */
.auth-container {
    max-width: 400px;
    margin: 4rem auto;
    padding: 0 1rem;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 640px) {
    .auth-container {
        margin: 2rem auto;
    }
    
    .card {
        padding: 1.5rem;
    }
}