:root {
  --bg: #0f1319;
  --panel: #19212c;
  --panel-2: #212b39;
  --line: #2b3646;
  --text: #e9eef6;
  --muted: #93a1b4;
  --amber: #ffb020;
  --amber-soft: rgba(255, 176, 32, 0.14);
  --danger: #ff6b6b;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(900px 480px at 50% -12%, #1d2836 0%, rgba(15, 19, 25, 0) 62%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-bottom: calc(28px + var(--safe-bottom));
}

body.lock { overflow: hidden; }

button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: rgba(15, 19, 25, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(43, 54, 70, 0.7);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: #14181f;
  background: linear-gradient(160deg, #ffc247, #ff9c07);
  box-shadow: 0 6px 16px rgba(255, 158, 7, 0.25);
  flex: none;
}

.brand-text { min-width: 0; }

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex: none;
}

.ghost-btn:active { transform: scale(0.97); }
.ghost-btn.wide { width: 100%; justify-content: center; padding: 13px; }

.primary-btn {
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  background: linear-gradient(160deg, #ffc247, #ff9c07);
  color: #191307;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(255, 158, 7, 0.22);
}

.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.6; }
.primary-btn.wide { width: 100%; padding: 14px; }

/* ---------- search ---------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 14px calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  padding: 0 13px;
  height: 44px;
  border-radius: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
}

.searchbar input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.searchbar input::placeholder { color: #6f7d90; }
.searchbar input::-webkit-search-cancel-button { filter: invert(0.7); }

/* ---------- layout ---------- */
main {
  padding: 16px calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  max-width: 780px;
  margin: 0 auto;
}

.section-head, .folder-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2, .folder-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}

.section-head.spaced { margin-top: 24px; }

.folder-head h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 20px; }
.counter { font-size: 12.5px; color: var(--muted); flex: none; }

/* ---------- folder tiles ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 620px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.tile-wrap { position: relative; }

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 118px;
  padding: 13px 14px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(165deg, #223042 0%, var(--panel) 62%);
  cursor: pointer;
  overflow: hidden;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--amber), rgba(255, 176, 32, 0.1));
}

.tile:active { transform: scale(0.985); }

.tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.tile-count {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #ffce7a;
  background: var(--amber-soft);
  border-radius: 999px;
  padding: 3px 8px;
}

.tile-bolt { color: var(--amber); font-size: 13px; opacity: 0.8; }

.tile-name {
  font-size: 15.5px;
  font-weight: 650;
  line-height: 1.25;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-hint { font-size: 11.5px; color: var(--muted); }

.more {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.more:active { background: rgba(255, 255, 255, 0.07); }

/* ---------- breadcrumbs ---------- */
.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 12px;
  font-size: 13px;
}

