/* Single — device-adaptive UI
   Desktop (≥761px): sidebar layout, hover states, double-click folders.
   Mobile  (≤760px): top bar + bottom tab navigation, single-tap folders,
                     bottom-sheet dialogs, 44px+ touch targets.
   Accent matches the logo (#0a84ff). */

:root,
:root[data-theme="dark"] {
  --bg: #12141a;
  --bg-soft: #181c26;
  --bg-card: #1a1f2b;
  --bg-hover: #222836;
  --border: #262c3a;
  --text: #e8eaf0;
  --text-dim: #8b93a7;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.15);
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --nav-h: 62px;
  --top-h: 54px;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-soft: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef1f7;
  --border: #dfe4ee;
  --text: #1c2230;
  --text-dim: #6b7386;
  --accent: #0069c2;
  --accent-soft: rgba(0, 105, 194, 0.10);
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 8px 30px rgba(30, 41, 59, 0.12);
}

/* ---------------- base ---------------- */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { overscroll-behavior: none; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Android WebView: holding images/text pops up a native callout and drags a
   preview over the app, which can freeze the UI. Kill selection + drag. */
body { -webkit-user-select: none; user-select: none; }
input, textarea { -webkit-user-select: auto; user-select: auto; }
img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}
button, .file-row, .tab, .crumb, .nav-item { touch-action: manipulation; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.ic {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------------- mobile top bar + bottom nav (hidden on desktop) ------- */

.topbar, .bottom-nav { display: none; }

/* ---------------- sidebar (desktop) ---------------- */

.sidebar {
  width: 232px;
  min-width: 232px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.brand-logo { width: 42px; height: 42px; border-radius: 12px; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 0.3px; }
.brand-sub { color: var(--text-dim); font-size: 11.5px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; color: var(--text-dim);
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14px; text-align: left; width: 100%;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item:active { transform: translateY(1px); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.badge {
  background: var(--accent); color: #fff;
  font-size: 10.5px; font-weight: 700; border-radius: 999px;
  padding: 1px 7px; line-height: 1.5;
}
.nav-item .badge { margin-left: auto; }

.sidebar-footer { margin-top: auto; padding: 10px 12px; border-top: 1px solid var(--border); }
.me-line { font-weight: 600; }
.me-sub { color: var(--text-dim); font-size: 11.5px; margin-top: 3px; }

/* ---------------- main ---------------- */

.main { flex: 1; overflow-y: auto; padding: 26px 30px; }
.view { display: none; max-width: 980px; margin: 0 auto; }
.view.active { display: block; }

.view-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; gap: 12px; flex-wrap: wrap;
}
.view-head h1 { font-size: 21px; margin: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.hint { color: var(--text-dim); font-size: 12.5px; margin: 6px 0 16px; }

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn.icobtn { padding: 7px; }
.btn.icobtn .ic { width: 15px; height: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------------- devices ---------------- */

.device-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}
.device-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.device-top { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 800;
}
.device-name { font-weight: 700; font-size: 15px; }
.device-meta { color: var(--text-dim); font-size: 11.5px; margin-top: 2px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-dot.online { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.status-dot.offline { background: var(--text-dim); }
.pill {
  font-size: 10.5px; border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 8px; color: var(--text-dim);
}
.pill.paired { border-color: var(--accent); color: var(--accent); }
.device-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.device-actions .btn { flex: 1 1 auto; justify-content: center; }
.device-actions .ic { width: 15px; height: 15px; }

.empty {
  color: var(--text-dim); text-align: center; padding: 46px 20px;
  border: 1px dashed var(--border); border-radius: 14px; font-size: 13px;
}

/* ---------------- files ---------------- */

.file-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.tab {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 12.5px;
  font-family: inherit;
}
.tab.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.breadcrumb { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.crumb {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 13px; padding: 4px 7px; border-radius: 6px; font-family: inherit;
}
.crumb:hover { background: var(--accent-soft); }
.crumb-sep { color: var(--text-dim); }

.file-list { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg-card); cursor: default;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--bg-hover); }
.file-row.clickable { cursor: pointer; }
.file-ico { width: 26px; display: flex; justify-content: center; color: var(--text-dim); }
.file-ico .ic { width: 18px; height: 18px; }
.file-ico.is-dir { color: var(--accent); }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.file-date { color: var(--text-dim); font-size: 12px; white-space: nowrap; width: 100px; text-align: right; }
.file-actions { display: flex; gap: 6px; }

/* ---------------- transfers ---------------- */

.transfer-list { display: flex; flex-direction: column; gap: 10px; }
.transfer-item {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px;
}
.transfer-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.transfer-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.transfer-name .ic { width: 15px; height: 15px; color: var(--accent); }
.transfer-sub { color: var(--text-dim); font-size: 11.5px; margin-top: 3px; }
.progress { height: 7px; background: var(--bg-hover); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.2s; }
.state-badge { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 8px; flex-shrink: 0; }
.state-badge.done { color: var(--ok); background: rgba(74, 222, 128, 0.12); }
.state-badge.failed { color: var(--danger); background: rgba(255, 107, 107, 0.12); }
.state-badge.active { color: var(--accent); background: var(--accent-soft); }

/* ---------------- settings ---------------- */

.settings { display: flex; flex-direction: column; gap: 16px; max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--text-dim); font-size: 12.5px; }
.field input[type="text"], .field input[type="number"], .field select {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; font-size: 14px; outline: none; width: 100%;
  font-family: inherit;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check span { color: var(--text); font-size: 13px; }
.field.check input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; }
.platform-panel {
  border: 1px solid var(--border); border-radius: 14px; padding: 16px;
  background: var(--bg-card);
}
.platform-panel h3 { margin: 0 0 6px; font-size: 15px; }
.drive-list { margin-top: 10px; font-size: 12.5px; color: var(--text-dim); }
.root-report { margin: 10px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 12.5px; }

/* ---------------- about ---------------- */

.about { text-align: center; padding-top: 10px; }
.about-logo { width: 96px; height: 96px; border-radius: 24px; }
.about h2 { margin: 12px 0 4px; }
.tagline { color: var(--text-dim); margin: 0 0 18px; }
.about-grid {
  display: inline-grid; grid-template-columns: auto auto; gap: 6px 18px;
  text-align: left; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 22px; margin-bottom: 16px;
}
.about-grid .k { color: var(--text-dim); font-size: 12.5px; }
.about-grid .v { font-size: 13px; word-break: break-all; }
.links a { color: var(--accent); text-decoration: none; }
.links a:hover { text-decoration: underline; }

/* ---------------- modal ---------------- */

.modal-root { position: fixed; inset: 0; z-index: 100; }
.modal-root.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.modal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 24px; width: min(440px, calc(100vw - 40px));
  max-height: 82vh; max-height: 82dvh; overflow-y: auto;
}
.modal h2 { margin: 0 0 6px; font-size: 17px; }
.modal p { color: var(--text-dim); font-size: 13px; margin: 6px 0 14px; }
.modal .row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.pin-box {
  font-size: 30px; letter-spacing: 8px; font-weight: 800; color: var(--accent);
  background: var(--accent-soft); border-radius: 12px; padding: 10px 0;
  text-align: center; margin: 10px 0; user-select: all; -webkit-user-select: all;
}
.modal input.pin-input {
  width: 100%; font-size: 22px; letter-spacing: 6px; text-align: center;
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px; outline: none; font-family: inherit;
}
.modal input.pin-input:focus { border-color: var(--accent); }
.modal .field { margin-top: 8px; }

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
}
.toast {
  background: var(--bg-soft); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 360px; animation: slide-in 0.2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.hidden { display: none !important; }

/* ================================================================
   MOBILE  (phones / Android — narrower than 760px)
   ================================================================ */

@media (max-width: 760px) {

  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

  /* --- top bar --- */
  .topbar {
    display: flex; align-items: center; gap: 10px;
    height: calc(var(--top-h) + env(safe-area-inset-top));
    min-height: calc(var(--top-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 14px 0;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
  }
  .topbar-logo { width: 30px; height: 30px; border-radius: 8px; }
  .topbar-title { font-size: 17px; font-weight: 700; letter-spacing: 0.3px; }
  .topbar-me {
    margin-left: auto; color: var(--text-dim); font-size: 11.5px;
    max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  #app { flex: 1; min-height: 0; display: block; }
  .sidebar { display: none; }
  .main { padding: 14px 14px 24px; height: 100%; overflow-y: auto; }
  .view-head h1 { font-size: 19px; }
  .hint { font-size: 12px; }

  /* --- header buttons become compact icon buttons --- */
  .head-actions { gap: 6px; }
  .head-actions .btn { padding: 8px; }
  .head-actions .btn-label { display: none; }

  /* --- bottom tab navigation --- */
  .bottom-nav {
    display: flex; align-items: stretch;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-soft);
    border-top: 1px solid var(--border);
  }
  .bottom-nav .nav-item {
    position: relative;
    flex: 1; flex-direction: column; gap: 3px;
    justify-content: center; align-items: center;
    padding: 6px 4px; border-radius: 10px;
    font-size: 10.5px; text-align: center; width: auto;
  }
  .bottom-nav .nav-item .ic { width: 21px; height: 21px; }
  .bottom-nav .nav-item.active { background: none; }
  .bottom-nav .nav-item.active .ic { color: var(--accent); }
  .bottom-nav .nav-item.active span { color: var(--accent); }
  .bottom-nav .transfer-badge {
    position: absolute; top: 5px; left: calc(50% + 7px);
    margin-left: 0; padding: 0 5px; font-size: 9.5px;
  }

  /* --- cards & rows --- */
  .device-grid { grid-template-columns: 1fr; gap: 10px; }
  .device-card { padding: 14px; }
  .device-actions .btn { padding: 10px 8px; }
  .device-actions .btn span { font-size: 12.5px; }

  .file-row { padding: 10px 10px; gap: 10px; }
  .file-date { display: none; }
  .file-actions { gap: 4px; }
  .file-actions .btn { padding: 9px; }
  .transfer-item { padding: 12px 14px; }

  /* --- dialogs become bottom sheets --- */
  /* --kb-offset is set from JS when the on-screen keyboard is open, so the
     sheet (and its inputs) ride above the keyboard instead of under it. */
  .modal {
    left: 0; right: 0; top: auto;
    bottom: var(--kb-offset, 0px);
    transform: none;
    width: 100%; max-height: calc(85dvh - var(--kb-offset, 0px));
    border-radius: 18px 18px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    animation: sheet-up 0.22s ease-out;
    transition: bottom 0.15s ease-out;
  }
  .modal .row-end { gap: 10px; }
  .modal .row-end .btn { flex: 1; justify-content: center; padding: 12px; font-size: 14px; }
  @keyframes sheet-up { from { transform: translateY(100%); } }

  /* --- toasts above the bottom nav --- */
  .toasts {
    left: 14px; right: 14px; bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom));
  }
  .toast { max-width: none; }

  .settings { max-width: none; }
  .about-grid { max-width: 100%; }
}
