:root {
    /* Minimalist Palette */
    --primary-color: #333333;
    --primary-hover: #000000;
    --secondary-color: #f8f9fa;
    --text-main: #333333;
    --text-secondary: #666666;
    --bg-color: #ffffff;
    --card-bg: #ffffff;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 10px 15px rgba(0, 0, 0, 0.08);

    /* Radius */
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 6px;

    /* Legacy Compatibility */
    --bg-gradient-start: #ffffff;
    --bg-gradient-end: #f8f9fa;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    background: #ffffff;
    color: var(--text-main);
    min-height: 100vh;
}

/* --- Common Components --- */

button,
.btn {
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* Legacy Button Support (Main Page) */
button:not(.btn-text):not(.page-btn) {
    background: var(--primary-color);
    color: white;
    padding: 14px 28px;
    border-radius: 9999px;
    /* Pill shape */
    font-size: 1rem;
    font-weight: 600;
    width: auto;
    /* Changed from 100% to auto for flexibility */
    box-shadow: var(--shadow-sm);
}

button:not(.btn-text):not(.page-btn):hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Modern Button Classes */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 107, 129, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary,
.secondary-btn {
    background: white;
    color: var(--text-main);
    border: 1px solid #e9ecef;
    box-shadow: var(--shadow-sm);
}

.secondary-btn {
    /* Specific to Home Page legacy class */
    border-radius: 9999px;
    margin-top: 1rem;
    width: 100%;
}

.btn-secondary:hover,
.secondary-btn:hover {
    background: #f8f9fa;
    border-color: #dee2e6;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-danger {
    background: #fff5f5;
    color: #e03131;
    border: 1px solid #ffe3e3;
}

.btn-danger:hover {
    background: #ffe3e3;
}

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
    box-shadow: none !important;
}

.btn-text:hover {
    color: var(--primary-color);
    transform: none !important;
}

/* --- Home Page Specifics (.container) --- */
body>.container {
    /* Selector specific to index.html container */
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 420px;
    width: 90%;
    margin: 40px auto;
    display: block;
    /* Overrides flex centering if body had it */
}

/* Home Page Typography */
.container .logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 10px;
    font-size: 0;
}

.container h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.container p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 2rem;
    padding: 6px;
    background: #f1f3f5;
    border-radius: var(--radius-md);
    position: relative;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.mode-item {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 0.95rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.mode-item.active {
    background: white;
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mode-item:hover:not(.active) {
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-main);
}

/* File Upload */
.file-upload-wrapper {
    margin: 1.5rem 0;
    position: relative;
}

.file-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    background-color: #f9fafb;
    border: 2px dashed #e5e7eb;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    min-height: 200px;
}

.file-upload-label:hover {
    border-color: var(--primary-color);
    background-color: #fff0f5;
}

.file-upload-icon {
    width: 32px;
    height: 32px;
    color: #9ca3af;
    transition: color 0.2s;
}

.file-upload-label:hover .file-upload-icon {
    color: var(--primary-color);
}

.file-upload-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input[type="file"] {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

.upload-preview {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #f9fafb;
    padding: 10px;
}

.upload-preview.show {
    display: block;
}

.file-upload-label.has-image .upload-placeholder {
    visibility: hidden;
}

.file-upload-label.has-image {
    border-style: solid;
    border-color: var(--primary-color);
    padding: 0;
}

/* Result Box */
#result {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    background-color: #f8fafc;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-main);
    line-height: 1.6;
    white-space: pre-wrap;
    text-align: left;
    border: 1px solid #f1f3f5;
    display: none;
    /* Hidden by default */
}

#result:not(:empty) {
    display: block;
    /* Show only when content exists */
}

.turnstile-container {
    margin: 1.5rem 0;
    display: flex;
    justify-content: center;
}

/* --- Dashboard / Images Page Layout --- */

.dashboard-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px;
}

/* Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding: 20px 30px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 20px;
    z-index: 100;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-name {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Action Bar */
.action-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: white;
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    border: 1px solid #e9ecef;
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 129, 0.1);
}

.custom-select,
.custom-date {
    border: none;
    outline: none;
    background: transparent;
    padding: 8px 12px;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
}

/* Image Grid */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    padding-bottom: 60px;
}

.image-card {
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    cursor: pointer;
    border: 2px solid transparent;
}

