:root {
    --primary: #123456;
    --secondary: #abcdef;
    --accent: #789abc;
    --background: #ffffff;
    --surface: #f5f5f5;
    --text: #000000;
    --heading-font: 'Roboto', sans-serif;
    --body-font: 'Open Sans', sans-serif;
    --scale-ratio: 1.25;
    
    --focus-ring-color: #3b82f6;
    --focus-ring-style: solid;
}

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

*:focus-visible {
    outline: 3px var(--focus-ring-style) var(--focus-ring-color);
    outline-offset: 2px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #f0f2f5;
    color: #333;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    background-color: #fff;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

main {
    flex: 1;
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 2rem;
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.panel {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: fit-content;
}

.control-panel {
    grid-column: 1;
}

.preview-container {
    grid-column: 2;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    min-height: 600px;
}

.output-panel {
    grid-column: 3;
}

/* Controls */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
}

select, button {
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

button.primary-btn {
    background-color: #007bff;
    color: white;
    border: none;
    font-weight: 600;
}

button.primary-btn:hover {
    background-color: #0056b3;
}

button.secondary-btn {
    background-color: #f8f9fa;
    color: #333;
}

button.secondary-btn:hover {
    background-color: #e2e6ea;
}

.swatch {
    width: 100%;
    height: 40px;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    border: 1px solid rgba(0,0,0,0.1);
}

/* Preview Area (Simulated Website) */
#preview-frame {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--background);
    color: var(--text);
    font-family: var(--body-font);
    transition: all 0.3s ease;
}

#preview-header {
    background-color: #fff; /* Will be overridden by theme */
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

#preview-hero {
    padding: 4rem 2rem;
    text-align: center;
    background-color: var(--surface);
}

#preview-hero h2 {
    font-family: var(--heading-font);
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

#preview-content {
    padding: 3rem 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.preview-card {
    background-color: var(--surface);
    padding: 2rem;
    border-radius: 8px;
    margin-top: 2rem;
    border: 1px solid rgba(0,0,0,0.05);
}

.preview-btn {
    padding: 0.8rem 1.5rem;
    border-radius: 4px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    margin: 0.5rem;
}

.preview-btn-primary {
    background-color: var(--primary);
    color: white; /* Need to ensure contrast later */
}

.preview-btn-secondary {
    background-color: var(--secondary);
    color: var(--text);
}

/* Output Areas */
textarea {
    width: 100%;
    height: 150px;
    padding: 0.5rem;
    font-family: monospace;
    font-size: 0.85rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    background: #f8f9fa;
}

input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

/* History Controls */
.header-controls {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1.2rem;
}

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

/* Badges */
.badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    margin-left: 0.5rem;
    font-weight: bold;
}

.badge.pass {
    background-color: #d4edda;
    color: #155724;
}

.badge.fail {
    background-color: #f8d7da;
    color: #721c24;
}

/* Swatch Inputs */
.swatch input[type="color"] {
    border: none;
    width: 30px;
    height: 30px;
    cursor: pointer;
    background: none;
}

/* Expanded Preview */
.preview-nav a {
    margin-left: 1rem;
    text-decoration: none;
    color: inherit;
    font-weight: 600;
}

.preview-form-group {
    margin-top: 1rem;
}

.preview-form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.preview-form-group input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 4px;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    margin-top: auto;
    color: #666;
    font-size: 0.9rem;
}

footer a {
    color: #007bff;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap; /* Fix: Allow tabs to wrap */
}

.tab-btn {
    padding: 0.5rem 1rem;
    background: #eee;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
}

.tab-btn.active {
    background: #007bff;
    color: white;
}

/* Lock Button */
.lock-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.5rem;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.lock-btn:hover, .lock-btn.locked {
    opacity: 1;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 1000;
}

.toast {
    background: #333;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* --- Phase 3 Styles --- */

/* App Dark Mode */
body.dark-mode {
    background-color: #1a1a1a;
    color: #f0f0f0;
}

body.dark-mode header,
body.dark-mode .panel,
body.dark-mode .preview-container {
    background-color: #2d2d2d;
    color: #f0f0f0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

body.dark-mode label {
    color: #ccc;
}

body.dark-mode select, 
body.dark-mode button.secondary-btn,
body.dark-mode input[type="text"],
body.dark-mode textarea,
body.dark-mode .tab-btn {
    background-color: #3d3d3d;
    color: #fff;
    border-color: #555;
}

body.dark-mode .tab-btn.active {
    background-color: #007bff;
}

body.dark-mode .icon-btn {
    border-color: #555;
    color: #fff;
}

body.dark-mode #preview-header {
    border-bottom-color: rgba(255,255,255,0.1);
}

/* Saved Themes */
#saved-themes-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.saved-theme-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #ddd;
}

body.dark-mode .saved-theme-item {
    background: #3d3d3d;
    border-color: #555;
}

.saved-theme-preview {
    display: flex;
    gap: 2px;
}

.mini-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.delete-theme-btn {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

/* Preview Controls */
.preview-controls {
    padding: 1rem;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 1rem;
    background: #fafafa;
}

body.dark-mode .preview-controls {
    background: #333;
    border-color: #444;
}

#preview-frame-wrapper {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

#preview-frame {
    min-height: 100%;
}

