:root {
    --bg: #08080a;
    --bg-elevated: #0f0f12;
    --surface: #141418;
    --surface-hover: #1a1a20;
    --surface-active: #222228;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.12);
    --text: #f2f2f5;
    --text-secondary: #a0a0ab;
    --text-tertiary: #6b6b76;
    --accent: #7c6bf0;
    --accent-soft: rgba(124, 107, 240, 0.14);
    --accent-glow: rgba(124, 107, 240, 0.35);
    --accent-hover: #9183f5;
    --danger: #f06060;
    --danger-soft: rgba(240, 96, 96, 0.12);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.12);
    --warn: #fbbf24;
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    --shadow-glow: 0 0 40px var(--accent-glow);
    --font: "DM Sans", system-ui, -apple-system, sans-serif;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --header-h: 72px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
}

.hidden {
    display: none !important;
}

.view {
    min-height: 100vh;
}

#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(124, 107, 240, 0.22), transparent 55%),
        radial-gradient(ellipse 50% 40% at 100% 100%, rgba(96, 165, 250, 0.08), transparent 50%),
        var(--bg);
    pointer-events: none;
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: rgba(20, 20, 24, 0.85);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    animation: rise 0.5s var(--ease) both;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
}

.brand h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    border: 1px solid rgba(124, 107, 240, 0.25);
    border-radius: var(--radius);
    color: var(--accent-hover);
    flex-shrink: 0;
}

.brand-mark svg {
    width: 24px;
    height: 24px;
}

.brand-mark-sm {
    width: 40px;
    height: 40px;
}

.brand-mark-sm svg {
    width: 20px;
    height: 20px;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.input-wrap input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrap input::placeholder {
    color: var(--text-tertiary);
}

.input-wrap input:focus {
    outline: none;
    border-color: rgba(124, 107, 240, 0.5);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s var(--ease), box-shadow 0.2s;
}

.btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 12px rgba(124, 107, 240, 0.3);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px rgba(124, 107, 240, 0.4);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: rgba(255, 255, 255, 0.16);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--surface);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(240, 96, 96, 0.2);
}

.btn-danger:hover {
    background: rgba(240, 96, 96, 0.2);
    border-color: rgba(240, 96, 96, 0.35);
}

.btn-icon {
    padding: 10px 14px;
}

.btn-block {
    width: 100%;
    margin-top: 20px;
    padding: 13px 16px;
}

.login-form .input-wrap {
    margin-bottom: 4px;
}

.form-error {
    margin: 14px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    border: 1px solid rgba(240, 96, 96, 0.25);
    color: #fca5a5;
    font-size: 0.88rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    height: var(--header-h);
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(8, 8, 10, 0.8);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.topbar-brand h1 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.storage-widget {
    width: 180px;
}

.storage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.storage-label {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.storage {
    height: 5px;
    background: var(--surface);
    border-radius: 999px;
    overflow: hidden;
}

.storage-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), #a78bfa);
    border-radius: 999px;
    transition: width 0.5s var(--ease);
}

.storage-fill.warn {
    background: linear-gradient(90deg, var(--warn), var(--danger));
}

.logout-form {
    margin: 0;
}

.content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 28px 40px;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    margin-top: 2px;
}

.breadcrumb-item {
    color: var(--text-tertiary);
    background: none;
    border: none;
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
}

.breadcrumb-item:hover {
    color: var(--text-secondary);
    background: var(--surface);
}

.breadcrumb-item.active {
    color: var(--text);
    background: var(--surface);
}

.breadcrumb-sep {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    user-select: none;
    opacity: 0.5;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 0 20px;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.toolbar-left .btn,
.toolbar-left .upload-label {
    min-height: 42px;
}

.upload-label {
    cursor: pointer;
}

.hint {
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

.drop-zone {
    position: relative;
    min-height: 400px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    transition: border-color 0.25s, box-shadow 0.25s;
}

.drop-zone.dragover {
    border-color: rgba(124, 107, 240, 0.45);
    box-shadow: inset 0 0 0 1px rgba(124, 107, 240, 0.2), var(--shadow-glow);
}

.drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 8, 10, 0.75);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.drop-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 32px;
    color: var(--accent-hover);
    font-weight: 600;
    font-size: 1.1rem;
}

