/* Shared Drive-style UI for the main app and the backup viewer. */
:root {
  --bg: #f8fafd;
  --surface: #ffffff;
  --surface-2: #f0f4f9;
  --surface-3: #e1e5ea;
  --border: #dadce0;
  --text: #1f1f1f;
  --muted: #5f6368;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #d6ebe3;
  --danger: #b3261e;
  --warn: #8a5a00;
  --shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131314;
    --surface: #1e1f20;
    --surface-2: #282a2c;
    --surface-3: #37393b;
    --border: #444746;
    --text: #e3e3e3;
    --muted: #a8abaf;
    --accent: #7cc7ae;
    --accent-text: #0e211b;
    --accent-soft: #24433a;
    --danger: #f2b8b5;
    --warn: #e6c27a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: inherit; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 256px 1fr; grid-template-rows: 64px 1fr; height: 100vh; height: 100dvh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; width: 232px; font-size: 20px; font-weight: 500; text-decoration: none; flex: none; }
.brand img { width: 36px; height: 36px; }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 28px; padding: 0 16px; height: 46px; }
.search input { flex: 1; border: 0; background: none; outline: none; font-size: 16px; min-width: 0; }
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }

.sidebar { padding: 4px 12px 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.new-btn { display: inline-flex; align-items: center; gap: 12px; height: 56px; padding: 0 20px 0 16px; margin: 4px 0 16px; border: 0; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow); font-size: 15px; font-weight: 500; cursor: pointer; align-self: flex-start; }
.new-btn:hover { background: var(--surface-2); }
.nav-item { display: flex; align-items: center; gap: 14px; height: 36px; padding: 0 16px; border-radius: 18px; text-decoration: none; cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav-item:hover { background: var(--surface-3); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
.nav-sep { height: 12px; }
.storage { padding: 4px 16px; color: var(--muted); font-size: 13px; }
.storage .meter { height: 4px; border-radius: 2px; background: var(--surface-3); margin: 8px 0 6px; overflow: hidden; }
.storage .meter > i { display: block; height: 100%; background: var(--accent); width: 0; }

.content { background: var(--surface); border-radius: 16px; margin: 0 16px 16px 0; overflow: auto; position: relative; display: flex; flex-direction: column; }
.content-head { position: sticky; top: 0; z-index: 5; background: var(--surface); padding: 16px 20px 8px; }
.title-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; font-size: 22px; }
.crumbs a { text-decoration: none; padding: 4px 10px; border-radius: 20px; white-space: nowrap; color: var(--muted); }
.crumbs a:last-child { color: var(--text); }
.crumbs a:hover { background: var(--surface-2); }
.crumbs .sep { color: var(--muted); font-size: 18px; }
.view-switch { margin-left: auto; display: flex; border: 1px solid var(--border); border-radius: 20px; overflow: hidden; flex: none; }
.view-switch button { border: 0; background: none; height: 34px; width: 48px; display: grid; place-items: center; cursor: pointer; }
.view-switch button.on { background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 14px; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; white-space: nowrap; }
.chip:hover { background: var(--surface-2); }
.chip.set { background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.chip .x { margin-left: 2px; }
.sort-row { display: flex; align-items: center; gap: 6px; margin: 14px 0 0; color: var(--text); font-weight: 500; }
.sort-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer; padding: 4px 8px; border-radius: 16px; font-weight: 500; }
.sort-btn:hover { background: var(--surface-2); }
.sort-btn .arrow { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); }
.activity { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.activity::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.body { padding: 4px 20px 24px; flex: 1; }
.section-label { font-size: 14px; font-weight: 500; margin: 14px 0 10px; }
.banner { margin: 0 20px 8px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.banner.error { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); }

/* folders */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.folder { display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 4px 0 16px; border-radius: var(--radius); background: var(--surface-2);
  text-decoration: none; cursor: pointer; min-width: 0; }
.folder:hover { background: var(--surface-3); }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.folder svg { flex: none; color: var(--muted); }

/* file cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card { background: var(--surface-2); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; min-width: 0; }
.card:hover { background: var(--surface-3); }
.card .card-head { display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 4px 0 14px; }
.card .card-head .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.card .thumb { margin: 0 8px 8px; aspect-ratio: 4 / 3; border-radius: 8px; background: var(--surface); display: grid; place-items: center; overflow: hidden; position: relative; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb .big-icon { color: var(--muted); }
.card .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 4px; }
.card .badge-pos { position: absolute; left: 6px; top: 6px; }
.kicon { display: inline-grid; place-items: center; flex: none; }

/* list */
.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-weight: 500; color: var(--text); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.list td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--surface-2); }
.list .cell-name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.list .cell-name span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .num { color: var(--muted); white-space: nowrap; }
.list .menu-cell { width: 44px; text-align: right; }

