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

:root {
    --bg: #06060a;
    --bg-soft: #0c0c14;
    --surface: rgba(22, 22, 33, 0.72);
    --surface-solid: #161621;
    --surface-2: #1e1e2c;
    --surface-3: #262636;
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.16);
    --border-strong: rgba(255, 255, 255, 0.24);
    --text: #f4f4f8;
    --text-dim: #9292a2;
    --text-muted: #5e5e70;
    --accent: #a855f7;
    --accent-2: #06b6d4;
    --accent-3: #ec4899;
    --success: #22d3aa;
    --warning: #fbbf24;
    --danger: #ff4d6d;
    --gradient: linear-gradient(135deg, #a855f7 0%, #ec4899 50%, #06b6d4 100%);
    --gradient-soft: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(6, 182, 212, 0.2));
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(168, 85, 247, 0.25);
    --radius: 20px;
    --radius-sm: 14px;
    --radius-xs: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

html { -webkit-text-size-adjust: 100%; }

html, body { height: 100%; }

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    overscroll-behavior-y: none;
}

.aurora {
    position: fixed;
    inset: 0;
    z-index: -2;
    background:
        radial-gradient(ellipse 60% 40% at 15% 5%, rgba(168, 85, 247, 0.18), transparent 60%),
        radial-gradient(ellipse 50% 40% at 85% 95%, rgba(6, 182, 212, 0.14), transparent 60%),
        radial-gradient(ellipse 40% 30% at 50% 50%, rgba(236, 72, 153, 0.08), transparent 60%);
    animation: auroraShift 20s ease-in-out infinite alternate;
}

@keyframes auroraShift {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-2%, 2%) scale(1.05); }
    100% { transform: translate(2%, -2%) scale(1); }
}

.noise {
    position: fixed;
    inset: 0;
    z-index: -1;
    opacity: 0.035;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.view { min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }

/* ================ LOGIN ================ */

#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: calc(20px + var(--safe-top));
    padding-bottom: calc(20px + var(--safe-bottom));
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-card {
    background: var(--surface);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 30px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: cardIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(168, 85, 247, 0.6), transparent);
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(30px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.brand { text-align: center; margin-bottom: 30px; }

.brand-icon {
    position: relative;
    display: inline-block;
    margin-bottom: 12px;
}

.brand-icon span {
    font-size: 48px;
    display: inline-block;
    animation: ghostFloat 3.5s ease-in-out infinite;
    filter: drop-shadow(0 8px 20px rgba(168, 85, 247, 0.4));
}

@keyframes ghostFloat {
    0%, 100% { transform: translateY(0) rotate(-3deg); }
    50% { transform: translateY(-10px) rotate(3deg); }
}

.brand-glow {
    position: absolute;
    inset: -20px;
    background: radial-gradient(circle, rgba(168, 85, 247, 0.35), transparent 70%);
    z-index: -1;
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

.brand h1 {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 6px;
    color: var(--text);
}

.brand h1 span {
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    color: var(--text-dim);
    font-size: 12px;
    letter-spacing: 0.3px;
    text-transform: lowercase;
}

.field { margin-bottom: 14px; }

.field label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: lowercase;
    letter-spacing: 1px;
    margin-bottom: 7px;
    font-weight: 500;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 14px 15px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

input[type="text"]:focus,
input[type="password"]:focus {
    border-color: var(--accent);
    background: rgba(0, 0, 0, 0.55);
    box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.14);
}

input::placeholder { color: var(--text-muted); }

.password-wrap { position: relative; }

.pw-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}

.pw-toggle:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.btn-primary {
    width: 100%;
    margin-top: 8px;
    padding: 15px 20px;
    background: var(--gradient);
    background-size: 200% 200%;
    color: white;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.25s, background-position 0.5s;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.3px;
    min-height: 52px;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 32px rgba(168, 85, 247, 0.4);
    background-position: 100% 0;
}

.btn-primary:active { transform: translateY(0) scale(0.99); }

.btn-primary:disabled { opacity: 0.7; cursor: not-allowed; transform: none; }

.btn-text, .btn-arrow, .btn-spinner { position: relative; z-index: 1; }

.btn-arrow { transition: transform 0.2s; }

.btn-primary:hover .btn-arrow { transform: translateX(3px); }

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 14px;
    min-height: 18px;
    text-align: center;
    transition: opacity 0.2s;
}

