/* Apple Photos Style - Light Theme (Default) */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f2f2f7;
    --bg-tertiary: #e5e5ea;
    --bg-elevated: #d1d1d6;
    --text-primary: #000000;
    --text-secondary: #6c6c70;
    --text-tertiary: #8e8e93;
    --accent-blue: #007aff;
    --accent-green: #34c759;
    --accent-red: #ff3b30;
    --separator: rgba(60, 60, 67, 0.29);
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --tab-bar-height: 83px;
    --header-height: 96px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --bg-elevated: #3a3a3c;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --text-tertiary: #636366;
    --accent-blue: #0a84ff;
    --accent-green: #30d158;
    --accent-red: #ff453a;
    --separator: rgba(84, 84, 88, 0.65);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid var(--separator);
    padding: 12px 16px;
    min-height: var(--header-height);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

[data-theme="dark"] .header {
    background: rgba(0, 0, 0, 0.85);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-action {
    width: 44px;
    height: 44px;
    border-radius: 22px;
    background: var(--bg-secondary);
    border: none;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
}

.header-action:active {
    background: var(--bg-tertiary);
}

.header-action svg {
    width: 22px;
    height: 22px;
}

.header-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-subtitle {
    font-size: 17px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.header-back {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--accent-blue);
    text-decoration: none;
    font-size: 17px;
    margin-bottom: 8px;
}

.header-back svg {
    width: 20px;
    height: 20px;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--tab-bar-height);
}

/* Section */
.section {
    padding: 16px;
}

.section-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Albums Grid */
.albums-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.album-card {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.album-card:active {
    transform: scale(0.96);
    opacity: 0.8;
}

.album-thumbnail {
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.album-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.album-emoji {
    font-size: 48px;
}

.album-info {
    padding: 8px 0;
}

.album-name {
    display: block;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

.album-count {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Folders Grid */
.folders-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.folder-card {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, opacity 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    cursor: pointer;
    position: relative;
}

.folder-card:active {
    transform: scale(0.96);
    opacity: 0.8;
}

.folder-thumbnail {
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.folder-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.folder-icon {
    font-size: 40px;
    color: var(--accent-blue);
}

.folder-info {
    padding: 8px 0;
}

.folder-name {
    display: block;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

.folder-count {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Photos Grid */
.photos-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
}

.photo-item {
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background: var(--bg-secondary);
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.photo-item:active img {
    transform: scale(1.05);
    opacity: 0.8;
}

/* Photo Viewer */
.photo-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 1000;
    display: none;
    flex-direction: column;
}

.photo-viewer.active {
    display: flex;
}

.viewer-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px;
    padding-top: calc(16px + var(--safe-area-top));
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    transition: opacity 0.3s ease;
}

.viewer-header.hidden {
    opacity: 0;
    pointer-events: none;
}

.viewer-close, .viewer-action {
    width: 44px;
    height: 44px;
    border-radius: 22px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.viewer-close svg, .viewer-action svg {
    width: 24px;
    height: 24px;
}

.viewer-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.viewer-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.viewer-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-area-bottom));
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    z-index: 10;
    display: flex;
    justify-content: space-around;
    transition: opacity 0.3s ease;
}

.viewer-footer.hidden {
    opacity: 0;
    pointer-events: none;
}

.viewer-btn {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    background: transparent;
    border: none;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    gap: 4px;
}

.viewer-btn svg {
    width: 24px;
    height: 24px;
}

.viewer-btn span {
    font-size: 10px;
    opacity: 0.8;
}

/* Tab Bar */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-bar-height);
    background: rgba(249, 249, 249, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--separator);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: var(--safe-area-bottom);
    z-index: 100;
}

[data-theme="dark"] .tab-bar {
    background: rgba(28, 28, 30, 0.95);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-tertiary);
    padding: 4px 20px;
    transition: color 0.2s ease;
}

.tab-item.active {
    color: var(--accent-blue);
}

.tab-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 2px;
}

.tab-label {
    font-size: 10px;
    font-weight: 500;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-progress {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-blue);
}

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

/* Add Button */
.add-button {
    position: fixed;
    bottom: calc(var(--tab-bar-height) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--accent-blue);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(10, 132, 255, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 50;
}

.add-button:active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.3);
}

.add-button svg {
    width: 28px;
    height: 28px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 80vh;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
}

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

.modal-title {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    width: 30px;
    height: 30px;
    border-radius: 15px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 17px;
    outline: none;
}

