/* ============================================================================
   OFFLINE DRIVE — "ink & parchment" redesign.
   Warm cream paper, deep ink, terracotta, muted gold. Hand-drawn SVG icons.
   Mobile-first, zero horizontal scroll, tap targets ≥48px.

   Design notes (from the audit):
   · `.view[hidden] { display:none !important }` — fixes login card never
     hiding (display:flex was overriding the hidden attribute).
   · Password visibility toggle, login busy state, focus-visible rings.
   · Higher-contrast secondary text; tighter, calmer card.
   ========================================================================== */

:root {
  --paper: #f4ecdc;        /* page background */
  --paper-deep: #ebe0c9;
  --card: #fdf8ee;         /* cards / panels */
  --card-2: #f6edda;
  --ink: #2e2417;          /* primary text */
  --ink-soft: #6b5b42;     /* secondary text */
  --muted: #94836a;        /* tertiary / meta */
  --line: #e2d3b2;         /* borders */
  --line-soft: #ece0c6;
  --accent: #b3562a;       /* terracotta */
  --accent-deep: #8f4119;
  --accent-soft: #f3ddc6;
  --gold: #d9a441;
  --green: #5f7d43;
  --red: #b0413e;
  --shadow: 0 1px 2px rgba(70, 50, 15, .07), 0 14px 34px -18px rgba(70, 50, 15, .30);
  --radius: 16px;
  --radius-sm: 11px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(1100px 480px at 88% -10%, rgba(217, 164, 65, .12), transparent 60%),
    radial-gradient(900px 420px at -12% 0%, rgba(179, 86, 42, .07), transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── the one that fixes everything ─────────────────────────────────────── */
.view[hidden] { display: none !important; }

#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 32px) calc(var(--sal) + 16px);
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

/* ── buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(70, 50, 15, .06);
  transition: background .15s ease, transform .05s ease, box-shadow .15s ease, border-color .15s ease;
  text-decoration: none;
  user-select: none;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover { background: var(--card-2); border-color: #d8c69c; }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-deep);
  color: #fff8ec;
  box-shadow: 0 2px 3px rgba(143, 65, 25, .25);
}
.btn.primary:hover { background: var(--accent-deep); }

.btn.ghost { background: transparent; border-color: var(--line-soft); color: var(--ink-soft); }
.btn.ghost:hover { background: var(--card-2); color: var(--ink); }

.btn.small { min-height: 40px; padding: 6px 14px; font-size: 14px; }
.btn.tiny { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn.block { width: 100%; }

.btn.busy { pointer-events: none; opacity: .8; }
.btn.busy .btn-label::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 10px;
  border: 2px solid rgba(255, 248, 236, .4);
  border-top-color: #fff8ec;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  transition: background .15s ease, color .15s ease;
}
.iconbtn:hover { background: var(--card-2); color: var(--ink); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:disabled { opacity: .38; cursor: default; }

/* ── login view ───────────────────────────────────────────────────────── */
.login-view {
  min-height: calc(100dvh - var(--sat) - var(--sab) - 32px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

.login-card {
  width: 100%;
  max-width: 384px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 30px 28px 24px;
  text-align: center;
}

.doodle { color: var(--accent); margin: 0 auto 4px; }
.doodle svg { width: 104px; height: auto; }

.login-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: .2px;
  margin: 4px 0 2px;
  color: var(--ink);
}

.tagline {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 14px;
  font-style: italic;
  font-family: var(--serif);
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 14px;
}
.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: #fffdf6;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:hover { border-color: #d8c69c; }
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179, 86, 42, .15);
}

/* password eye toggle */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--muted);
  transition: color .15s ease, background .15s ease;
}
.pw-toggle:hover { color: var(--accent-deep); background: var(--accent-soft); }
.pw-toggle svg { width: 20px; height: 20px; }