.error:not(:empty) {
    animation: shake 0.35s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* ================ TOPBAR ================ */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    padding-top: calc(14px + var(--safe-top));
    background: rgba(12, 12, 20, 0.72);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon-sm { font-size: 22px; }

.brand-name {
    font-size: 17px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 9px 14px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    min-height: 40px;
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border-color: var(--border-hover);
}

.btn-icon { padding: 8px 10px; font-size: 14px; min-width: 40px; justify-content: center; }

/* ================ MAIN ================ */

main {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px 24px 100px;
    padding-bottom: calc(100px + var(--safe-bottom));
}

.hero { margin-bottom: 24px; animation: fadeIn 0.5s ease-out; }

.hero h2 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 6px;
}

.wave {
    display: inline-block;
    animation: wave 2.8s ease-in-out infinite;
    transform-origin: 70% 70%;
}

@keyframes wave {
    0%, 60%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(14deg); }
    20% { transform: rotate(-8deg); }
    30% { transform: rotate(14deg); }
    40% { transform: rotate(-4deg); }
    50% { transform: rotate(10deg); }
}

.hero p {
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1.55;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 22px;
    animation: fadeIn 0.5s ease-out 0.08s both;
}

.stat-card {
    background: var(--surface);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color 0.2s, transform 0.2s;
    min-height: 76px;
}

.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon-files { background: rgba(168, 85, 247, 0.15); color: #d8b4fe; }
.stat-icon-size { background: rgba(6, 182, 212, 0.15); color: #67e8f9; }

.stat-body { min-width: 0; }

.stat-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: lowercase;
    letter-spacing: 1.2px;
    margin-bottom: 2px;
    font-weight: 500;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ================ UPLOAD ZONE ================ */

.upload-zone {
    background: var(--surface);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    margin-bottom: 28px;
    cursor: pointer;
    transition: border-color 0.25s, background 0.25s, transform 0.25s;
    text-align: center;
    position: relative;
    overflow: hidden;
    animation: fadeIn 0.5s ease-out 0.16s both;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-soft);
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.upload-zone:hover::before,
.upload-zone.dragover::before { opacity: 1; }

.upload-zone.dragover {
    border-style: solid;
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.upload-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    position: relative;
    z-index: 1;
}

.upload-icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-icon {
    font-size: 42px;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    z-index: 1;
}

.upload-zone:hover .upload-icon { transform: scale(1.15) rotate(-4deg); }

.upload-icon-pulse {
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(168, 85, 247, 0.4), transparent 70%);
    animation: pulse 2.5s ease-in-out infinite;
    z-index: 0;
}

.upload-text strong {
    display: block;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 3px;
}

.upload-text span {
    color: var(--text-dim);
    font-size: 12px;
}

.upload-text u {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent);
}

.upload-status {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-dim);
    min-height: 18px;
    position: relative;
    z-index: 1;
}

.upload-progress {
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    z-index: 1;
}

.progress-track {
    flex: 1;
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--gradient);
    background-size: 200% 100%;
    border-radius: 999px;
    transition: width 0.2s ease;
    animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
    0% { background-position: 0% 0; }
    100% { background-position: 200% 0; }
}

.progress-percent {
    font-size: 12px;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    min-width: 36px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ================ FILES ================ */

.files-section { animation: fadeIn 0.5s ease-out 0.24s both; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.section-header h3 {
    font-size: 14px;
    color: var(--text-dim);
    font-weight: 500;
    text-transform: lowercase;
    letter-spacing: 1.5px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 8px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
    color: var(--text-dim);
    min-height: 40px;
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.12);
}

.search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    width: 160px;
}

