:root {
    /* macOS System Colors */
    --app-bg: rgba(255, 255, 255, 0.72);
    --sidebar-bg: rgba(246, 246, 247, 0.72);
    --content-bg: rgba(255, 255, 255, 0.92);
    --border: rgba(0, 0, 0, 0.08);
    --separator: rgba(0, 0, 0, 0.08);
    
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --text-tertiary: #bfbfbf;
    
    --accent: #007aff;
    --selection-bg: rgba(0, 122, 255, 0.14);
    --selection-border: rgba(0, 122, 255, 0.22);
    --hover-bg: rgba(0, 0, 0, 0.05);
    --chrome-bg: rgba(255, 255, 255, 0.35);
    --panel-bg: rgba(255, 255, 255, 0.35);
    
    --shadow-window: 0 24px 50px rgba(0,0,0,0.15), 0 0 1px rgba(0,0,0,0.1);
    
    --radius-window: 12px;
    --radius-btn: 8px;
    
    --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    --wallpaper: url('https://images.unsplash.com/photo-1621360841013-c768371e93cf?q=80&w=2560&auto=format&fit=crop');
    color-scheme: light;
}

:root[data-theme="dark"] {
    --app-bg: rgba(28, 28, 30, 0.72);
    --sidebar-bg: rgba(36, 36, 38, 0.72);
    --content-bg: rgba(18, 18, 20, 0.88);
    --border: rgba(255, 255, 255, 0.10);
    --separator: rgba(255, 255, 255, 0.10);

    --text-primary: #f5f5f7;
    --text-secondary: rgba(235, 235, 245, 0.6);
    --text-tertiary: rgba(235, 235, 245, 0.35);

    --accent: #0a84ff;
    --selection-bg: rgba(10, 132, 255, 0.22);
    --selection-border: rgba(10, 132, 255, 0.28);
    --hover-bg: rgba(255, 255, 255, 0.08);
    --chrome-bg: rgba(0, 0, 0, 0.25);
    --panel-bg: rgba(255, 255, 255, 0.06);

    --shadow-window: 0 24px 50px rgba(0,0,0,0.6), 0 0 1px rgba(255,255,255,0.08);
    color-scheme: dark;
}

:where([hidden]) { display: none !important; }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

body {
    background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0.55)), var(--wallpaper) no-repeat center center fixed;
    background-size: cover;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-system);
    overflow: hidden;
}

:root[data-theme="dark"] body {
    background: linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0.70)), var(--wallpaper) no-repeat center center fixed;
    background-size: cover;
}

.is-dragging-window {
    cursor: grabbing;
}

.is-dragging-window * {
    cursor: grabbing !important;
}

/* --- The "NSWindow" --- */
.mac-window {
    width: 960px;
    height: 640px;
    background: var(--app-bg);
    border-radius: var(--radius-window);
    box-shadow: var(--shadow-window);
    display: flex;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255,255,255,0.35);
    animation: windowPop 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
}

@keyframes windowPop {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* --- Sidebar --- */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border-right: 1px solid var(--separator);
    display: flex;
    flex-direction: column;
    padding-top: 52px;
}

.traffic-lights {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    gap: 8px;
    z-index: 100;
}

.light { width: 12px; height: 12px; border-radius: 50%; }
.light.close { background: #ff5f56; border: 1px solid #e0443e; }
.light.min { background: #ffbd2e; border: 1px solid #dea123; }
.light.max { background: #27c93f; border: 1px solid #1aab29; }

.nav-group { padding: 0 10px; margin-bottom: 24px; }
.nav-label { font-size: 11px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; padding-left: 10px; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 6px 10px;
    border-radius: var(--radius-btn); font-size: 13px; color: var(--text-primary);
    cursor: default; transition: background 0.1s;
}
.nav-item.active { background: var(--selection-bg); font-weight: 600; box-shadow: inset 0 0 0 1px var(--selection-border); }
.nav-item svg { width: 16px; height: 16px; color: var(--accent); }
.nav-item[role="button"] { cursor: pointer; }

/* --- Main Content --- */
.main-view {
    flex: 1;
    background: var(--content-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
}

.main-view.is-recents .toolbar-actions {
    opacity: 0;
    pointer-events: none;
}

/* Toolbar */
.toolbar {
    height: 52px;
    border-bottom: 1px solid var(--separator);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--chrome-bg);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
}

.toolbar-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.toolbar-actions { display: flex; gap: 12px; }

.btn-icon {
    width: 28px; height: 28px; border-radius: 6px;
    border: 1px solid transparent; background: transparent;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); cursor: pointer;
}
.btn-icon:hover { background: var(--hover-bg); }

@media (min-width: 769px) {
    .toolbar { cursor: grab; }
}

.btn-pill {
    border: 1px solid var(--separator);
    background: var(--chrome-bg);
    color: var(--text-primary);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
}
.btn-pill:hover { background: var(--hover-bg); }

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.view-recents {
    padding: 0;
}

.recents-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    min-height: 0;
}

.recents-page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--separator);
    background: var(--chrome-bg);
    height: 52px; /* Standard toolbar height */
    flex-shrink: 0;
}