.drop-overlay-inner svg {
    width: 48px;
    height: 48px;
    animation: bounce 1.2s var(--ease) infinite;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 80px 24px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2.5px solid var(--surface-active);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    padding: 16px;
}

.file-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100%;
    transition: border-color 0.25s, transform 0.25s var(--ease), box-shadow 0.25s;
    animation: card-in 0.35s var(--ease) both;
}

.file-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-3px);
    box-shadow: var(--shadow-sm);
}

.file-thumb {
    aspect-ratio: 1;
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    cursor: default;
}

.file-thumb.is-folder {
    cursor: pointer;
    background: linear-gradient(145deg, rgba(124, 107, 240, 0.12), rgba(20, 20, 24, 0.9));
}

.file-thumb img,
.file-thumb canvas.dxf-preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.file-thumb img {
    transition: transform 0.4s var(--ease);
}

.file-thumb canvas.dxf-preview-canvas {
    background: #12141a;
}

.file-thumb canvas.dxf-preview-canvas.dxf-ready {
    background: #12141a;
}

.file-type-badge.dxf-fallback .ext {
    background: rgba(96, 165, 250, 0.14);
    color: #93c5fd;
}

.file-card:hover .file-thumb img {
    transform: scale(1.04);
}

.file-type-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.file-type-badge .ext {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--surface-active);
    color: var(--text-secondary);
}

.file-type-badge.dir .ext {
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.file-type-badge svg {
    width: 36px;
    height: 36px;
    color: var(--text-tertiary);
}

.file-type-badge.dir svg {
    color: var(--accent);
}

.file-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.file-name {
    font-weight: 600;
    font-size: 0.88rem;
    word-break: break-word;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.file-meta {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.file-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-top: auto;
    padding-top: 12px;
}

.btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-action svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.btn-action:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.14);
}

.btn-action:active {
    transform: scale(0.96);
}

.btn-action-danger {
    color: var(--danger);
}

.btn-action-danger:hover {
    background: var(--danger-soft);
    border-color: rgba(240, 96, 96, 0.3);
    color: var(--danger);
}

.empty-state {
    text-align: center;
    padding: 72px 32px 88px;
}

.empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-tertiary);
}

.empty-icon svg {
    width: 28px;
    height: 28px;
}

.empty-state h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.empty-state p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    max-width: 320px;
    margin-inline: auto;
}

.upload-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    width: min(420px, calc(100% - 32px));
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 150;
    animation: rise 0.3s var(--ease) both;
}

.upload-bar-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.upload-bar-track {
    height: 4px;
    background: var(--bg-elevated);
    border-radius: 999px;
    overflow: hidden;
}

.upload-bar-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.3s var(--ease);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fade-in 0.2s ease both;
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow);
    animation: modal-in 0.3s var(--ease) both;
}

.modal-card h2 {
    margin: 0 0 20px;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    max-width: 380px;
    padding: 14px 18px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
    z-index: 300;
    font-size: 0.9rem;
    font-weight: 500;
    animation: toast-in 0.35s var(--ease) both;
}

.toast.error {
    border-color: rgba(240, 96, 96, 0.35);
    background: #1a1214;
    color: #fca5a5;
}

.toast.success {
    border-color: rgba(74, 222, 128, 0.3);
    background: #0f1a14;
    color: #86efac;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes card-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@media (max-width: 768px) {
    :root {
        --header-h: auto;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 14px;
    }

    .topbar-actions {
        justify-content: space-between;
    }

    .storage-widget {
        flex: 1;
    }

    .btn-label {
        display: none;
    }

    .content {
        padding: 0 16px 32px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        padding-top: 16px;
        gap: 12px;
    }

    .toolbar-left {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
    }

    .toolbar-left .btn,
    .toolbar-left .upload-label {
        width: 100%;
        justify-content: center;
        min-height: 44px;
        font-size: 0.85rem;
    }

    .hint {
        text-align: center;
    }

    .file-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
        padding: 12px;
    }

    .btn-action {
        height: 34px;
    }

    .btn-action svg {
        width: 16px;
        height: 16px;
    }

    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