.form-input:focus {
    box-shadow: 0 0 0 2px var(--accent-blue);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: var(--accent-blue);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.btn-primary:active {
    opacity: 0.8;
}

.btn-secondary {
    width: 100%;
    padding: 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 8px;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--bg-elevated);
    border-radius: 16px;
    padding: 40px 20px;
    text-align: center;
    margin-bottom: 16px;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-area.dragover {
    border-color: var(--accent-blue);
    background: rgba(10, 132, 255, 0.1);
}

.upload-area svg {
    width: 48px;
    height: 48px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

.upload-area p {
    color: var(--text-secondary);
    font-size: 15px;
}

.upload-area input[type="file"] {
    display: none;
}

/* Toast */
.toast {
    position: fixed;
    bottom: calc(var(--tab-bar-height) + 80px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 15px;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 1500;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--accent-blue);
    color: white;
}

.toast.error {
    background: var(--accent-red);
    color: white;
}

/* Error Message */
.error-message {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 40px;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 15px;
}

/* Swipe Indicator */
.swipe-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.swipe-indicator.left {
    left: 10px;
}

.swipe-indicator.right {
    right: 10px;
}

.swipe-indicator svg {
    width: 24px;
    height: 24px;
    color: rgba(255,255,255,0.6);
}

/* Delete Confirm */
.delete-confirm {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    z-index: 1100;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.delete-confirm.active {
    transform: translateY(0);
}

.delete-confirm h3 {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 8px;
}

.delete-confirm p {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 20px;
}

.delete-confirm .btn-danger {
    width: 100%;
    padding: 16px;
    background: var(--accent-red);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
}

.delete-confirm .btn-cancel {
    width: 100%;
    padding: 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
}

/* Share Modal */
.share-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.share-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.share-modal {
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    width: 100%;
    max-width: 500px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.share-modal-overlay.active .share-modal {
    transform: translateY(0);
}

.share-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.share-modal-header h3 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
}

.share-modal-close {
    width: 30px;
    height: 30px;
    border-radius: 15px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.share-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.share-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
    text-align: left;
    width: 100%;
}

.share-option:active {
    background: var(--bg-primary);
}

.share-option svg {
    width: 24px;
    height: 24px;
    color: var(--accent-blue);
    flex-shrink: 0;
}

.share-option span {
    flex: 1;
}

.sort-check {
    color: var(--accent-blue);
    font-weight: 600;
    flex: 0 !important;
    min-width: 20px;
}

/* Selection Mode */
.selection-bar {
    position: fixed;
    bottom: var(--tab-bar-height);
    left: 0;
    right: 0;
    height: 56px;
    background: var(--accent-blue);
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

.selection-bar.active {
    display: flex;
}

.selection-bar-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 17px;
    font-weight: 500;
    padding: 8px 16px;
    cursor: pointer;
}

.selection-bar-btn-primary {
    background: rgba(255,255,255,0.2);
    border-radius: 8px;
}

.selection-bar-btn-primary:disabled {
    opacity: 0.5;
}

.selection-count {
    color: white;
    font-size: 17px;
    font-weight: 600;
}

/* Photo selection checkbox */
.photo-item.selectable {
    position: relative;
}

.photo-item .select-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    border: 2px solid var(--bg-tertiary);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: all 0.2s ease;
}

.photo-item.selectable .select-checkbox {
    display: flex;
}

.photo-item.selectable.selected .select-checkbox {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.photo-item.selectable.selected .select-checkbox::after {
    content: '✓';
    color: white;
    font-size: 16px;
    font-weight: 700;
}

.photo-item.selectable.selected img {
    transform: scale(0.92);
    border-radius: 4px;
}

.photo-item.selectable::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0);
    transition: background 0.2s ease;
    pointer-events: none;
}

.photo-item.selectable.selected::after {
    background: rgba(0,132,255,0.15);
}

/* Folder selection mode */
.folder-card.selectable {
    position: relative;
}

.folder-card .select-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    border: 2px solid var(--bg-tertiary);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: all 0.2s ease;
}

.folder-card.selectable .select-checkbox {
    display: flex;
}

.folder-card.selectable.selected .select-checkbox {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.folder-card.selectable.selected .select-checkbox::after {
    content: '✓';
    color: white;
    font-size: 16px;
    font-weight: 700;
}

/* Blue ring around entire folder card when selected */
.folder-card.selectable.selected {
    transform: scale(0.95);
}

.folder-card.selectable.selected .folder-thumbnail {
    outline: 4px solid var(--accent-blue);
    outline-offset: -4px;
}

.folder-card.selectable.selected .folder-thumbnail img {
    opacity: 0.8;
}

.folder-card.selectable.selected .folder-name {
    color: var(--accent-blue);
}
