:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --surface-3: #e9eaee;
  --border: #e4e5e9;
  --border-strong: #d4d6dc;
  --text: #16171b;
  --text-2: #4b4f5a;
  --muted: #80848f;
  --accent: #5046e5;
  --accent-2: #6d64f0;
  --accent-soft: #eeedfd;
  --accent-text: #ffffff;
  --ok: #10915b;
  --danger: #d03b30;
  --danger-soft: #fdecea;
  --folder: #e8a23a;
  --shadow-sm: 0 1px 2px rgba(15, 17, 26, .05);
  --shadow: 0 1px 3px rgba(15, 17, 26, .06), 0 8px 24px -12px rgba(15, 17, 26, .12);
  --shadow-lg: 0 24px 64px -16px rgba(15, 17, 26, .35);
  --radius: 12px;
  --radius-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e11; --surface: #15161b; --surface-2: #1c1d23; --surface-3: #25262e; --border: #26272f; --border-strong: #33353f;
    --text: #ececf1; --text-2: #b4b7c2; --muted: #7d808c; --accent: #7c74ff; --accent-2: #928bff; --accent-soft: #23214a; --accent-text: #0d0e11;
    --ok: #3fcf8e; --danger: #ff6b61; --danger-soft: #3a1714; --folder: #f0b354;
    --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02); --shadow-lg: 0 24px 64px -16px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0e11; --surface: #15161b; --surface-2: #1c1d23; --surface-3: #25262e; --border: #26272f; --border-strong: #33353f;
  --text: #ececf1; --text-2: #b4b7c2; --muted: #7d808c; --accent: #7c74ff; --accent-2: #928bff; --accent-soft: #23214a; --accent-text: #0d0e11;
  --ok: #3fcf8e; --danger: #ff6b61; --danger-soft: #3a1714; --folder: #f0b354;
  --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02); --shadow-lg: 0 24px 64px -16px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
small { color: var(--muted); font-weight: 400; }

/* ---------- tombol & input ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); box-shadow: 0 1px 2px rgba(80,70,229,.3); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.bordered { border-color: var(--border-strong); background: var(--surface); }
input[type=text], input[type=password], input[type=search] {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 550; color: var(--text-2); margin-bottom: 6px; }
.input-icon, .input-action, .search { position: relative; display: flex; align-items: center; }
.input-icon > .i, .search > .i { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.input-icon input, .search input { padding-left: 38px; }
.input-action input { padding-right: 44px; }
.input-action .icon-btn { position: absolute; right: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 12px 0 0; }
.row-end { display: flex; justify-content: space-between; gap: 8px; margin-top: 22px; }

.switches { margin-top: 18px; display: grid; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 34px; height: 20px; border-radius: 999px; background: var(--surface-3); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- login / koneksi ---------- */
.center-view {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 400px at 110% 110%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.auth-card.wide { max-width: 560px; }
.auth-card h1 { font-size: 22px; font-weight: 700; margin-top: 16px; }
.auth-card .sub { color: var(--muted); margin: 6px 0 8px; }
.auth-card .btn.primary.block { margin-top: 22px; height: 42px; }
.card-head { display: flex; gap: 14px; align-items: flex-start; }
.card-head h1 { margin-top: 2px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff;
}
.brand-mark.lg { width: 48px; height: 48px; border-radius: 14px; }
.brand-mark.lg .i { width: 24px; height: 24px; }

/* ---------- layout aplikasi ---------- */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; padding: 0 6px; }
.conn-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface-2); }
.conn-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok); font-weight: 600; }
.conn-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.conn-bucket { font-weight: 650; margin-top: 6px; word-break: break-all; }
.conn-host { font-size: 12px; color: var(--muted); word-break: break-all; }
.side-nav, .side-foot { display: grid; gap: 2px; }
.side-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 38px; padding: 0 10px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); font: inherit; font-weight: 500; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.main { min-width: 0; padding: 0 28px 48px; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
}
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; flex: 1; min-width: 220px; font-size: 15px; }
.crumbs button { border: 0; background: transparent; color: var(--text-2); font: inherit; padding: 4px 8px; border-radius: 6px; cursor: pointer; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs button.current { color: var(--text); font-weight: 650; }
.crumbs .sep { color: var(--muted); display: inline-flex; }
.crumbs .sep .i { width: 14px; height: 14px; }
.tools { display: flex; align-items: center; gap: 8px; }
.search { width: 260px; }
.search input { height: 36px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.seg-btn { display: grid; place-items: center; width: 32px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- statistik ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2); font-size: 13px;
}
.chip b { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.chip.warn { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* ---------- grid ---------- */
.section-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 0 10px; }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 26px; }
.folder-card {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); cursor: pointer; text-align: left; font: inherit; color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.folder-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.folder-card .i { color: var(--folder); width: 22px; height: 22px; fill: color-mix(in srgb, var(--folder) 25%, transparent); }
.folder-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 14px; }
.file-card {
  display: flex; flex-direction: column; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); text-align: left; font: inherit; color: var(--text); padding: 0;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.file-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.file-card:focus-visible, .folder-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--muted); position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.thumb img.loaded { opacity: 1; }
