/* ============================================================
   TELEDRIVE — DESIGN TOKENS
   Tema "Vault": brankas digital — gelap, tenang, aksen kuningan.
   Font sistem saja (tanpa font eksternal) — koneksi pengguna
   bisa sangat lambat, jadi zero request tambahan itu prioritas.
   ============================================================ */

:root {
    --bg: #12151b;
    --surface: #1a1f27;
    --surface-2: #212734;
    --border: #2a3140;
    --text: #e7eaf0;
    --text-dim: #8b93a6;
    --accent: #d4a054;
    --accent-soft: rgba(212, 160, 84, .14);
    --accent-contrast: #14181f;
    --success: #5fb488;
    --danger: #d9636a;
    --radius: 10px;
    --sidebar-w: 240px;
    --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Noto Serif", serif;
}

[data-theme="light"] {
    --bg: #eef0f4;
    --surface: #ffffff;
    --surface-2: #f4f5f8;
    --border: #d7dbe3;
    --text: #1b1f27;
    --text-dim: #5b6472;
    --accent: #b9793a;
    --accent-contrast: #ffffff;
    --success: #2f8f63;
    --danger: #c1414a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

.mono { font-family: ui-monospace, "SF Mono", "Courier New", monospace; font-size: 0.85em; color: var(--text-dim); }

a { color: var(--accent); text-decoration: none; }

button {
    font-family: inherit;
    cursor: pointer;
}

/* ---------- App Shell ---------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

.topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, var(--accent) 0%, transparent 28%);
    opacity: .5;
    pointer-events: none;
}

.topbar .search {
    flex: 1;
    max-width: 420px;
}

.topbar input[type="search"] {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn.active { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); }

.hamburger { display: none; }

.sidebar {
    grid-area: sidebar;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 20px;
    font-family: var(--serif);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: .01em;
}
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.brand-mark img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
.brand-mark svg { width: 16px; height: 16px; color: var(--accent); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
    font-size: 0.92rem;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--accent); }

.new-folder-btn {
    margin-top: 14px;
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.88rem;
}
.new-folder-btn:hover { border-color: var(--accent); color: var(--accent); }

main {
    grid-area: main;
    padding: 18px 22px 100px;
    overflow-y: auto;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 0.88rem;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.breadcrumb button {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.88rem;
    padding: 2px 4px;
}
.breadcrumb button:hover { color: var(--accent); }
.breadcrumb .current { color: var(--text); }

.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 60px 20px;
}

/* ---------- Loading Indicators ---------- */

.global-loading-bar {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 0;
    background: var(--accent);
    z-index: 200;
    opacity: 0;
    transition: opacity .2s ease;
    pointer-events: none;
}
.global-loading-bar.active {
    opacity: 1;
    animation: gLoadingSlide 1s ease-in-out infinite;
}
@keyframes gLoadingSlide {
    0%   { width: 0%;  margin-left: 0%; }
    50%  { width: 55%; margin-left: 20%; }
    100% { width: 0%;  margin-left: 100%; }
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto;
    animation: td-spin .7s linear infinite;
}
@keyframes td-spin { to { transform: rotate(360deg); } }

.btn.is-loading {
    opacity: .7;
    pointer-events: none;
    position: relative;
}
.spinner-inline {
    width: 13px;
    height: 13px;
    border: 2px solid rgba(128,128,128,.35);
    border-top-color: currentColor;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    vertical-align: -2px;
    animation: td-spin .6s linear infinite;
}

/* ---------- Grid View ---------- */

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
}

.file-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    text-align: center;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.file-card:hover { border-color: var(--accent); }
.card-menu-btn {
    position: absolute;
    top: 6px; right: 6px;
    width: 22px; height: 22px;
    border-radius: 50%;
    border: none;
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-menu-btn:hover { color: var(--text); }
.row-menu-btn { position: static; margin-left: auto; background: transparent; flex-shrink: 0; }
.file-card .icon { width: 34px; height: 34px; color: var(--accent); }
.file-card .thumb {
    width: 100%;
    height: 78px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--surface-2);
}
.file-card .name { font-size: 0.82rem; word-break: break-word; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.file-card .meta { font-size: 0.7rem; color: var(--text-dim); }

/* ---------- Table/List View ---------- */

.file-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.file-table th {
    text-align: left;
    color: var(--text-dim);
    font-weight: 500;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.file-table th:hover { color: var(--accent); }
.file-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.file-table tr:hover td { background: var(--surface-2); }
.file-table tr[data-type] {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.file-table .name-cell { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.file-table .icon { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }

.hidden { display: none !important; }

/* ---------- Floating Upload FAB + Drawer ---------- */

.upload-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-contrast);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,.35);
    z-index: 30;
}

.upload-drawer {
    position: fixed;
    right: 22px;
    bottom: 88px;
    width: 320px;
    max-width: calc(100vw - 44px);
    max-height: 60vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0,0,0,.4);
    z-index: 30;
}
.upload-drawer .drawer-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
    font-weight: 600;
}
.upload-item { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.upload-item:last-child { border-bottom: none; }
.upload-item .row1 { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 6px; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.progress-bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width .2s; }
.upload-item .status { font-size: 0.72rem; color: var(--text-dim); margin-top: 4px; }
.upload-item .status.err { color: var(--danger); }
.upload-item .status.ok { color: var(--success); }

/* ---------- Toast ---------- */

.toast-wrap {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 60;
    padding: 20px;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    max-width: 360px;
}
.modal h3 { margin: 0 0 14px; font-size: 1rem; }
.modal input {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    margin-bottom: 14px;
}
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 0.88rem;
}
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