.form-error {
  color: var(--red);
  font-size: 14px;
  margin: 0 0 12px;
  padding: 9px 12px;
  background: #fbeae6;
  border: 1px solid #f2cdc5;
  border-radius: var(--radius-sm);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.login-card.shake { animation: shake .25s ease 2; }

.login-foot {
  margin: 18px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ── main view / header ───────────────────────────────────────────────── */
.main-view { padding-top: 2px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 10px;
}

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

.brand-doodle {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(70, 50, 15, .05);
}
.brand-doodle svg { width: 26px; height: 26px; }

.brand-text h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
}

.usage-text {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.usagebar {
  height: 8px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
  border: 1px solid var(--line-soft);
  margin-bottom: 16px;
}
.usage-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width .5s ease;
}
.usage-fill.warn { background: linear-gradient(90deg, var(--red), #d98a4a); }

/* ── breadcrumbs ──────────────────────────────────────────────────────── */
.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.crumbs::-webkit-scrollbar { display: none; }

.crumb-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.crumb-wrap::-webkit-scrollbar { display: none; }

.crumb {
  flex: none;
  max-width: 180px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--card);
  border: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .15s ease, color .15s ease;
}
.crumb:hover { background: var(--card-2); color: var(--ink); }
.crumb.current { color: var(--accent-deep); background: var(--accent-soft); border-color: var(--accent-soft); font-weight: 600; }
.crumb + .crumb::before {
  content: "›";
  color: var(--muted);
  margin-right: 6px;
  font-size: 16px;
}

/* ── toolbar ──────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar-spacer { flex: 1; }

.sortbar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.sort-btn {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}
.sort-btn:hover { color: var(--ink); }
.sort-btn.on { background: var(--accent-soft); color: var(--accent-deep); }

/* ── file grid ────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 14px 14px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(70, 50, 15, .05);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, border-color .15s ease;
}
.item:hover { border-color: #d8c69c; box-shadow: var(--shadow); transform: translateY(-1px); }
.item:active { transform: translateY(0); }

.ic-wrap { width: 46px; height: 46px; flex: none; }
.ic-wrap svg { width: 100%; height: 100%; display: block; }

.ic-folder { color: var(--gold); }
.ic-file   { color: #a08a5f; }
.ic-image  { color: #4f8f7a; }
.ic-video  { color: #7a6cb0; }
.ic-audio  { color: #c07a2a; }
.ic-pdf    { color: #c04a3a; }
.ic-archive{ color: #8a7a3a; }
.ic-code   { color: #4f6f9f; }

.item-body { min-width: 0; }

.item-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  word-break: break-word;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-meta {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* per-item size bar — visual share of total used space */
.sizebar {
  margin-top: 8px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}
.sizebar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #d9a441, #b3562a);
  opacity: .75;
  min-width: 0;
}
.item.is-dir .sizebar-fill { background: linear-gradient(90deg, #c9a24e, #a87b2c); }

.item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
  padding-top: 6px;
  opacity: 0;
  transition: opacity .15s ease;
}
.item:hover .item-actions { opacity: 1; }

/* Touch devices have no hover — always show the actions */
@media (hover: none), (pointer: coarse) {
  .item-actions { opacity: 1; }
}

.act-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: var(--ink-soft);
  transition: background .15s ease, color .15s ease;
}
.act-btn:hover { background: var(--paper); color: var(--accent-deep); }
.act-btn.delete:hover { color: var(--red); background: #fbeae6; }
.act-btn svg { width: 19px; height: 19px; }

/* ── empty state ──────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 56px 20px 40px;
  color: var(--muted);
}
.empty-doodle { color: #c9b48d; margin-bottom: 10px; }
.empty-doodle svg { width: 92px; height: auto; }
.empty-title { font-family: var(--serif); font-size: 20px; color: var(--ink-soft); margin: 0 0 4px; }
.empty-sub { margin: 0; font-size: 14px; }

/* ── drop overlay ─────────────────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: calc(var(--sat) + 8px) calc(var(--sar) + 8px) calc(var(--sab) + 8px) calc(var(--sal) + 8px);
  z-index: 40;
  border: 2.5px dashed var(--accent);
  border-radius: 24px;
  background: rgba(244, 236, 220, .93);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-overlay[hidden] { display: none !important; }
.drop-box {
  text-align: center;
  color: var(--accent-deep);
  padding: 40px;
}
.drop-box svg { width: 64px; height: 64px; margin-bottom: 10px; }
.drop-box p { font-family: var(--serif); font-size: 22px; margin: 0; }

/* ── upload panel ─────────────────────────────────────────────────────── */
.upload-panel {
  position: fixed;
  right: calc(var(--sar) + 16px);
  bottom: calc(var(--sab) + 16px);
  width: min(360px, calc(100vw - 32px));
  z-index: 30;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px 12px;
}
.upload-panel[hidden] { display: none !important; }
.up-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.up-title { font-family: var(--serif); font-size: 15px; font-weight: 600; }
.up-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.up-row { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 4px 8px; align-items: center; }
.up-name {
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.up-pct { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.up-bar { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.up-fill { height: 100%; width: 0%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .2s ease; }
.up-row.done .up-fill { background: var(--green); }
.up-row.fail .up-fill { background: var(--red); }
.up-row.fail .up-name { color: var(--red); }

/* ── modal ────────────────────────────────────────────────────────────── */
.modal-overlay[hidden] { display: none !important; }
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(46, 36, 23, .42);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px 22px 18px;
}
.modal h2 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 8px;
  color: var(--ink);
}
.modal-msg {
  margin: 0 0 14px;
  font-size: 14.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.modal-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: #fffdf6;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.modal-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179, 86, 42, .15);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── toasts ───────────────────────────────────────────────────────────── */
.toast-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--sab) + 18px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 1;
  transition: opacity .3s ease, transform .3s ease;
  animation: toast-in .25s ease;
}
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.foot {
  text-align: center;
  margin-top: 34px;
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
}

/* ── motion safety ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