.recents-page-actions {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Spread content */
    width: 100%;
    gap: 16px;
}

/* macOS Segmented Control */
.segmented-control {
    display: flex;
    align-items: center;
    background: rgba(118, 118, 128, 0.12);
    border-radius: 6px;
    padding: 2px;
    height: 28px;
}

:root[data-theme="dark"] .segmented-control {
    background: rgba(118, 118, 128, 0.24);
}

.btn-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 24px;
    border: none;
    background: transparent;
    border-radius: 5px;
    color: var(--text-primary);
    cursor: default;
    transition: background 0.1s, box-shadow 0.1s;
}

.btn-segment svg {
    opacity: 0.7;
}

.btn-segment.active {
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12), 0 0 0 0.5px rgba(0,0,0,0.08);
}

.btn-segment.active svg {
    opacity: 1;
    color: var(--text-primary);
}

:root[data-theme="dark"] .btn-segment.active {
    background: #636366;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.segment-separator {
    width: 1px;
    height: 14px;
    background: rgba(0,0,0,0.1);
    margin: 0 1px;
}

:root[data-theme="dark"] .segment-separator {
    background: rgba(255,255,255,0.1);
}

.btn-segment.active + .segment-separator,
.segment-separator:has(+ .btn-segment.active) {
    opacity: 0; /* Hide separator next to active item */
}


/* macOS Search Field */
.search-field {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 8px;
    border-radius: 6px; /* Standard macOS search field radius */
    background: rgba(118, 118, 128, 0.12);
    border: 1px solid transparent;
    color: var(--text-primary);
    width: 240px;
    flex: none; /* Fixed width mostly */
    transition: all 0.2s;
}

:root[data-theme="dark"] .search-field {
    background: rgba(118, 118, 128, 0.24);
}

.search-field:focus-within {
    background: var(--content-bg);
    box-shadow: 0 0 0 1px var(--accent), 0 0 0 3px var(--selection-bg);
}

.search-field .search-icon {
    color: var(--text-secondary);
    width: 13px;
    height: 13px;
    stroke-width: 2.5px;
}

.search-field input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    width: 100%;
    height: 100%;
}
.search-field input::placeholder {
    color: var(--text-secondary);
}

/* Spacer to push search to the right if needed, or keeping it grouped */
.recents-actions-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.recents-page-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: var(--content-bg);
}

/* Remove old button toggle styles */
.btn-icon-toggle.active {
    /* Removed */
}

.recent-table {
    flex: 1;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
    overflow: hidden;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    --recent-cols: 40px 1fr 140px 100px 40px;
}

.recent-table-header {
    display: grid;
    grid-template-columns: var(--recent-cols);
    align-items: center;
    gap: 10px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--separator);
    position: sticky;
    top: 0;
    z-index: 10;
}

.recent-table-header .recent-col-name,
.recent-table-header .recent-col-date,
.recent-table-header .recent-col-size {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-right: 1px solid transparent; /* Placeholder for resize handles */
    padding-left: 4px;
}

.recent-list {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: auto;
    background: transparent;
    padding-bottom: 40px;
}

.recent-empty {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    padding-bottom: 10%;
}

.recent-item {
    display: grid;
    grid-template-columns: var(--recent-cols);
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    color: var(--text-primary);
    cursor: default;
    border-bottom: 1px solid var(--separator);
    font-size: 13px;
}
.recent-item:last-child { border-bottom: none; }

.recent-item:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}
:root[data-theme="dark"] .recent-item:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.recent-item:hover {
    background: var(--hover-bg);
}

.recent-thumb {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid var(--separator);
    object-fit: cover;
    background: rgba(0,0,0,0.05);
}

.recent-name {
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 4px;
}

.recent-date,
.recent-size {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 4px;
    font-feature-settings: "tnum";
}

.recent-delete {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.1s;
}
.recent-item:hover .recent-delete { opacity: 1; }
.recent-delete:hover { background: rgba(0,0,0,0.1); color: var(--text-primary); }

/* Grid Layout */
.recent-table[data-layout="grid"] .recent-table-header {
    display: none;
}

.recent-table[data-layout="grid"] .recent-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    grid-auto-rows: max-content;
    gap: 20px 16px;
    padding: 20px;
    align-content: start;
}

.recent-table[data-layout="grid"] .recent-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    transition: background 0.1s;
}

.recent-table[data-layout="grid"] .recent-item:nth-child(even) {
    background: transparent;
}

.recent-table[data-layout="grid"] .recent-item:hover {
    background: var(--hover-bg);
}

.recent-table[data-layout="grid"] .recent-item:active {
    background: var(--selection-bg);
}

.recent-table[data-layout="grid"] .recent-thumb {
    width: 80px;
    height: 80px;
    border-radius: 5px; /* macOS icon style */
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.recent-table[data-layout="grid"] .recent-name {
    white-space: normal;
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.3;
    width: 100%;
    color: var(--text-primary);
}

.recent-table[data-layout="grid"] .recent-date,
.recent-table[data-layout="grid"] .recent-size {
    display: none;
}

.recent-table[data-layout="grid"] .recent-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--app-bg);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    opacity: 0;
}
.recent-table[data-layout="grid"] .recent-item:hover .recent-delete { opacity: 1; }

