:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #e2e5ee;
  --text: #171a23;
  --muted: #6b7183;
  --accent: #4f6bff;
  --accent-soft: #e7ebff;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2a2f3d;
    --text: #e9ebf2;
    --muted: #8d93a5;
    --accent: #7b8fff;
    --accent-soft: #232a4a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* Butang */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn.wide { width: 100%; justify-content: center; padding: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.x { border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.x:hover { color: var(--text); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 40px 32px; width: 100%; max-width: 380px; text-align: center; box-shadow: var(--shadow);
}
.login-card h1 { margin: 16px 0 4px; font-size: 26px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.err { color: var(--danger) !important; margin-top: 12px !important; font-size: 13px; }

.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.logo svg { width: 20px; height: 20px; fill: #fff; stroke: none; }
.logo.big { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto; }
.logo.big svg { width: 38px; height: 38px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.search {
  flex: 1; max-width: 520px; margin: 0 auto; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 12px;
}
.search svg { color: var(--muted); width: 18px; height: 18px; flex: none; }
.search input { flex: 1; border: 0; outline: 0; background: none; color: var(--text); font: inherit; padding: 9px 0; min-width: 0; }
.search:focus-within { border-color: var(--accent); }
.user { display: flex; align-items: center; gap: 8px; }
.user img { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); }

/* Storan */
.storage { display: flex; align-items: center; gap: 12px; padding: 14px 24px 0; color: var(--muted); font-size: 12px; }
.storage-bar { width: 180px; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
#storageFill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 2px; font-size: 18px; font-weight: 600; flex-wrap: wrap; min-width: 0; }
.crumbs button { border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs button:last-child { color: var(--text); }
.crumbs .sep { color: var(--muted); }
.actions { display: flex; gap: 8px; }

/* Senarai fail */
.files { padding: 0 24px 40px; }
.files.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; overflow: hidden; transition: border-color .15s, box-shadow .15s, transform .15s;
  animation: pop .25s ease both;
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-2px); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.thumb { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 44px; height: 44px; stroke-width: 1.4; }
.meta { padding: 10px 12px; min-width: 0; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--muted); font-size: 12px; }
.more {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 8px; border: 0;
  background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center;
  opacity: 0; transition: opacity .15s; box-shadow: var(--shadow);
}
.card:hover .more, .more:focus { opacity: 1; }
@media (hover: none) { .more { opacity: 1; } }

/* Paparan senarai */
.files.list { display: flex; flex-direction: column; gap: 6px; }
.files.list .card { display: flex; align-items: center; }
.files.list .card:hover { transform: none; }
.files.list .thumb { width: 48px; height: 48px; aspect-ratio: auto; flex: none; margin: 6px; border-radius: 10px; }
.files.list .thumb svg { width: 24px; height: 24px; }
.files.list .meta { flex: 1; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.files.list .more { position: static; opacity: 1; box-shadow: none; background: none; margin-right: 8px; }

.c-folder { color: #f5a524; }
.c-image { color: #17c964; }
.c-video { color: #f31260; }
.c-audio { color: #9353d3; }
.c-pdf { color: #e5484d; }
.c-doc { color: var(--accent); }
.c-zip { color: #a1785c; }
.c-file { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 60px 16px; }
.empty svg { width: 56px; height: 56px; stroke-width: 1.2; }
.loading { display: grid; place-items: center; padding: 60px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dropzone */
.dropzone {
  position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--accent) 18%, transparent);
  display: grid; place-items: center; pointer-events: none;
}
.dropzone div {
  border: 2px dashed var(--accent); background: var(--surface); color: var(--accent); font-weight: 600;
  font-size: 18px; padding: 40px 60px; border-radius: 20px;
}

/* Panel upload */
.uploads {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 340px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.uploads header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 600; background: var(--surface-2); }
.uploads ul { list-style: none; margin: 0; padding: 6px 14px 12px; max-height: 260px; overflow: auto; }
.uploads li { padding: 8px 0; font-size: 13px; }
.uploads .row { display: flex; justify-content: space-between; gap: 8px; }
.uploads .row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads .row span:last-child { color: var(--muted); flex: none; }
.bar { height: 4px; background: var(--surface-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.uploads li.done .bar div { background: #17c964; }
.uploads li.fail .bar div { background: var(--danger); }

/* Menu */
.menu {
  position: fixed; z-index: 60; min-width: 180px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu button {
  display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: none; color: var(--text);
  font: inherit; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-align: left;
}
.menu button svg { width: 18px; height: 18px; color: var(--muted); }
.menu button:hover { background: var(--surface-2); }
.menu button.danger, .menu button.danger svg { color: var(--danger); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 16px; }
.preview-box {
  width: min(1000px, 100%); height: min(85vh, 100%); background: var(--surface); border-radius: 16px;
  display: flex; flex-direction: column; overflow: hidden;
}
.preview-box header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.preview-box header span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-box header div { display: flex; gap: 8px; align-items: center; flex: none; }
.preview-body { flex: 1; display: grid; place-items: center; overflow: auto; background: var(--surface-2); }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-body pre { align-self: stretch; justify-self: stretch; margin: 0; padding: 16px; white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.preview-body .msg { color: var(--muted); text-align: center; padding: 20px; }

.dialog { width: min(400px, 100%); background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.dialog h3 { margin: 0 0 6px; }
.dialog p { margin: 0 0 14px; color: var(--muted); }
.dialog p:empty { display: none; }
.dialog input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; outline: none; margin-bottom: 16px;
}
.dialog input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 80;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Telefon */
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .brand span { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .user { margin-left: auto; }
  .storage, .toolbar { padding-left: 16px; padding-right: 16px; }
  .files { padding: 0 16px 40px; }
  .files.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .files.list .sub { display: none; }
}