.thumb .i { width: 34px; height: 34px; stroke-width: 1.4; }
.thumb .ext { position: absolute; bottom: 8px; right: 8px; font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 2px 6px; border-radius: 5px; background: var(--surface); color: var(--text-2); border: 1px solid var(--border); }
.file-info { padding: 10px 12px 12px; min-width: 0; }
.file-name { font-weight: 550; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- daftar ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-2); }
.name-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.name-cell .mini { width: 34px; height: 34px; border-radius: 7px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; flex: none; color: var(--muted); }
.name-cell .mini img { width: 100%; height: 100%; object-fit: cover; }
.name-cell .mini.folder .i { color: var(--folder); fill: color-mix(in srgb, var(--folder) 25%, transparent); }
.name-cell span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- kosong, skeleton, muat lagi ---------- */
.empty { text-align: center; padding: 72px 16px; color: var(--muted); }
.empty .i { width: 40px; height: 40px; stroke-width: 1.3; margin-bottom: 10px; }
.empty h3 { margin: 0 0 4px; color: var(--text); font-size: 15px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-card { aspect-ratio: 4 / 3.9; }
.sk-table { height: 320px; }
.sm-sub { color: var(--muted); margin: 4px 0 0; font-size: 13px; }
.load-more { display: flex; justify-content: center; margin-top: 22px; }

/* ---------- overlay: preview & dialog ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8, 9, 12, .72); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.viewer { width: min(1200px, 100%); height: min(820px, 100%); display: grid; grid-template-columns: 1fr 320px; border-radius: 16px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow-lg); }
.viewer-stage { position: relative; background: #0b0c0f; display: grid; place-items: center; min-height: 0; }
.stage-inner { width: 100%; height: 100%; display: grid; place-items: center; padding: 24px; min-height: 0; }
.stage-inner img, .stage-inner video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.stage-inner iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.stage-inner .no-preview { color: #9aa0ad; text-align: center; }
.stage-inner .no-preview .i { width: 48px; height: 48px; stroke-width: 1.2; }
.nav-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff; display: grid; place-items: center; cursor: pointer; z-index: 2; }
.nav-arrow:hover { background: rgba(255,255,255,.22); }
.nav-arrow.left { left: 14px; } .nav-arrow.right { right: 14px; }
.viewer-side { display: flex; flex-direction: column; padding: 18px; gap: 16px; border-left: 1px solid var(--border); min-height: 0; overflow: auto; }
.side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.side-head h2 { font-size: 15px; font-weight: 650; word-break: break-all; padding-top: 7px; }
.meta { display: grid; gap: 12px; margin: 0; }
.meta div { display: grid; gap: 2px; }
.meta dt { font-size: 12px; color: var(--muted); }
.meta dd { margin: 0; font-size: 13px; word-break: break-all; color: var(--text); }
.side-actions { display: grid; gap: 8px; margin-top: auto; }
.dialog { width: min(640px, 100%); max-height: 100%; overflow: auto; background: var(--surface); border-radius: 16px; padding: 20px; box-shadow: var(--shadow-lg); }
.dialog .side-head h2 { padding-top: 6px; }
.big-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 20px; }
.big-stat { padding: 14px 16px; border-radius: var(--radius); background: var(--surface-2); }
.big-stat .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.big-stat .l { font-size: 12px; color: var(--muted); }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: 13px; }
.bar-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.bar-row .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #8b5cf6); }
.progress-line { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 28px 0; justify-content: center; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 380px; padding: 11px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 13px; animation: rise .2s; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsif ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .conn-card { display: none; }
  .side-nav, .side-foot { display: flex; gap: 4px; margin: 0; border: 0; padding: 0; }
  .side-foot { margin-left: auto; }
  .nav-item { width: auto; font-size: 13px; }
  .main { padding: 0 16px 40px; }
  .viewer { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .viewer-side { border-left: 0; border-top: 1px solid var(--border); max-height: 45vh; }
}
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }
  .tools { width: 100%; }
  .search { flex: 1; width: auto; }
  .nav-item span:not(.i):not([data-icon]) { display: none; }
  #navBrowse, #navSummary, #navSwitch, #btnTheme, #btnLogout { font-size: 0; gap: 0; width: 38px; justify-content: center; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  th.hide-sm, td.hide-sm { display: none; }
  .overlay { padding: 0; }
  .viewer { height: 100%; border-radius: 0; }
}