.recents-footer {
    height: 28px;
    border-top: 1px solid var(--separator);
    display: flex;
    align-items: center;
    justify-content: center; /* Centered like Finder status bar */
    padding: 0 12px;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--sidebar-bg);
    border-radius: 0;
}
@media (min-width: 769px) {
    .toolbar { cursor: grab; }
}

/* Workspace */
.workspace {
    flex: 1; padding: 24px; display: flex;
    justify-content: center; align-items: center; overflow: hidden;
}

/* Empty State */
.empty-state { text-align: center; color: var(--text-secondary); }
.empty-icon { width: 64px; height: 64px; color: var(--text-tertiary); margin-bottom: 16px; }
.empty-text { font-size: 13px; margin-bottom: 24px; }

.btn-apple {
    background: var(--accent); color: white; border: none;
    font-size: 13px; font-weight: 500; padding: 6px 14px;
    border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,0.1); cursor: pointer;
}
.btn-apple:active { background: #0062cc; }
.btn-apple:disabled { opacity: 0.5; cursor: default; }

/* Canvas */
.canvas-container {
    width: 100%; height: 100%; display: none;
    border: 1px solid var(--border); border-radius: 4px;
    overflow: hidden; position: relative;
    background: #f0f0f0 url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0iI2ZmZiI+PHJlY3Qgd2lkdGg9IjEwIiBoZWlnaHQ9IjEwIiBmaWxsPSIjZjVmNWY1Ii8+PHJlY3QgeD0iMTAiIHk9IjEwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIGZpbGw9IiNmNWY1ZjUiLz48L3N2Zz4=');
}

.img-viewer { width: 100%; height: 100%; position: relative; }
.img-layer { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }

.comparison-overlay {
    position: absolute; top: 0; left: 0; width: 50%; height: 100%;
    overflow: hidden; border-right: 1px solid rgba(255,255,255,0.8);
    box-shadow: 5px 0 15px rgba(0,0,0,0.1);
}
.img-overlay { width: 100%; height: 100%; object-fit: contain; }

.slider-handle {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 24px; height: 24px; background: white; border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2); display: flex;
    align-items: center; justify-content: center; color: var(--text-secondary);
    cursor: col-resize; z-index: 10;
}

/* Status Bar (Desktop) */
.status-bar {
    height: 28px; border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px; font-size: 11px; color: var(--text-secondary); background: #fcfcfc;
}

/* --- Mobile / iOS Native Adaptation --- */
@media (max-width: 768px) {
    body {
        background: #000;
        height: 100vh;
        height: 100svh;
        height: 100dvh;
        height: calc(var(--vvh, 1vh) * 100);
        width: 100%;
        overflow: hidden;
        position: fixed;
        inset: 0;
    }

    .mac-window {
        width: 100%;
        height: 100%;
        border-radius: 0;
        box-shadow: none; border: none; animation: none;
        flex-direction: column; background: #000;
    }

    .sidebar { display: none; }

    /* Top Bar */
    .toolbar {
        position: fixed; top: 0; left: 0; right: 0;
        height: auto; min-height: 44px;
        padding: 0 16px; padding-top: env(safe-area-inset-top);
        background: rgba(30, 30, 30, 0.8); backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-bottom: 0.5px solid rgba(255,255,255,0.1);
        z-index: 1000; display: flex; align-items: center; justify-content: center;
    }

    .toolbar-title { color: #fff; font-size: 17px; font-weight: 600; }
    .toolbar-actions { display: none; } /* Hide desktop actions */

    /* Main Area */
    .main-view {
        background: #000; width: 100%; height: 100%;
        padding-top: calc(44px + env(safe-area-inset-top));
        padding-bottom: calc(83px + env(safe-area-inset-bottom));
    }
    
    .workspace { background: #000; padding: 0; }
    .canvas-container { border: none; background: #000; border-radius: 0; }

    /* Bottom Bar */
    .status-bar {
        position: fixed; bottom: 0; left: 0; right: 0;
        height: auto; min-height: 83px; padding: 10px 20px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
        background: rgba(30, 30, 30, 0.8); backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 0.5px solid rgba(255,255,255,0.1);
        display: flex; align-items: flex-start; justify-content: space-between;
        z-index: 1000; color: #fff;
    }
    
    /* Elements overrides */
    .empty-state { color: #888; }
    .empty-icon { color: #555; }
    
    .btn-apple {
        background: #007aff; border-radius: 8px;
        padding: 12px 24px; font-size: 17px; width: 100%; max-width: 200px;
    }
    
    .slider-handle {
        width: 36px; height: 36px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.5);
        border: 2px solid #fff; background: rgba(255,255,255,0.2);
        backdrop-filter: blur(4px);
    }
    
    /* Hide text status on mobile */
    #statusLeft, #statusRight { display: none; }
}
