/* ===========================================
   Main Styles - Genemond Diamond Painting Tool
   =========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');
@import './variables.css';
@import './components.css';

/* Reset & Base Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    line-height: 1.6;
    /* Generous line height */
    letter-spacing: -0.01em;
    /* Modern, tight letter spacing */
}

/* Custom Scrollbar - Minimal & Clean */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Selection */
::selection {
    background: var(--color-primary-subtle);
    color: var(--color-primary-dark);
}

/* ===========================================
   App Layout
   =========================================== */

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-primary);
}

/* Custom Title Bar */
.titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    background: var(--bg-secondary);
    /* No border, just subtle separation potentially or very light border */
    border-bottom: 1px solid var(--border-subtle);
    /* Removed -webkit-app-region: drag; as this is now a web app */
    user-select: none;
    padding: 0 var(--space-6);
    z-index: var(--z-sticky);
}

.titlebar-logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.titlebar-logo .logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-lg);
    color: white;
    /* Ensure icon stays white */
    box-shadow: var(--shadow-sm);
}

.titlebar-logo h1 {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.titlebar-controls {
    display: flex;
    gap: var(--space-2);
}

.titlebar-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    /* Lighter default state */
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius-sm);
}

.titlebar-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.titlebar-btn.close:hover {
    background: var(--color-error);
    color: white;
}

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ===========================================
   Sidebar
   =========================================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    /* Distinct surface */
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--z-base);
}

.sidebar-header {
    padding: var(--space-6);
    /* No border, use spacing for separation */
    margin-bottom: var(--space-2);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-6) var(--space-6);
}

.sidebar-section {
    margin-bottom: var(--space-8);
    /* Generous spacing */
}

.sidebar-section-title {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    /* Muted label */
    margin-bottom: var(--space-4);
}

/* ===========================================
   Canvas Area
   =========================================== */

.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    /* Soft gray/white base */
    position: relative;
    overflow: hidden;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-6);
    background: transparent;
    /* Float over base */
    z-index: 10;
}

.canvas-toolbar-group {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.canvas-container {
    flex: 1;
    display: flex;
    padding: var(--space-8);
    overflow: auto;
    position: relative;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow-xl);
    /* Elevated surface */
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: white;
    /* No heavy border */
    border: 1px solid rgba(0, 0, 0, 0.02);
    transition: box-shadow var(--transition-slow);
    width: fit-content;
    flex-shrink: 0;
    margin: auto;
}

#preview-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-12);
    text-align: center;
    margin: auto;
    width: 100%;
    max-width: 480px;
}

.empty-state-icon {
    width: 96px;
    height: 96px;
    background: var(--bg-secondary);
    border-radius: var(--radius-2xl);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    margin-bottom: var(--space-8);
    color: var(--text-tertiary);
    box-shadow: var(--shadow-sm);
    /* Subtle lift */
    transition: all var(--transition-base);
}

.empty-state:hover .empty-state-icon {
    box-shadow: var(--shadow-md);
    color: var(--color-primary);
}

.empty-state h2 {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-3);
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: var(--space-8);
    font-weight: var(--font-normal);
}

/* Drop Zone */
.drop-zone {
    position: absolute;
    inset: var(--space-6);
    border: 2px dashed var(--color-primary-light);
    border-radius: var(--radius-xl);
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
    z-index: var(--z-dropdown);
    backdrop-filter: blur(4px);
}

.drop-zone.active {
    opacity: 1;
    visibility: visible;
}