/* ---------- Folder Style Picker (warna & ikon) ---------- */

.style-picker { display: flex; flex-direction: column; gap: 18px; }
.style-picker .picker-label {
    font-size: .78rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    display: block;
}
.style-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px 0 4px;
}
.style-preview .file-card { width: 100px; cursor: default; }
.style-preview .file-card:hover { border-color: var(--border); }

.color-swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.color-swatch.selected { border-color: var(--text); }
.color-swatch.selected::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,.3);
}

.icon-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}
.icon-option {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    color: var(--text-dim);
    background: var(--surface-2);
}
.icon-option:hover { color: var(--text); }
.icon-option.selected {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}
.icon-option svg { width: 19px; height: 19px; }

.preview-modal { max-width: 640px; }
.preview-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px; gap: 10px;
}
.preview-title { font-weight: 600; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-body { min-height: 80px; }
.preview-loading { text-align: center; padding: 30px; color: var(--text-dim); }
.preview-text {
    max-height: 60vh; overflow: auto; background: var(--surface-2);
    padding: 12px; border-radius: 8px; white-space: pre-wrap; word-break: break-word;
    text-align: left; font-size: 0.8rem;
}
.actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Drag & Drop ---------- */

.dragging { opacity: .35; }

.drag-ghost {
    position: fixed;
    top: 0; left: 0;
    transform: translate(-50%, -140%);
    pointer-events: none;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 8px;
    font-size: 0.8rem;
    box-shadow: 0 10px 24px rgba(0,0,0,.4);
    max-width: 200px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.drag-ghost .icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--accent); }

.drop-target {
    outline: 2px dashed var(--accent) !important;
    background: var(--accent-soft) !important;
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */

@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }
    .hamburger { display: inline-flex; }
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 78vw;
        max-width: 280px;
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 40;
        box-shadow: 0 0 30px rgba(0,0,0,.4);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 35;
    }
    .sidebar-backdrop.open { display: block; }

    main { padding: 14px 14px 100px; }
    .topbar .search { max-width: none; }
    .file-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }

    /* Di layar kecil, tabel disederhanakan: sembunyikan kolom sekunder */
    .file-table th.col-date, .file-table td.col-date { display: none; }

    .upload-drawer { right: 12px; left: 12px; width: auto; bottom: 82px; }
    .upload-fab { right: 16px; bottom: 16px; }
}

/* ============================================================
   HALAMAN LOGIN — "Ruang Brankas"
   Dial brass dekoratif + kartu mengambang, tanpa gambar eksternal
   (semua motif digambar dengan SVG/CSS agar tetap ringan).
   ============================================================ */

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(ellipse 900px 600px at 50% -10%, var(--accent-soft), transparent 60%),
        var(--bg);
}

.vault-dial {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(820px, 130vw);
    height: min(820px, 130vw);
    transform: translate(-50%, -50%);
    color: var(--border);
    opacity: .55;
    pointer-events: none;
    z-index: 0;
}
[data-theme="light"] .vault-dial { opacity: .35; }

.login-card {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 30px 60px -20px rgba(0,0,0,.55);
    animation: card-rise .5s cubic-bezier(.16,1,.3,1) both;
}
@media (prefers-reduced-motion: reduce) {
    .login-card { animation: none; }
}
@keyframes card-rise {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-emblem {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    box-shadow: inset 0 0 0 3px var(--bg), 0 0 0 1px var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
    overflow: hidden;
}
.login-emblem img { width: 100%; height: 100%; object-fit: cover; }
.login-emblem svg { width: 26px; height: 26px; color: var(--accent); }

.login-brand {
    text-align: center;
    font-family: var(--serif);
    font-weight: 700;
    font-size: 1.4rem;
    margin-bottom: 4px;
}
.login-sub {
    text-align: center;
    color: var(--text-dim);
    font-size: .85rem;
    margin-bottom: 28px;
}

.field {
    margin-bottom: 16px;
}
.field label {
    display: block;
    font-size: .78rem;
    color: var(--text-dim);
    margin-bottom: 6px;
}
.field input {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 13px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: .95rem;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 600;
    font-size: .95rem;
    margin-top: 6px;
    transition: filter .15s, transform .15s;
}
.login-submit:hover { filter: brightness(1.08); }
.login-submit:active { transform: translateY(1px); }

.login-note {
    text-align: center;
    color: var(--text-dim);
    font-size: .76rem;
    margin-top: 18px;
}

.login-err {
    background: rgba(217,99,106,.12);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: .85rem;
    margin-bottom: 18px;
}