.icon-btn { border: 0; background: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; color: inherit; }
.icon-btn:hover { background: var(--surface-3); }
.badge { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.badge.warn { color: var(--warn); }
.badge.ok { color: var(--accent); }
.badge.bad { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 72px 20px; }
.empty-title { font-size: 18px; color: var(--text); font-weight: 500; }

/* menus / popovers */
.popover { position: fixed; z-index: 60; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 0; min-width: 200px; }
.popover button, .popover a { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 16px; border: 0; background: none; cursor: pointer; text-align: left; text-decoration: none; white-space: nowrap; }
.popover button:hover, .popover a:hover { background: var(--surface-2); }
.popover .on { font-weight: 600; color: var(--accent); }
.popover hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* details side panel (ⓘ) */
.info-panel { position: absolute; top: 0; right: 0; bottom: 0; width: 320px; background: var(--surface); border-left: 1px solid var(--border); z-index: 6; padding: 16px; overflow-y: auto; }
.info-panel h3 { margin: 0 0 12px; font-size: 16px; font-weight: 500; }
.info-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.info-panel dt { color: var(--muted); }
.info-panel dd { margin: 0; word-break: break-word; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 500; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .55; cursor: default; }

/* drop zone + upload tray */
.dropzone { position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--accent) 16%, transparent); display: grid; place-items: center; pointer-events: none; }
.dropzone > div { background: var(--surface); padding: 18px 26px; border-radius: 14px; box-shadow: var(--shadow); border: 2px dashed var(--accent); }
.tray { position: fixed; right: 24px; bottom: 0; z-index: 30; width: min(360px, calc(100vw - 32px)); background: var(--surface); border-radius: 16px 16px 0 0; box-shadow: var(--shadow); overflow: hidden; }
.tray header { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 8px 16px; background: var(--surface-2); font-weight: 500; }
.tray ul { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.tray li { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.tray .row { display: flex; justify-content: space-between; gap: 10px; }
.tray .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray .state { color: var(--muted); white-space: nowrap; }
.tray .state.err { color: var(--danger); }
.bar { height: 4px; border-radius: 4px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: #0d0d0d; color: #f1f1f1; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.viewer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 16px; }
.viewer-actions { display: flex; gap: 8px; }
.viewer .icon-btn:hover { background: #2a2a2a; }
.viewer .btn { background: #262626; border-color: #3a3a3a; color: #f1f1f1; }
.viewer .btn:hover { background: #333; }
.viewer .btn.primary { background: #7cc7ae; border-color: #7cc7ae; color: #0e211b; }
.viewer-body { flex: 1; display: flex; min-height: 0; position: relative; }
.stage { flex: 1; min-width: 0; display: grid; place-items: center; overflow: auto; position: relative; }
.stage img, .stage video { max-width: 100%; max-height: 100%; display: block; }
.stage img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.stage img.zoomable { cursor: zoom-in; }
.stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.stage pre { width: 100%; height: 100%; margin: 0; padding: 20px; overflow: auto; background: #161616; font: 13px/1.5 ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
.stage .placeholder { text-align: center; color: #b5b5b5; max-width: 360px; padding: 20px; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; background: rgba(0, 0, 0, .45); color: #fff; border: 0; font-size: 34px; width: 44px; height: 64px; cursor: pointer; border-radius: 8px; }
.nav:hover { background: rgba(0, 0, 0, .7); }
.nav.prev { left: 8px; }
.nav.next { right: 8px; }
.viewer.with-details .nav.next { right: 328px; }
.details { width: 320px; flex: none; background: #171717; border-left: 1px solid #2a2a2a; padding: 16px; overflow-y: auto; }
.details h3 { font-size: 12.5px; color: #9a9a9a; font-weight: 600; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.details h3:first-child { margin-top: 0; }
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.details dt { color: #9a9a9a; }
.details dd { margin: 0; word-break: break-word; }
.details .note { color: #b5b5b5; font-size: 13px; margin: 6px 0 10px; }
.details .btn { width: 100%; margin-top: 6px; }
.details a { color: #9fd9c4; }

dialog { border: 0; border-radius: 24px; background: var(--surface); color: var(--text); padding: 24px; width: min(400px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { margin: 0 0 16px; font-size: 22px; font-weight: 400; }
dialog input { width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; }
dialog input:focus { outline: 2px solid var(--accent); border-color: transparent; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 20px 0 0; padding: 0; }
dialog menu .btn { border: 0; background: none; color: var(--accent); }
dialog menu .btn:hover { background: var(--accent-soft); }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 8px 0 0; }

/* public share page: no sidebar, no account features */
.share-mode .shell { grid-template-columns: 1fr; }
.share-mode .sidebar, .share-mode .menu-btn, .share-mode .new-btn { display: none; }
.share-mode .content { margin-left: 16px; }

/* share dialog */
.share-list { list-style: none; padding: 0; margin: 16px 0 0; max-height: 240px; overflow-y: auto; }
.share-list li { padding: 10px 0; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.share-link { display: flex; gap: 8px; align-items: center; }
.share-link input { flex: 1; font-size: 13px; padding: 8px 10px; }
.share-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.share-meta .revoke { margin-left: auto; color: var(--danger); background: none; border: 0; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.share-meta .revoke:hover { background: var(--surface-2); }
dialog select { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 15px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
dialog .row { display: flex; gap: 8px; align-items: flex-end; }
dialog .row > div { flex: 1; }
.bin-note { margin: 0 20px 8px; color: var(--muted); font-size: 13px; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; }
  .brand { width: auto; font-size: 18px; }
  .brand span { display: none; }
  .menu-btn { display: inline-grid; }
  .sidebar { position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; width: 280px; background: var(--bg); box-shadow: var(--shadow); padding-top: 16px; transform: translateX(-105%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .content { margin: 0; border-radius: 16px 16px 0 0; }
  .content-head { padding: 12px 12px 6px; }
  .body { padding: 4px 12px 24px; }
  .crumbs { font-size: 18px; }
  .folders, .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .search { height: 40px; }
  .info-panel { width: 100%; }
  .viewer-body { flex-direction: column; }
  .details { width: auto; border-left: 0; border-top: 1px solid #2a2a2a; max-height: 42vh; }
  .viewer.with-details .nav.next { right: 8px; }
  .nav { top: 30%; }
  .list .hide-sm { display: none; }
}
.scrim { position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, .3); }
