﻿/* ========================================
   Apple-Inspired Design System
   Optimized for Desktop Browsers with Sidebar Layout
   ======================================== */

:root {
    /* Apple-inspired Color Palette */
    --color-primary: #007AFF;
    --color-primary-hover: #0051D5;
    --color-success: #34C759;
    --color-danger: #FF3B30;
    --color-warning: #FF9500;
    /* Neutral Grays */
    --color-text-primary: #1d1d1f;
    --color-text-secondary: #6e6e73;
    --color-text-tertiary: #86868b;
    --color-border: #d2d2d7;
    --color-border-light: #e5e5ea;
    --color-background: #fbfbfd;
    --color-surface: #ffffff;
    --color-surface-elevated: #ffffff;
    /* Canvas Background */
    --color-canvas-background: #e8f5e9;
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.04);
    /* Typography */
    --font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
    /* Spacing Scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    /* Sidebar */
    --sidebar-width: 420px;
}

/* ========================================
   Base Styles
   ======================================== */

body {
    font-family: var(--font-system);
    background: var(--color-background);
    color: var(--color-text-primary);
    line-height: 1.5;
    margin: 0;
    padding: 0;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

@media (min-width: 769px) {
    body:has(.app-layout) {
        overflow: hidden; /* only app pages become non-scrolling shells */
    }

    .app-layout {
        height: 100dvh; /* already present below; keeping for clarity */
    }
}

* {
    box-sizing: border-box;
}

/* ========================================
   App Layout (Sidebar + Canvas)
   ======================================== */

.app-layout {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border-light);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.sidebar-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-surface-elevated);
    position: sticky;
    top: 0;
    z-index: 100;
}

    .sidebar-header h1 {
        font-size: 1.75rem;
        font-weight: 700;
        letter-spacing: -0.02em;
        color: var(--color-text-primary);
        margin: 0 0 var(--space-xs) 0;
        line-height: 1.1;
    }

    .sidebar-header p {
        margin: 0;
        font-size: 0.875rem;
    }

/* ========================================
   Upload Section
   ======================================== */

.upload-section {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-background);
}

.upload-status {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

    .upload-status.success {
        background: rgba(52, 199, 89, 0.06);
        border-color: rgba(52, 199, 89, 0.3);
        color: var(--color-success);
    }

        .upload-status.success strong {
            display: block;
            font-weight: 600;
            margin-bottom: var(--space-xs);
            color: var(--color-success);
        }

.status-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

/* ========================================
   Controls Section
   ======================================== */
/* ========================================
   Top Navigation (macOS Style)
   ======================================== */

.top-nav {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 9999;
}

.nav-toggle {
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 0.5px solid rgba(0, 0, 0, 0.04);
    border-radius: var(--radius-md);
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all var(--transition-base);
}

    .nav-toggle:hover {
        background: rgba(255, 255, 255, 0.85);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
        transform: scale(1.02);
    }

    .nav-toggle:active {
        transform: scale(0.98);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    }

.hamburger {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--color-text-primary);
    position: relative;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 1px;
}

    .hamburger::before,
    .hamburger::after {
        content: '';
        position: absolute;
        width: 18px;
        height: 2px;
        background: var(--color-text-primary);
        left: 0;
        transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 1px;
    }

    .hamburger::before {
        top: -5px;
    }

    .hamburger::after {
        top: 5px;
    }

.top-nav.expanded .hamburger {
    background: transparent;
}

    .top-nav.expanded .hamburger::before {
        transform: rotate(45deg);
        top: 0;
    }

    .top-nav.expanded .hamburger::after {
        transform: rotate(-45deg);
        top: 0;
    }

.nav-links {
    position: absolute;
    top: 44px;
    right: 0;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 0.5px solid rgba(0, 0, 0, 0.04);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);
    min-width: 180px;
    overflow: hidden;
    animation: menuFadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes menuFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px 16px;
    color: var(--color-text-primary);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 400;
    transition: background var(--transition-fast);
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.04);
}

    .nav-links a:last-child {
        border-bottom: none;
    }

    .nav-links a:hover {
        background: rgba(0, 122, 255, 0.08);
    }

    .nav-links a:active {
        background: rgba(0, 122, 255, 0.12);
    }

    /* Emoji spacing for nav items */
    .nav-links a::first-letter {
        font-size: 1.1em;
    }

.controls {
    flex: 1;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0 0 var(--space-md) 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.group-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0 0 var(--space-sm) 0;
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--color-border-light);
}

.controls label {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary);
    cursor: pointer;
    position: relative;
}

    /* Parameter Descriptions */
    .controls label::after {
        content: attr(title);
        display: block;
        font-size: 0.6875rem;
        font-weight: 400;
        color: var(--color-text-tertiary);
        line-height: 1.4;
    }

    /* Remove default title tooltips since we're showing them inline */
    .controls label[title]:hover::before {
        content: none;
    }