.crumb {
  border: none;
  background: transparent;
  color: var(--amber);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 7px;
  border-radius: 8px;
  cursor: pointer;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb:active { background: rgba(255, 176, 32, 0.12); }
.crumb-current { color: var(--text); font-weight: 700; cursor: default; }
.crumb-sep { color: #4b5a6d; }

/* ---------- import + top add ---------- */
.import-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 18px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  border: 1px dashed #45596f;
  border-radius: 14px;
  background: rgba(33, 43, 57, 0.5);
}

.import-btn:active { background: #243040; }
.import-icon { font-size: 18px; color: var(--amber); }
.import-btn strong { display: block; font-size: 14px; font-weight: 650; }
.import-btn small { display: block; margin-top: 2px; font-size: 11.5px; color: var(--muted); }

.add-btn { padding: 10px 15px; font-size: 14px; }

/* ---------- backup + restore ---------- */
.backup-row {
  display: flex;
  gap: 10px;
  margin: -6px 0 18px;
}

.backup-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #1b242f;
  color: var(--text);
}

.backup-btn:active { background: #243040; }
.backup-icon { font-size: 17px; color: var(--amber); }
.backup-btn strong { display: block; font-size: 13.5px; font-weight: 650; }
.backup-btn small { display: block; margin-top: 2px; font-size: 10.5px; color: var(--muted); }

.section-head.tight { margin-top: 18px; margin-bottom: 10px; }

/* ---------- progress ---------- */
.progress {
  height: 8px;
  border-radius: 999px;
  background: #223041;
  overflow: hidden;
  margin: 4px 0 18px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffc247, #ff9c07);
  transition: width 0.2s;
}

/* ---------- file list ---------- */
.file-list { display: flex; flex-direction: column; gap: 9px; }

.file-row {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  overflow: hidden;
}

.file-open {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 12px 44px 12px 12px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.file-open:active { background: rgba(255, 255, 255, 0.04); }

.file-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 46px;
  flex: none;
  border-radius: 7px;
  background: #2a3442;
  border: 1px solid #3a4859;
  color: #ffc247;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
}

.file-meta { min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.file-name {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.file-info { font-size: 11.5px; color: var(--muted); }

.file-row .more { top: 50%; transform: translateY(-50%); }

/* ---------- empty state ---------- */
.empty {
  margin-top: 8px;
  padding: 30px 20px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(25, 33, 44, 0.5);
}

.empty.small { padding: 22px 16px; }
.empty-icon { font-size: 30px; }
.empty h3 { margin: 10px 0 6px; font-size: 16px; }
.empty p { margin: 0 auto 16px; max-width: 340px; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.empty em { color: #ffce7a; font-style: normal; }

/* ---------- overlays & sheets ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 12, 0.66);
  backdrop-filter: blur(2px);
}

.sheet {
  position: relative;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 10px 18px calc(20px + var(--safe-bottom));
  border-radius: 22px 22px 0 0;
  background: #151c25;
  border-top: 1px solid var(--line);
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.22s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-grip {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #3a4757;
  margin: 0 auto 14px;
}

.sheet h2 { margin: 0 0 4px; font-size: 19px; }
.sheet h2.action-title { margin-bottom: 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.sheet-sub { margin: 0 0 18px; font-size: 13px; line-height: 1.5; color: var(--muted); }

.field-label {
  display: block;
  margin: 16px 0 7px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.text-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f151d;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

select.text-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, #93a1b4 50%), linear-gradient(135deg, #93a1b4 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.text-input:focus { border-color: #4a5d75; box-shadow: 0 0 0 3px rgba(255, 176, 32, 0.1); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.chips:empty { display: none; }

.chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #1b242f;
  color: #c7d3e2;
  font-size: 12.5px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:active { background: var(--amber-soft); }

.file-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border-radius: 13px;
  border: 1px dashed #3c4c60;
  background: rgba(33, 43, 57, 0.55);
  text-align: left;
  cursor: pointer;
}

.file-pick strong { display: block; font-size: 14.5px; font-weight: 650; }
.file-pick small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.file-pick-icon { font-size: 20px; }

.picked { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.picked:empty { display: none; }

.picked-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  background: #1b242f;
  border: 1px solid var(--line);
  font-size: 13px;
}

.picked-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked-item small { color: var(--muted); flex: none; }

.picked-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  padding: 2px 6px;
  cursor: pointer;
}

.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }

.action-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }

.sheet-action {
  width: 100%;
  padding: 14px;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #1b242f;
  font-size: 15px;
  cursor: pointer;
}

.sheet-action:active { background: #243040; }
.sheet-action.danger { color: var(--danger); border-color: rgba(255, 107, 107, 0.32); }

/* ---------- viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  background: #0a0d12;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: #131a23;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.viewer-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-tools { display: flex; gap: 6px; flex: none; }

.vbtn {
  display: grid;
  place-items: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1b242f;
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.vbtn:active { background: #253141; }

.page-strip {
  position: relative;
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.page {
  position: relative;
  flex: none;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.page canvas { display: block; }

.page-num {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(12, 16, 22, 0.62);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.viewer-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: #131a23;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: #c4d0df;
  flex: none;
}

.viewer-foot span { min-width: 62px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + var(--safe-bottom));
  transform: translate(-50%, 16px);
  z-index: 95;
  max-width: min(90vw, 420px);
  padding: 11px 18px;
  border-radius: 999px;
  background: #26313f;
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 13.5px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- sync badge ---------- */
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: #ffce7a;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.sync-badge:active { transform: scale(0.97); }
.sync-badge.busy { color: var(--amber); }
.sync-badge.busy::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  animation: sync-pulse 1.1s ease-in-out infinite;
}

@keyframes sync-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

/* ---------- open with ---------- */
.file-row .file-open { padding-right: 58px; }

.open-with {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #1b242f;
  color: var(--amber);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.open-with:active { background: #253141; }

.sync-detail {
  margin: -6px 0 16px;
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-word;
}