/* Layout Specific Styles */
/* Dashboard */
.layout-dashboard {
    display: grid;
    grid-template-columns: 200px 1fr;
    grid-template-rows: 60px 1fr;
    min-height: 100%;
}

.dashboard-sidebar {
    grid-row: 1 / -1;
    background-color: var(--primary);
    color: white;
    padding: 1rem;
}

.dashboard-header {
    background-color: var(--surface);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.dashboard-content {
    padding: 2rem;
    background-color: var(--background);
}

/* Blog */
.layout-blog #preview-content {
    max-width: 700px;
    font-size: 1.1rem;
    line-height: 1.6;
}

/* E-commerce */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.product-card {
    background: var(--surface);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    overflow: hidden;
}

.product-img {
    height: 150px;
    background: var(--secondary);
    opacity: 0.5;
}

.product-info {
    padding: 1rem;
}

.product-info {
    padding: 1rem;
}

/* --- Phase 4 Styles --- */

/* Smooth Transitions */
:root {
    transition: --primary 0.3s ease, --secondary 0.3s ease, --accent 0.3s ease, --background 0.3s ease, --surface 0.3s ease, --text 0.3s ease;
}

#preview-frame * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Vibe Sliders */
.slider-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.slider-group input[type="range"] {
    width: 60%;
}

/* Typography Controls */
.font-control {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.font-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f0f0f0;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

body.dark-mode .font-display {
    background: #3d3d3d;
}

@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
    }
    .control-panel, .preview-container, .output-panel {
        grid-column: 1;
    }
}

/* --- Phase 5 Styles --- */

/* Zen Mode */
body.zen-mode header,
body.zen-mode .control-panel,
body.zen-mode .output-panel,
body.zen-mode .preview-controls {
    display: none;
}

body.zen-mode main {
    grid-template-columns: 1fr;
    height: 100vh;
    padding: 0;
}

body.zen-mode .preview-container {
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* Modal */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.5); 
    animation: fadeIn 0.3s;
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto; 
    padding: 20px;
    border: 1px solid #888;
    width: 80%; 
    max-width: 600px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    position: relative;
    animation: slideIn 0.3s;
}

body.dark-mode .modal-content {
    background-color: #2d2d2d;
    border-color: #444;
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

body.dark-mode .close-modal:hover {
    color: white;
}

#snippet-code {
    width: 100%;
    height: 200px;
    margin: 1rem 0;
    padding: 0.5rem;
    font-family: monospace;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
}

body.dark-mode #snippet-code {
    background-color: #3d3d3d;
    color: #fff;
    border-color: #555;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Interactive Preview Elements */
.interactive-element {
    cursor: pointer;
    position: relative;
}

.interactive-element:hover::after {
    content: "Source";
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 0 0 0 4px;
    pointer-events: none;
}

/* Type Scale Variables (Defaults) */
:root {
    --scale-ratio: 1.25;
    --text-base: 1rem;
    --text-lg: calc(var(--text-base) * var(--scale-ratio));
    --text-xl: calc(var(--text-lg) * var(--scale-ratio));
    --text-2xl: calc(var(--text-xl) * var(--scale-ratio));
    --text-3xl: calc(var(--text-2xl) * var(--scale-ratio));
    --text-4xl: calc(var(--text-3xl) * var(--scale-ratio));
    --text-sm: calc(var(--text-base) / var(--scale-ratio));
    --text-xs: calc(var(--text-sm) / var(--scale-ratio));
}

#preview-frame h1 { font-size: var(--text-4xl); }
#preview-frame h2 { font-size: var(--text-3xl); }
#preview-frame h3 { font-size: var(--text-2xl); }
#preview-frame h4 { font-size: var(--text-xl); }
#preview-frame p, #preview-frame li { font-size: var(--text-base); }
#preview-frame small { font-size: var(--text-sm); }

/* --- Phase 7 Styles --- */

/* Theme Name Badge */
.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.theme-name-badge {
    background: rgba(0,0,0,0.05);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #666;
    border: 1px solid rgba(0,0,0,0.1);
}

body.dark-mode .theme-name-badge {
    background: rgba(255,255,255,0.1);
    color: #ccc;
    border-color: rgba(255,255,255,0.1);
}

/* Fix Contrast Button */
.small-btn {
    padding: 0.1rem 0.4rem;
    font-size: 1rem;
    margin-left: 0.5rem;
}

/* Tour Overlay */
.tour-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    pointer-events: auto; /* Blocks clicks behind */
}

/* Highlighted Element (relative to overlay) */
.tour-highlight {
    position: relative;
    z-index: 2001;
    box-shadow: 0 0 0 4px #007bff, 0 0 0 5000px rgba(0,0,0,0.5); /* Fake overlay cutout */
    pointer-events: none; /* Allow clicks through if needed, but usually we block */
    background: white; /* Ensure visibility */
    border-radius: 4px;
}

body.dark-mode .tour-highlight {
    background: #2d2d2d;
}

.tour-box {
    position: absolute;
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    width: 300px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 2002;
    transition: all 0.3s ease;
}

body.dark-mode .tour-box {
    background: #333;
    color: white;
}

.tour-controls {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
}

.tour-controls button.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

/* Mobile Nav Fix */
@media (max-width: 600px) {
    header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .header-left {
        width: 100%;
        justify-content: space-between;
    }

    .header-controls {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }
}