/* ========================================
   Input Fields
   ======================================== */

.controls input[type="number"],
.controls input[type="text"] {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9375rem;
    font-family: var(--font-system);
    color: var(--color-text-primary);
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: all var(--transition-base);
    outline: none;
}

    .controls input[type="number"]:hover:not(:disabled),
    .controls input[type="text"]:hover:not(:disabled) {
        border-color: var(--color-text-tertiary);
    }

    .controls input[type="number"]:focus,
    .controls input[type="text"]:focus {
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
    }

    .controls input[type="number"]:disabled,
    .controls input[type="text"]:disabled {
        background: var(--color-background);
        color: var(--color-text-tertiary);
        cursor: not-allowed;
        opacity: 0.6;
    }

/* Checkbox Styling */
.controls input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.controls label:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: var(--space-sm);
}

    .controls label:has(input[type="checkbox"])::after {
        margin-left: 26px;
    }

/* ========================================
   Actions Section
   ======================================== */

.actions {
    padding: var(--space-lg);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-background);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    position: sticky;
    bottom: 0;
}

/* ========================================
   Buttons
   ======================================== */

button {
    padding: var(--space-md) var(--space-lg);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: var(--font-system);
    color: var(--color-surface);
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
    text-align: center;
}

    button:hover:not(:disabled) {
        background: var(--color-primary-hover);
        box-shadow: var(--shadow-md);
        transform: translateY(-1px);
    }

    button:active:not(:disabled) {
        transform: translateY(0);
        box-shadow: var(--shadow-sm);
    }

    button:disabled {
        background: var(--color-border);
        color: var(--color-text-tertiary);
        cursor: not-allowed;
        box-shadow: none;
        transform: none;
    }

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

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

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

    .btn-success:hover:not(:disabled) {
        background: #2ba548;
    }

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

    .btn-danger:hover:not(:disabled) {
        background: #cc2e25;
    }

/* ========================================
   File Upload
   ======================================== */

input[type="file"] {
    width: 100%;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
}

    input[type="file"]::file-selector-button {
        padding: var(--space-sm) var(--space-lg);
        font-size: 0.875rem;
        font-weight: 500;
        font-family: var(--font-system);
        color: var(--color-primary);
        background: rgba(0, 122, 255, 0.06);
        border: 1.5px solid var(--color-primary);
        border-radius: var(--radius-sm);
        cursor: pointer;
        transition: all var(--transition-base);
        margin-right: var(--space-md);
    }

        input[type="file"]::file-selector-button:hover {
            background: rgba(0, 122, 255, 0.12);
            border-color: var(--color-primary-hover);
        }

/* ========================================
   Canvas Area
   ======================================== */

.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-canvas-background);
    overflow: hidden;
    position: relative;
}

.canvas-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

canvas {
    border: 1px solid var(--color-border-light) !important;
    border-radius: var(--radius-lg) !important;
    display: block !important;
    box-shadow: var(--shadow-lg) !important;
    background: var(--color-surface) !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
}

/* ========================================
   Canvas Placeholder
   ======================================== */

.canvas-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.placeholder-content {
    text-align: center;
    max-width: 400px;
    padding: var(--space-2xl);
    color: var(--color-text-tertiary);
}

    .placeholder-content svg {
        color: var(--color-border);
        margin-bottom: var(--space-xl);
    }

    .placeholder-content h2 {
        font-size: 1.5rem;
        font-weight: 600;
        color: var(--color-text-secondary);
        margin: 0 0 var(--space-md) 0;
    }

    .placeholder-content p {
        font-size: 0.9375rem;
        color: var(--color-text-tertiary);
        line-height: 1.6;
        margin: 0;
    }

/* ========================================
   Status & Loading
   ======================================== */

.gen-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: rgba(0, 122, 255, 0.06);
    border: 1px solid rgba(0, 122, 255, 0.2);
    border-radius: var(--radius-md);
    color: var(--color-primary);
    font-weight: 500;
    font-size: 0.875rem;
    margin: var(--space-lg);
    margin-top: 0;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2.5px solid rgba(0, 122, 255, 0.2);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   Debug Information
   ======================================== */

.debug {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: var(--color-background);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    margin: var(--space-lg);
    color: var(--color-text-secondary);
    line-height: 1.6;
}

    .debug > div {
        padding: var(--space-xs) 0;
        border-bottom: 1px solid var(--color-border-light);
    }

        .debug > div:last-child {
            border-bottom: none;
        }

/* ========================================
   Typography Utilities
   ======================================== */