.search-box input::placeholder { color: var(--text-muted); }

.search-clear {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.search-clear:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }

.file-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--surface);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    gap: 14px;
    transition: border-color 0.2s, transform 0.2s, background 0.2s;
    animation: rowIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes rowIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.file-row:hover {
    border-color: var(--border-hover);
    transform: translateX(4px);
    background: var(--surface-2);
}

.file-icon-wrap {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
    transition: transform 0.2s;
}

.file-row:hover .file-icon-wrap { transform: scale(1.08) rotate(-4deg); }

.file-icon-image { background: rgba(236, 72, 153, 0.15); }
.file-icon-video { background: rgba(168, 85, 247, 0.15); }
.file-icon-audio { background: rgba(6, 182, 212, 0.15); }
.file-icon-code { background: rgba(34, 211, 170, 0.15); }
.file-icon-doc { background: rgba(59, 130, 246, 0.15); }
.file-icon-pdf { background: rgba(239, 68, 68, 0.15); }
.file-icon-archive { background: rgba(251, 191, 36, 0.15); }
.file-icon-data { background: rgba(139, 92, 246, 0.15); }

.file-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    font-size: 11px;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    display: flex;
    align-items: center;
    gap: 8px;
    font-variant-numeric: tabular-nums;
}

.file-meta-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-muted);
}

.file-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.file-actions button {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.file-actions button:hover { transform: translateY(-1px); }

.file-actions .view-btn:hover {
    background: rgba(168, 85, 247, 0.15);
    border-color: var(--accent);
    color: #d8b4fe;
}

.file-actions .dl-btn:hover {
    background: rgba(6, 182, 212, 0.15);
    border-color: var(--accent-2);
    color: #67e8f9;
}

.file-actions .del-btn:hover {
    background: rgba(255, 77, 109, 0.15);
    border-color: var(--danger);
    color: #fda4af;
}

/* ================ SKELETON ================ */

.skeleton-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.skeleton-box {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-icon { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; }
.skeleton-info { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.skeleton-line { height: 12px; }
.skeleton-line-sm { width: 40%; height: 10px; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
    animation: fadeIn 0.5s ease-out;
}

.empty-state .icon { font-size: 56px; margin-bottom: 14px; opacity: 0.5; }

.empty-state p { font-size: 14px; }
.empty-state .hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ================ FAB ================ */

.fab {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    right: calc(20px + var(--safe-right));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient);
    background-size: 200% 200%;
    color: white;
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 32px rgba(168, 85, 247, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 40;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: fabIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fabIn {
    from { opacity: 0; transform: scale(0.5) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.fab:hover { transform: scale(1.05); box-shadow: 0 16px 40px rgba(168, 85, 247, 0.5); }
.fab:active { transform: scale(0.95); }

/* ================ MODALS ================ */

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 820px;
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.94) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-drag-handle {
    display: none;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    margin: 8px auto 0;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-dim);
    gap: 12px;
    flex-shrink: 0;
}

.modal-header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#preview-body {
    padding: 20px;
    overflow: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

#preview-body pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: #c9d1d9;
    line-height: 1.65;
}

#preview-body img,
#preview-body iframe {
    max-width: 100%;
    border-radius: 10px;
    border: none;
    display: block;
    margin: 0 auto;
}

#preview-body iframe { width: 100%; height: 65vh; height: 65dvh; }

/* ================ CONFIRM ================ */

.confirm-content {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px 22px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.confirm-icon {
    font-size: 40px;
    margin-bottom: 12px;
    animation: confirmShake 0.6s ease-out 0.15s;
}

@keyframes confirmShake {
    0%, 100% { transform: rotate(0); }
    20% { transform: rotate(-12deg); }
    40% { transform: rotate(12deg); }
    60% { transform: rotate(-6deg); }
    80% { transform: rotate(6deg); }
}

.confirm-content h4 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: -0.3px;
}

.confirm-content p {
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 22px;
    line-height: 1.5;
    word-break: break-word;
}

.confirm-actions {
    display: flex;
    gap: 10px;
}

.confirm-actions button {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: transform 0.15s, background 0.15s, border-color 0.15s;
    min-height: 44px;
}

.confirm-actions button:active { transform: scale(0.97); }

.btn-danger {
    background: linear-gradient(135deg, #ff4d6d, #ec4899);
    color: white;
    border: none;
}

.btn-danger:hover { box-shadow: 0 8px 24px rgba(255, 77, 109, 0.35); }

/* ================ TOASTS ================ */

.toast-container {
    position: fixed;
    top: calc(20px + var(--safe-top));
    right: calc(20px + var(--safe-right));
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: calc(100vw - 40px);
}

.toast {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-xs);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
    max-width: 340px;
    display: flex;
    align-items: center;
    gap: 10px;
    word-break: break-word;
}

.toast-icon { font-size: 16px; flex-shrink: 0; }

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent-2); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(60px); }
    to { opacity: 1; transform: translateX(0); }
}