.drop-zone-icon {
    font-size: 48px;
    margin-bottom: var(--space-4);
    animation: bounce 1s infinite;
    color: var(--color-primary);
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* ===========================================
   Legend Panel
   =========================================== */

.legend-panel {
    width: var(--legend-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.legend-header {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
}

.legend-header h3 {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.legend-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-1);
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.legend-item:hover {
    background: var(--bg-tertiary);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(0, 0, 0, 0.1);
    /* Subtle definition */
    flex-shrink: 0;
}

.legend-symbol {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: var(--font-bold);
    font-family: var(--font-mono);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.legend-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.legend-hex {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-tertiary);
}

.legend-count {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: var(--font-medium);
}

/* ===========================================
   Footer
   =========================================== */

.footer {
    height: var(--footer-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: 0 var(--space-6);
}

/* ===========================================
   Animations
   =========================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn var(--transition-base) forwards;
}

.animate-slide-in-left {
    animation: slideInLeft var(--transition-slow) forwards;
}

.animate-slide-in-up {
    animation: slideInUp var(--transition-slow) forwards;
}

/* Utilities */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: var(--space-2);
}

.gap-4 {
    gap: var(--space-4);
}

/* Typography improvements */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    margin: 0;
}

/* ===========================================
   Responsive Design
   =========================================== */

@media (max-width: 1200px) {
    :root {
        --sidebar-width: 240px;
        --legend-width: 220px;
    }
}

@media (max-width: 1024px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    #app {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .main-container {
        flex-direction: column;
        overflow-y: visible;
        overflow-x: hidden;
        height: auto;
        min-height: calc(100vh - var(--header-height) - var(--footer-height));
    }

    .main-container>div {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .sidebar,
    .legend-panel {
        width: 100% !important;
        height: auto !important;
        max-height: none;
        border: none;
        border-bottom: 1px solid var(--border-subtle);
        overflow: visible;
    }

    .sidebar {
        order: 2;
    }

    .sidebar-content {
        overflow: visible;
        max-height: none;
    }

    .canvas-area {
        order: 1;
        min-height: 50vh;
        flex: none;
        overflow: visible;
    }

    .canvas-container {
        min-height: 300px;
        overflow: auto;
    }

    .legend-panel {
        order: 3;
        border-bottom: none;
        border-top: 1px solid var(--border-subtle);
    }

    .legend-content {
        max-height: 300px;
        overflow-y: auto;
    }

    .canvas-toolbar {
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        backdrop-filter: blur(8px);
        padding: var(--space-2) var(--space-4);
        z-index: var(--z-sticky);
    }

    .footer {
        position: sticky;
        bottom: 0;
        z-index: var(--z-sticky);
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: 52px;
        --footer-height: 56px;
    }

    html {
        font-size: 15px;
    }

    .titlebar {
        padding: 0 var(--space-3);
        flex-wrap: wrap;
        height: auto;
        min-height: var(--header-height);
        gap: var(--space-2);
        padding-top: var(--space-2);
        padding-bottom: var(--space-2);
    }

    .titlebar-logo {
        flex-shrink: 0;
    }

    .titlebar-logo h1 {
        display: none;
    }

    .titlebar-controls {
        gap: var(--space-1);
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .btn span {
        display: none;
    }

    /* Keep upgrade button text visible on mobile - important CTA */
    .btn-gold span {
        display: inline;
    }

    .btn {
        padding: var(--space-2);
        min-width: 36px;
        min-height: 36px;
    }

    .btn svg {
        flex-shrink: 0;
    }


    .premium-badge-wrapper span {
        display: none;
    }

    .premium-badge-wrapper {
        padding: var(--space-2) !important;
    }

    /* User pill mobile adjustments */
    .user-pill span {
        display: none;
    }

    .user-pill {
        padding: var(--space-1) var(--space-2) !important;
    }

    .footer {
        padding: var(--space-2) var(--space-3);
        gap: var(--space-2);
        height: auto;
        min-height: var(--footer-height);
    }

    .footer .btn {
        flex: 1;
        min-width: auto;
    }

    .footer .btn span {
        display: inline;
        font-size: var(--text-xs);
    }

    .zoom-value {
        display: none;
    }

    .zoom-controls {
        padding: 2px;
    }

    .zoom-btn {
        width: 32px;
        height: 32px;
    }

    /* Canvas toolbar mobile */
    .canvas-toolbar {
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-2);
    }

    .canvas-toolbar-group {
        gap: var(--space-2);
    }

    /* Sidebar mobile adjustments */
    .sidebar-header {
        padding: var(--space-4);
    }

    .sidebar-content {
        padding: 0 var(--space-4) var(--space-4);
    }

    .sidebar-section {
        margin-bottom: var(--space-4);
    }

    .sidebar-section-title {
        margin-bottom: var(--space-3);
    }

    /* Empty state mobile */
    .empty-state {
        padding: var(--space-6);
    }

    .empty-state-icon {
        width: 72px;
        height: 72px;
        font-size: 32px;
        margin-bottom: var(--space-6);
    }

    .empty-state h2 {
        font-size: var(--text-lg);
    }

    .empty-state p {
        font-size: var(--text-sm);
    }

    /* Legend panel mobile */
    .legend-header {
        padding: var(--space-3) var(--space-4);
    }

    .legend-content {
        padding: var(--space-3);
        max-height: 250px;
    }

    .legend-item {
        padding: var(--space-2);
        gap: var(--space-2);
    }

    /* Canvas wrapper mobile */
    .canvas-wrapper {
        margin: var(--space-2);
        border-radius: var(--radius-md);
    }

    .canvas-container {
        padding: var(--space-4);
    }
}

@media (max-width: 480px) {
    :root {
        --header-height: 48px;
        --footer-height: 52px;
    }

    html {
        font-size: 14px;
    }

    .titlebar {
        padding: var(--space-2);
    }

    .titlebar-controls {
        width: 100%;
        justify-content: space-between;
        order: 2;
    }

    .titlebar-logo {
        order: 1;
    }

    .btn {
        padding: var(--space-1) var(--space-2);
        min-width: 32px;
        min-height: 32px;
    }

    .btn-lg {
        padding: var(--space-2) var(--space-3);
    }

    /* Sidebar mobile - even more compact */
    .sidebar-header {
        padding: var(--space-3);
    }

    .sidebar-content {
        padding: 0 var(--space-3) var(--space-3);
    }

    /* Range sliders touch-friendly */
    .range-slider {
        height: 6px;
    }

    .range-slider::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    /* Toggle touch-friendly */
    .toggle {
        width: 48px;
        height: 28px;
    }

    .toggle-thumb {
        width: 24px;
        height: 24px;
    }

    .toggle input:checked~.toggle-thumb {
        transform: translateX(20px);
    }

    /* Input fields touch-friendly */
    .input {
        padding: var(--space-3);
        font-size: var(--text-base);
        min-height: 44px;
    }

    select.input {
        min-height: 44px;
    }

    /* Footer export button */
    .footer .btn {
        font-size: var(--text-sm);
    }

    /* Canvas area adjustments */
    .canvas-container {
        padding: var(--space-2);
        min-height: 250px;
    }

    .canvas-area {
        min-height: 40vh;
    }

    /* Empty state even more compact */
    .empty-state {
        padding: var(--space-4);
    }

    .empty-state-icon {
        width: 56px;
        height: 56px;
        font-size: 24px;
        margin-bottom: var(--space-4);
    }

    /* Grid settings - stack columns on very small screens */
    .sidebar-section>div[style*="grid-template-columns: 1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
        gap: var(--space-4) !important;
    }

    /* Legend items more compact */
    .legend-item {
        font-size: var(--text-xs);
    }

    .legend-color {
        width: 18px;
        height: 18px;
    }

    .legend-symbol {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }

    /* Modals full-width on very small screens */
    .modal {
        width: 95%;
        margin: var(--space-2);
        padding: var(--space-4);
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-body {
        margin-bottom: var(--space-4);
    }

    .modal-footer {
        flex-direction: column;
        gap: var(--space-2);
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Height-based adjustments */
@media (max-height: 700px) {
    .sidebar-section {
        margin-bottom: var(--space-4);
    }
}

@media (max-height: 600px) {
    .sidebar-section {
        margin-bottom: var(--space-3);
    }

    .range-group {
        margin-bottom: var(--space-4);
    }

    .input-group {
        margin-bottom: var(--space-3);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .zoom-btn {
        min-width: 40px;
        min-height: 40px;
    }

    .toggle {
        width: 52px;
        height: 30px;
    }

    .toggle-thumb {
        width: 26px;
        height: 26px;
    }

    .toggle input:checked~.toggle-thumb {
        transform: translateX(22px);
    }

    /* Prevent hover states from sticking */
    .btn:hover:not(:active) {
        background: inherit;
    }

    .btn-primary:hover:not(:active) {
        background: var(--color-premium);
    }

    .btn-secondary:hover:not(:active) {
        background: white;
        color: var(--text-secondary);
    }

    .btn-gold:hover:not(:active) {
        background: linear-gradient(135deg, var(--color-gold) 0%, var(--color-gold-dark) 100%);
    }

    .btn-export:hover:not(:active) {
        background: var(--color-export);
    }
}

/* Landscape phone orientation */
@media (max-height: 500px) and (orientation: landscape) {
    .main-container {
        flex-direction: row;
    }

    .main-container>div {
        flex-direction: row;
    }

    .sidebar {
        width: 200px !important;
        max-width: 30%;
        order: 1;
        border-right: 1px solid var(--border-subtle);
        border-bottom: none;
    }

    .canvas-area {
        order: 2;
        flex: 1;
        min-height: auto;
    }

    .legend-panel {
        display: none;
    }

    .sidebar-content {
        max-height: calc(100vh - var(--header-height) - var(--footer-height) - 80px);
        overflow-y: auto;
    }
}

.user-pill:hover {
    border-color: var(--color-primary-light) !important;
    background: var(--bg-primary) !important;
}