code {
    color: var(--color-primary);
    background: rgba(0, 122, 255, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.text-muted {
    color: var(--color-text-secondary);
}

.text-small {
    font-size: 0.875rem;
}

/* ========================================
   Validation States
   ======================================== */

.valid.modified:not([type=checkbox]) {
    border-color: var(--color-success) !important;
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.1) !important;
}

.invalid {
    border-color: var(--color-danger) !important;
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.1) !important;
}

.validation-message {
    color: var(--color-danger);
    font-size: 0.75rem;
    margin-top: var(--space-xs);
    font-weight: 500;
}

/* ========================================
   Blazor Error UI
   ======================================== */

#blazor-error-ui {
    background: var(--color-surface-elevated);
    border-top: 2px solid var(--color-danger);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    bottom: 0;
    display: none;
    left: 0;
    padding: var(--space-md) var(--space-lg);
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: var(--color-danger);
    font-weight: 500;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: var(--space-lg);
        top: 50%;
        transform: translateY(-50%);
        font-size: 1.25rem;
        opacity: 0.7;
        transition: opacity var(--transition-fast);
    }

        #blazor-error-ui .dismiss:hover {
            opacity: 1;
        }

.blazor-error-boundary {
    background: linear-gradient(135deg, #FF3B30 0%, #cc2e25 100%);
    padding: var(--space-lg) var(--space-lg) var(--space-lg) var(--space-2xl);
    color: white;
    border-radius: var(--radius-md);
    margin: var(--space-lg);
    box-shadow: var(--shadow-lg);
    position: relative;
}

    .blazor-error-boundary::before {
        content: "⚠";
        position: absolute;
        left: var(--space-lg);
        top: 50%;
        transform: translateY(-50%);
        font-size: 1.5rem;
    }

    .blazor-error-boundary::after {
        content: "An error has occurred.";
        font-weight: 600;
    }

/* ========================================
   Loading Progress
   ======================================== */

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto var(--space-lg) auto;
}

    .loading-progress circle {
        fill: none;
        stroke: var(--color-border);
        stroke-width: 0.5rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: var(--color-primary);
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 600;
    color: var(--color-text-primary);
    inset: calc(20vh + 3.5rem) 0 auto 0;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }

/* ========================================
   Form Floating (Bootstrap compatibility)
   ======================================== */

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--color-text-tertiary);
    text-align: end;
    transition: all var(--transition-base);
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 320px;
    }
}

@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border-light);
    }

    .canvas-area {
        min-height: 50vh;
    }
}

/* ========================================
   Utility Classes
   ======================================== */

.mt-0 {
    margin-top: 0 !important;
}

.mt-1 {
    margin-top: var(--space-xs) !important;
}

.mt-2 {
    margin-top: var(--space-sm) !important;
}

.mt-3 {
    margin-top: var(--space-md) !important;
}

.mt-4 {
    margin-top: var(--space-lg) !important;
}

.mt-5 {
    margin-top: var(--space-xl) !important;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mb-1 {
    margin-bottom: var(--space-xs) !important;
}

.mb-2 {
    margin-bottom: var(--space-sm) !important;
}

.mb-3 {
    margin-bottom: var(--space-md) !important;
}

.mb-4 {
    margin-bottom: var(--space-lg) !important;
}

.mb-5 {
    margin-bottom: var(--space-xl) !important;
}

/* Desktop: keep full-height layout but use dynamic viewport units to avoid iOS bars issues */
@media (min-width: 769px) {
    body {
        overflow: hidden;
    }

    .app-layout {
        height: 100dvh;
    }
    /* overrides base 100vh */
}

/* Tablet and below: let the page scroll and avoid scroll traps */
@media (max-width: 1024px) {
    body {
        overflow: auto;
    }
    /* re-enable page scroll */
    .app-layout {
        height: auto; /* stop forcing full-viewport height */
        min-height: 100svh; /* still at least one viewport tall */
        overflow: visible; /* no hidden overflow */
    }

    .canvas-area {
        overflow: auto; /* allow canvas region to scroll if needed */
    }
}

/* Phone: avoid split scroll areas; make sidebar and canvas flow naturally */
@media (max-width: 768px) {
    .sidebar {
        max-height: none; /* override the 50vh cap */
        overflow: visible; /* let the page (body) handle scrolling */
    }

    .actions {
        position: sticky; /* keep actions accessible without trapping scroll */
        bottom: 0;
    }

    .canvas-area {
        flex: none;
        min-height: auto; /* let content define height */
        overflow: visible; /* rely on page scroll */
    }

    .canvas-container {
        height: auto; /* avoid 100% height without a fixed parent */
        padding: var(--space-md);
    }
}