.toast.out { animation: toastOut 0.25s ease forwards; }

@keyframes toastOut {
    to { opacity: 0; transform: translateX(60px); }
}

/* ================ RESPONSIVE ================ */

@media (max-width: 640px) {
    .topbar { padding: 12px 16px; padding-top: calc(12px + var(--safe-top)); }

    .brand-name { font-size: 16px; }

    .btn-ghost span { display: none; }
    .btn-ghost { padding: 9px 12px; }

    main {
        padding: 20px 16px 90px;
        padding-bottom: calc(90px + var(--safe-bottom));
    }

    .hero h2 { font-size: 24px; }
    .hero p { font-size: 13px; }

    .stats { gap: 10px; }

    .stat-card { padding: 14px; gap: 12px; min-height: 70px; }

    .stat-icon { width: 36px; height: 36px; border-radius: 10px; }

    .stat-value { font-size: 20px; }

    .upload-zone { padding: 26px 18px; margin-bottom: 22px; }

    .upload-icon { font-size: 38px; }

    .upload-text strong { font-size: 15px; }

    .section-header { gap: 10px; }

    .search-box { flex: 1; min-width: 0; }
    .search-box input { width: 100%; min-width: 0; }

    .file-row { padding: 12px 14px; gap: 12px; }

    .file-icon-wrap { width: 38px; height: 38px; font-size: 18px; border-radius: 10px; }

    .file-name { font-size: 13.5px; }

    .file-meta { font-size: 10.5px; }

    .file-actions { gap: 5px; }

    .file-actions button { width: 34px; height: 34px; }

    .file-row:hover { transform: none; }

    .fab { display: flex; }

    .upload-zone { display: none; }

    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 88dvh;
        border-radius: 24px 24px 0 0;
        border-bottom: none;
        animation: slideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .modal-drag-handle { display: block; }

    .modal-header { padding: 12px 16px; }

    #preview-body { padding: 16px; }

    #preview-body iframe { height: 55dvh; }

    .confirm-content {
        max-width: calc(100% - 32px);
        margin: 0 16px 16px;
        padding: 24px 20px 18px;
    }

    .toast-container {
        left: 12px;
        right: 12px;
        top: calc(12px + var(--safe-top));
        max-width: none;
    }

    .toast { max-width: none; }
}

@media (max-width: 360px) {
    .hero h2 { font-size: 22px; }

    .stat-card { padding: 12px; gap: 10px; }

    .stat-icon { width: 32px; height: 32px; }

    .stat-value { font-size: 18px; }

    .file-actions button { width: 32px; height: 32px; }

    .file-meta { font-size: 10px; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .hero { margin-bottom: 16px; }

    .hero h2 { font-size: 22px; }

    .stats { margin-bottom: 16px; }
}

@media (hover: none) {
    .file-row:hover { transform: none; background: var(--surface); }
    .stat-card:hover { transform: none; }
    .upload-zone:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}