:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #646b78;
  --border: #e1e4e9;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e6eefe;
  --danger: #d1343e;
  --ok: #17895b;
  --warn: #b26a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .08);
  --radius: 14px;
  --k-folder: #3b82f6; --k-image: #db2777; --k-video: #7c3aed; --k-audio: #0891b2;
  --k-pdf: #dc2626; --k-text: #64748b; --k-doc: #2563eb; --k-sheet: #16a34a;
  --k-slides: #ea580c; --k-archive: #a16207; --k-code: #0f766e; --k-file: #6b7280;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #252932;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #2e333d;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --accent-soft: #1e2a47;
    --danger: #f2626b;
    --ok: #3ccb8c;
    --warn: #f0a63a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Tamil", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.4rem; margin: .4rem 0; line-height: 1.25; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.icon { width: 22px; height: 22px; flex: none; }
.icon.big { width: 72px; height: 72px; }
.brand-icon { width: 44px; height: 44px; color: var(--accent); }
.sep { width: 16px; height: 16px; color: var(--muted); }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { min-height: 52px; padding: 0 28px; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: .92rem; font-weight: 600; }
input, select {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; font-weight: 400;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check-label { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check-label input { width: 20px; min-height: 20px; height: 20px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.alert { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin: 10px 0; }
.note { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; font-size: .92rem; }

/* Plain pages: setup, login, errors */
body.plain { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.card { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 28px 22px; width: 100%; }
.narrow { max-width: 420px; }
.center { text-align: center; }
.checks { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; font-size: .9rem; }
.checks li { display: flex; gap: 8px; align-items: flex-start; }
.checks li .icon { width: 18px; height: 18px; margin-top: 2px; }
.checks .ok .icon { color: var(--ok); }
.checks .warn { color: var(--warn); }

/* App chrome */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; padding-left: 8px; min-width: 0; }
.topbar-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title .icon { color: var(--accent); }
.searchbar { flex: 1; display: flex; align-items: center; gap: 4px; }
.searchbar input { min-height: 40px; border-radius: 20px; padding: 6px 14px; }

.wrap { max-width: 1000px; margin: 0 auto; padding: 0 12px calc(120px + env(safe-area-inset-bottom)); }
.crumbs {
  display: flex; align-items: center; gap: 2px; overflow-x: auto; white-space: nowrap;
  padding: 12px 4px 6px; scrollbar-width: none; font-weight: 600;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs a, .crumbs button { color: var(--muted); padding: 6px 8px; border-radius: 8px; border: 0; background: none; font: inherit; cursor: pointer; }
.crumbs a:last-child, .crumbs button:last-child { color: var(--text); }
.crumbs .icon { width: 18px; height: 18px; vertical-align: -3px; }
body.share .crumbs { max-width: 1000px; margin: 0 auto; padding-left: 12px; padding-right: 12px; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 4px 4px 10px; flex-wrap: wrap; }
.usage { flex: 1; min-width: 160px; font-size: .82rem; color: var(--muted); }
.usage-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 4px; max-width: 260px; }
.usage-bar div { height: 100%; background: var(--accent); border-radius: 3px; }
.usage-bar.full div { background: var(--danger); }
.toolbar select { width: auto; min-height: 38px; padding: 4px 8px; font-size: .9rem; }

/* File list */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 8px 4px 8px 12px; min-height: 64px;
  color: inherit; background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.row-main:hover { background: var(--surface-2); }
.row .icon-btn { margin-right: 4px; color: var(--muted); }
.thumb {
  width: 44px; height: 44px; flex: none; border-radius: 10px; object-fit: cover;
  display: grid; place-items: center; background: var(--surface-2);
}
.row-text { min-width: 0; display: grid; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.meta { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); list-style: none; }
.empty .icon { width: 56px; height: 56px; display: block; margin: 0 auto 10px; opacity: .5; }

.kind-folder { color: var(--k-folder); } .kind-image { color: var(--k-image); } .kind-video { color: var(--k-video); }
.kind-audio { color: var(--k-audio); } .kind-pdf { color: var(--k-pdf); } .kind-text { color: var(--k-text); }
.kind-doc { color: var(--k-doc); } .kind-sheet { color: var(--k-sheet); } .kind-slides { color: var(--k-slides); }
.kind-archive { color: var(--k-archive); } .kind-code { color: var(--k-code); } .kind-file { color: var(--k-file); }
.thumb.kind-folder { background: color-mix(in srgb, var(--k-folder) 14%, transparent); }

/* Grid view */
.list.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
  background: none; box-shadow: none; overflow: visible;
}
.list.grid .row { flex-direction: column; align-items: stretch; position: relative; border: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list.grid .row-main { flex-direction: column; align-items: stretch; padding: 0; gap: 0; min-height: 0; }
.list.grid .thumb { width: 100%; height: auto; aspect-ratio: 1; border-radius: 0; }
.list.grid .thumb .icon { width: 44px; height: 44px; }
.list.grid .row-text { padding: 8px 40px 10px 10px; }
.list.grid .row .icon-btn { position: absolute; right: 0; bottom: 4px; margin: 0; width: 38px; height: 38px; }
@media (max-width: 420px) { .list.grid { grid-template-columns: repeat(2, 1fr); } }

/* Floating add button */
.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  width: 60px; height: 60px; border-radius: 20px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 20px rgba(37, 99, 235, .4);
  display: grid; place-items: center;
}
.fab .icon { width: 28px; height: 28px; }
.drop-hint {
  position: fixed; inset: 12px; z-index: 60; border: 3px dashed var(--accent); border-radius: 24px;
  background: color-mix(in srgb, var(--accent) 12%, transparent); display: grid; place-items: center;
  font-size: 1.3rem; font-weight: 700; color: var(--accent); pointer-events: none;
}

/* Modals: bottom sheet on phones, centred dialog on larger screens */
.modal-wrap {
  position: fixed; inset: 0; z-index: 58; background: rgba(10, 12, 16, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  background: var(--surface); width: 100%; max-height: 92vh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 10px; }
@media (min-width: 640px) {
  .modal-wrap { align-items: center; padding: 20px; }
  .sheet { max-width: 460px; border-radius: 20px; padding: 20px 22px; }
  .sheet.wide { max-width: 640px; }
  .sheet::before { display: none; }
}
.sheet-title { font-weight: 700; font-size: 1.05rem; margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-sub { color: var(--muted); font-size: .88rem; margin: 0 0 10px; }
.actions { list-style: none; margin: 6px -8px 0; padding: 0; }
.actions button {
  width: 100%; display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 12px;
  border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 12px;
}
.actions button:hover { background: var(--surface-2); }
.actions .danger { color: var(--danger); }
.dialog-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.dialog-buttons .btn { flex: 1; }
@media (min-width: 640px) { .dialog-buttons .btn { flex: none; } }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: .9rem; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }

/* Simple tables inside sheets (shares, users) */
.items { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.items li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; }
.items .grow { flex: 1; min-width: 0; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 55; background: #0b0c0f; color: #f2f3f5; display: flex; flex-direction: column; animation: fade .15s; }
.viewer-bar { display: flex; align-items: center; gap: 2px; padding: calc(4px + env(safe-area-inset-top)) 6px 4px; background: rgba(0, 0, 0, .5); }
.viewer-bar .title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; }
.viewer-bar .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.viewer-body { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; touch-action: pan-y pinch-zoom; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body pre { width: 100%; height: 100%; margin: 0; overflow: auto; padding: 16px; background: #fff; color: #111; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.viewer-body .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0, 0, 0, .45); color: #fff; }
.viewer-body .nav.prev { left: 8px; } .viewer-body .nav.next { right: 8px; }
.viewer-none { text-align: center; padding: 20px; }
.viewer-none .icon { width: 80px; height: 80px; }
.viewer-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); text-align: center; }

/* Upload progress panel */
.uploads {
  position: fixed; left: 12px; right: 12px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 35;
  max-width: 420px; margin-left: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  border: 1px solid var(--border); overflow: hidden;
}
.uploads-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; font-weight: 650; border-bottom: 1px solid var(--border); }
.uploads-head span { flex: 1; }
.uploads ul { list-style: none; margin: 0; padding: 4px 0; max-height: 40vh; overflow: auto; }
.uploads li { padding: 6px 14px; font-size: .88rem; }
.up-line { display: flex; gap: 8px; align-items: center; }
.up-line .name { flex: 1; font-weight: 500; }
.up-status { font-size: .78rem; color: var(--muted); }
.up-status.err { color: var(--danger); }
.up-status.done { color: var(--ok); }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  background: #1f2329; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px); font-size: .92rem; animation: up .2s;
}
.toast.err { background: var(--danger); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Share pages */
body.share { padding-bottom: env(safe-area-inset-bottom); }
body.share .files { max-width: 1000px; margin: 0 auto; padding: 0 12px 24px; }
.share-file { max-width: 900px; margin: 0 auto; padding: 16px 16px 24px; text-align: center; display: grid; gap: 12px; justify-items: center; }
.file-title { word-break: break-word; margin-bottom: 0; }
.share-file .muted { margin: 0; }
.preview-box { width: 100%; display: grid; gap: 10px; justify-items: center; }
.preview-media { max-width: 100%; max-height: 70vh; border-radius: 12px; background: #000; }
.preview-doc { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.preview-doc.text { height: 50vh; }
.preview-none { padding: 30px; }
.share-foot { text-align: center; color: var(--muted); font-size: .82rem; padding: 16px; }