.image-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.image-card.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(255, 107, 129, 0.1);
}

.image-wrapper {
    position: relative;
    padding-top: 100%;
    /* 1:1 Aspect Ratio */
    background: #f1f3f5;
    overflow: hidden;
}

.image-wrapper img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.image-card:hover .image-wrapper img {
    transform: scale(1.05);
}

.score-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary-color);
    font-weight: 800;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 1.1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
}

.card-info {
    padding: 16px;
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.info-time {
    font-size: 0.85rem;
    color: #adb5bd;
    font-weight: 500;
}

.info-tags {
    display: flex;
    gap: 8px;
}

.tag {
    background: #f8f9fa;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Selection and States */
.selection-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    border: 2px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
    z-index: 10;
}

.image-card.deleting .selection-overlay {
    opacity: 1;
}

.image-card.selected .selection-overlay {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.image-card.selected .selection-overlay::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.state-container {
    text-align: center;
    padding: 60px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Minimalist Redesign (App-like) --- */

.images-page {
    background-color: #ffffff;
    /* Cleaner white background */
}

.app-layout {
    max-width: 100%;
    margin: 0 auto;
    min-height: 100vh;
    padding-top: 60px;
    /* Space for fixed header */
    padding-bottom: 80px;
    /* Space for bottom bar protection */
}

/* App Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    z-index: 1000;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.header-left,
.header-right {
    flex: 1;
    display: flex;
    align-items: center;
}

.header-right {
    justify-content: flex-end;
}

.header-center {
    flex: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.app-title {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    color: #000;
    line-height: 1.2;
}

.subtitle-count {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-btn {
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: background 0.2s;
}

.nav-btn:active {
    background: #f1f3f5;
}

.text-btn {
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-size: 16px;
    font-weight: 600;
    padding: 8px 12px;
    cursor: pointer;
}

.text-btn:active {
    opacity: 0.7;
}

/* Minimalist Grid */
.minimalist-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 3 columns on mobile standard */
    gap: 2px;
    /* Very tight gap like Photos app */
    padding: 0;
    /* Edge to edge */
}

@media (min-width: 768px) {
    .minimalist-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 16px;
        padding: 24px;
        max-width: 1200px;
        margin: 0 auto;
    }

    .app-layout {
        padding-top: 80px;
    }

    .app-header {
        height: 80px;
        padding: 0 32px;
    }

    .app-title {
        font-size: 20px;
    }
}

.minimalist-grid .image-card {
    border-radius: 0;
    /* Square edges on mobile grid */
    box-shadow: none;
    border: none;
    aspect-ratio: 1;
}

@media (min-width: 768px) {
    .minimalist-grid .image-card {
        border-radius: 12px;
        /* Rounded on desktop */
    }
}

.minimalist-grid .card-info,
.minimalist-grid .score-badge {
    display: none;
    /* Hide metadata in grid view for cleanliness */
}

/* Specific overlay for minimalist grid score (optional: maybe just show image) */
/* Specific overlay for minimalist grid score (optional: maybe just show image) */
/* .minimalist-grid .image-wrapper::after { } */

/* Selection State in Minimalist Grid */
.image-card .selection-overlay {
    top: 6px;
    right: 6px;
    /* Move to right */
    left: auto;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.2);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.image-card.selected .selection-overlay {
    background: var(--primary-color);
    border-color: white;
}

.image-card.deleting .image-wrapper {
    transform: scale(0.9);
    /* Shrink slightly when in edit mode to show selection better */
    transition: transform 0.2s;
}

.image-card.selected .image-wrapper {
    opacity: 0.7;
}

/* Bottom Action Bar */
.bottom-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding: 16px 24px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
}

.bottom-action-bar.visible {
    transform: translateY(0);
}

.bar-content {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#selection-count {
    font-weight: 500;
    color: var(--text-main);
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn.delete {
    background: #fff5f5;
    color: #e03131;
}

.action-btn:disabled {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .dashboard-container {
        padding: 16px;
    }

    .dashboard-header {
        position: relative;
        top: 0;
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
        padding: 16px;
    }

    .user-profile {
        width: 100%;
        justify-content: space-between;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        justify-content: space-between;
    }

    .input-wrapper {
        flex: 1;
    }

    body>.container {
        padding: 24px;
        width: 95%;
    }
}