/* Design system shared with PDF Ways, Banking Pages and Task in the Mind:
   cream / warm-charcoal surfaces, clay accent, serif display type, soft bordered cards,
   round bordered icon buttons, springy press + staggered rise + push transitions. */

/* ============ Tokens ============ */
:root {
  --bg: #FAF9F5; --surface: #FFFFFF; --raised: #F0EEE6; --outline: #DFDACD;
  --ink: #1F1E1D; --muted: #5C5A54;
  --primary: #C15F3C; --primary-pressed: #A84F30; --on-primary: #FFFFFF;
  --primary-soft: rgb(193 95 60 / .12);
  --danger: #A3352A; --success: #1B7334; --success-soft: #ECF5ED; --warning: #9A6212;
  --bar: rgb(250 249 245 / .82);
  --scrim: rgb(31 30 29 / .38);
  --shadow: 0 1px 2px rgb(31 30 29 / .04), 0 8px 24px rgb(31 30 29 / .06);
  --shadow-lg: 0 24px 60px rgb(31 30 29 / .18);

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-card: 16px; --r-control: 14px; --r-dialog: 24px; --r-tag: 7px;

  /* Springs (Motion.kt): bouncy ≈ damping .55, smooth ≈ .85, snappy for press-in */
  --bouncy: linear(0, .06 2%, .23 5%, .5 9%, .78 14%, .98 19%, 1.09 24%, 1.12 28%, 1.1 33%, 1.04 40%, 1 47%, .985 55%, .99 65%, 1);
  --smooth: linear(0, .08 3%, .31 8%, .6 14%, .82 21%, .95 29%, 1.01 37%, 1.02 45%, 1.005 60%, 1);
  --snappy: cubic-bezier(.3, .7, .4, 1);
  --stagger: 45ms;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1F1E1D; --surface: #262624; --raised: #30302E; --outline: #413F3B;
  --ink: #F5F4EF; --muted: #B4B0A6;
  --primary: #D97757; --primary-pressed: #C2664A; --on-primary: #1F1E1D;
  --primary-soft: rgb(217 119 87 / .16);
  --danger: #E58A7C; --success: #7FC98D; --success-soft: #233026; --warning: #E0B054;
  --bar: rgb(31 30 29 / .8);
  --scrim: rgb(0 0 0 / .55);
  --shadow: 0 1px 2px rgb(0 0 0 / .2), 0 8px 24px rgb(0 0 0 / .18);
  --shadow-lg: 0 24px 60px rgb(0 0 0 / .45);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 16px/1.55 var(--sans); letter-spacing: .01em;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.icon { width: 20px; height: 20px; flex: none; display: block; }

/* ============ Shared components ============ */
/* Press bounce: shrink on a snappy curve, release on the bouncy spring (bounceClick). */
.press { transition: transform .55s var(--bouncy), background-color .2s, color .2s; }
.press:active { transform: scale(var(--press, .95)); transition: transform .12s var(--snappy); }

.round-icon {
  position: relative; width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--outline);
  transition: transform .55s var(--bouncy), background-color .2s, color .2s;
}
.round-icon:active { transform: scale(.9); transition: transform .12s var(--snappy); }
@media (hover: hover) { .round-icon:hover { color: var(--ink); background: var(--raised); } }
.round-icon.accent { color: var(--primary); }
.round-icon.small { width: 36px; height: 36px; }
.round-icon.small .icon { width: 18px; height: 18px; }
.round-icon:disabled { opacity: .4; pointer-events: none; }
.round-icon .sun { display: none; }
:root[data-theme="dark"] .round-icon .sun { display: block; }
:root[data-theme="dark"] .round-icon .moon { display: none; }
.round-icon.spin .icon { animation: spin-once .6s var(--bouncy); }
@keyframes spin-once { from { transform: rotate(-120deg) scale(.6); } }
.round-icon.loading .icon { opacity: 0; }
.round-icon.loading::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2.2px solid var(--outline); border-top-color: var(--primary); animation: spin .7s linear infinite; }
.round-icon.done { animation: pop-in .5s var(--bouncy); color: var(--success); }
@keyframes spin { to { transform: rotate(360deg); } }

.bubble {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--primary); background: var(--raised);
  transition: transform .55s var(--bouncy);
}
.bubble.big { width: 64px; height: 64px; }
.bubble.big .icon { width: 28px; height: 28px; }
.bubble.success { color: var(--success); background: var(--success-soft); }

.card {
  background: var(--surface); border-radius: var(--r-card);
  box-shadow: inset 0 0 0 1px var(--outline), var(--shadow);
}
.section-label {
  font: 600 11.5px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 26px 4px 10px;
}
.tag {
  display: inline-block; padding: 2px 7px; border-radius: var(--r-tag);
  font: 600 10px/1.5 var(--sans); letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); background: var(--raised);
}
.btn {
  --press: .96;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 50px; padding: 0 28px; border-radius: var(--r-control);
  font: 600 15px/1 var(--sans); color: var(--on-primary); background: var(--primary);
}
@media (hover: hover) { .btn:hover { background: var(--primary-pressed); } }

/* Entrance (Motion.entrance): rise 36px + scale .94 → 1 on the smooth spring, 45 ms stagger. */
@keyframes rise { from { opacity: 0; transform: translateY(36px) scale(.94); } }
@keyframes pop-in { from { opacity: 0; transform: scale(.4); } }
.rise { animation: rise .7s var(--smooth) backwards; animation-delay: calc(var(--d, 0ms) + var(--i, 0) * var(--stagger)); }
.pop { animation: pop-in .6s var(--bouncy) backwards; animation-delay: var(--d, 0ms); }

/* ============ PIN panel (lock + change PIN) ============ */
.pin-panel { display: flex; flex-direction: column; align-items: center; text-align: center; width: 100%; max-width: 360px; margin: 0 auto; }
.pin-panel h2 { font: 400 28px/1.25 var(--serif); letter-spacing: -.01em; margin-top: 18px; }
.pin-sub { margin-top: 6px; font-size: 14.5px; color: var(--muted); min-height: 1.55em; transition: color .2s; }
.pin-sub.error { color: var(--danger); }
.dots { display: flex; gap: 11px; margin: 26px 0 0; height: 16px; align-items: center; }
.dot {
  width: 14px; height: 14px; border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--outline);
  transform: scale(.72); transition: transform .55s var(--bouncy), background-color .2s, box-shadow .2s;
}
.dot:nth-child(6) { margin-left: 9px; }
.dot.on { transform: scale(1); background: var(--primary); box-shadow: inset 0 0 0 1.5px var(--primary); }
.dots.error .dot { background: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger); }
.dots.ok .dot { background: var(--success); box-shadow: inset 0 0 0 1.5px var(--success); animation: pop-in .5s var(--bouncy) backwards; animation-delay: calc(var(--n) * 30ms); }
.dots.shake { animation: shake .45s linear; }
@keyframes shake { 15% { transform: translateX(14px); } 35% { transform: translateX(-12px); } 55% { transform: translateX(9px); } 72% { transform: translateX(-6px); } 88% { transform: translateX(3px); } }

.keypad { --key: 76px; display: grid; grid-template-columns: repeat(3, var(--key)); gap: 14px 24px; margin-top: 34px; }
.key {
  width: var(--key); height: var(--key); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--outline);
  touch-action: manipulation; user-select: none;
  transition: transform .55s var(--bouncy), background-color .25s, box-shadow .25s;
}
.key .num { font: 400 28px/1 var(--sans); }
.key .abc { font: 500 9px/1 var(--sans); letter-spacing: .18em; color: var(--muted); min-height: 9px; }
.key.pressed { transform: scale(.9); background: var(--raised); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 50%, transparent); transition-duration: .12s; transition-timing-function: var(--snappy); }
@media (hover: hover) { .key:hover { background: var(--raised); } }
.key.side { background: transparent; box-shadow: none; color: var(--primary); }
.key.side .icon { width: 28px; height: 28px; }
.key.side.pressed { background: var(--primary-soft); box-shadow: none; }
.keypad.locked { opacity: .4; pointer-events: none; transition: opacity .3s; }
.pin-footer { margin-top: 18px; min-height: 44px; display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.panel-swap { will-change: transform, opacity; }

/* ============ Lock screen ============ */
.lock { min-height: 100svh; display: flex; align-items: center; justify-content: center; padding: max(28px, env(safe-area-inset-top)) 24px max(20px, env(safe-area-inset-bottom)); }
.lock-theme { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; z-index: 5; }
.lock.leaving #lockPanel { animation: lock-out .45s var(--snappy) forwards; }
@keyframes lock-out { to { opacity: 0; transform: scale(1.06); } }
@media (max-height: 740px) { .lock .keypad { --key: 64px; gap: 10px 22px; margin-top: 24px; } .key .num { font-size: 24px; } .pin-panel h2 { font-size: 24px; margin-top: 12px; } .dots { margin-top: 18px; } }
@media (max-height: 600px) { .lock .bubble.big { display: none; } }

/* ============ Vault ============ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bar); border-bottom: 1px solid transparent;
  -webkit-backdrop-filter: blur(18px) saturate(140%); backdrop-filter: blur(18px) saturate(140%);
  transition: border-color .25s;
}
.topbar.scrolled { border-bottom-color: var(--outline); }
.topbar-inner { width: min(760px, 100%); margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; }
.heading { flex: 1; min-width: 0; }
.heading h1, .heading h3 { font: 400 24px/1.25 var(--serif); letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heading p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.timer {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; flex: none;
  font: 600 13px/1 var(--sans); font-variant-numeric: tabular-nums; white-space: nowrap;
  color: var(--on-primary); background: var(--primary);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 30%, transparent);
  transition: background-color .25s;
}
.timer .icon { width: 15px; height: 15px; }
.timer.warn { background: var(--danger); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.content { width: min(760px, 100%); margin: 0 auto; padding: 8px 16px max(48px, env(safe-area-inset-bottom)); }
.search {
  display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 16px; margin-top: 6px;
  border-radius: var(--r-control); background: var(--surface); color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--outline); transition: box-shadow .2s;
}
.search:focus-within { box-shadow: inset 0 0 0 1.5px var(--primary), 0 0 0 4px var(--primary-soft); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; }
.search input::placeholder { color: var(--muted); }

.list { overflow: hidden; }
.row { position: relative; display: flex; align-items: center; transition: background-color .2s; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 74px; right: 0; height: 1px; background: var(--outline); }
.row-main { --press: .97; flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; text-align: left; padding: 13px 16px; min-height: 72px; }
.row.file .row-main { padding-right: 8px; }
@media (hover: hover) {
  .row:hover { background: color-mix(in srgb, var(--raised) 55%, transparent); }
  .row-main:hover .bubble { transform: scale(1.08) rotate(-4deg); }
  .row:hover .chev { transform: translateX(4px); }
}
.thumb { width: 44px; height: 44px; flex: none; border-radius: 12px; object-fit: cover; background: var(--raised); box-shadow: inset 0 0 0 1px var(--outline); }
.row-text { flex: 1; min-width: 0; }
.row-name { font: 500 16px/1.4 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: flex; align-items: center; gap: 8px; margin-top: 3px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.chev { color: var(--muted); margin-right: 16px; transition: transform .55s var(--bouncy); }
.row-actions { display: flex; gap: 6px; padding-right: 12px; }
.row-actions .round-icon { width: 38px; height: 38px; }
.row-actions .round-icon .icon { width: 18px; height: 18px; }

.skeleton-row { height: 72px; display: flex; align-items: center; gap: 14px; padding: 0 16px; }
.skeleton-row + .skeleton-row { border-top: 1px solid var(--outline); }
.sk { background: linear-gradient(100deg, var(--raised) 35%, color-mix(in srgb, var(--raised) 40%, var(--surface)) 50%, var(--raised) 65%); background-size: 300% 100%; animation: shimmer 1.2s linear infinite; border-radius: 8px; }
.sk.circle { width: 44px; height: 44px; border-radius: 50%; flex: none; }
.sk.line { height: 12px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 64px 24px; }
.empty-title { font: 400 22px/1.3 var(--serif); margin-top: 16px; }
.empty-sub { color: var(--muted); font-size: 14px; margin-top: 6px; max-width: 300px; }

/* ============ Viewer ============ */
.viewer, .modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .3s; }
.open > .scrim { opacity: 1; }
.sheet {
  position: relative; width: min(980px, 100%); height: min(90svh, 1100px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); border-radius: var(--r-dialog); box-shadow: inset 0 0 0 1px var(--outline), var(--shadow-lg);
}
.sheet-bar { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--outline); background: var(--bg); }
.sheet-bar h3 { font-size: 20px; }
.zoom-group { display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 999px; box-shadow: inset 0 0 0 1px var(--outline); background: var(--surface); }
.zoom-group .round-icon { box-shadow: none; background: transparent; }
.zoom-val { min-width: 46px; text-align: center; font: 600 12.5px/1 var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet-body { flex: 1; overflow: auto; overscroll-behavior: contain; display: grid; place-items: start safe center; gap: 14px; padding: 18px; background: var(--raised); }
.sheet-body img { width: calc(var(--z, 1) * 100%); max-width: calc(var(--z, 1) * 100%); max-height: calc(var(--z, 1) * 100%); object-fit: contain; margin: auto; border-radius: 12px; box-shadow: var(--shadow); cursor: zoom-in; }
.sheet-body canvas { width: calc(var(--z, 1) * 100%); max-width: calc(var(--z, 1) * 900px); height: auto; border-radius: 6px; background: #fff; box-shadow: inset 0 0 0 1px var(--outline), var(--shadow); }
.sheet-body > * { animation: rise .6s var(--smooth) backwards; }
.v-loading { margin: auto; align-self: center; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--outline); border-top-color: var(--primary); animation: spin .8s linear infinite !important; }
.fallback { margin: auto; align-self: center; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; color: var(--muted); }
@media (max-width: 640px) {
  .viewer { padding: 0; }
  .sheet { width: 100%; height: 100svh; border-radius: 0; box-shadow: none; }
  .sheet-bar { padding-top: max(12px, env(safe-area-inset-top)); gap: 8px; }
  .sheet-bar h3 { font-size: 17px; }
  .zoom-val { display: none; }
  .sheet-body { padding: 12px; }
}
@media (max-width: 400px) { .zoom-group { display: none; } }

/* ============ Change-PIN dialog ============ */
.dialog {
  position: relative; width: min(420px, 100%); max-height: calc(100svh - 40px); overflow: auto;
  padding: 30px 24px 18px; background: var(--bg); border-radius: var(--r-dialog);
  box-shadow: inset 0 0 0 1px var(--outline), var(--shadow-lg);
}
.dialog-close { position: absolute; top: 14px; right: 14px; z-index: 1; }
.dialog .keypad { --key: 68px; gap: 12px 22px; margin-top: 26px; }
.dialog .pin-panel h2 { font-size: 24px; }
.steps { display: flex; gap: 6px; margin-top: 14px; }
.steps i { width: 22px; height: 4px; border-radius: 4px; background: var(--outline); transition: background-color .3s, width .55s var(--bouncy); }
.steps i.on { background: var(--primary); width: 34px; }
.done-panel { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 26px 0 10px; }
.done-panel h2 { font: 400 26px/1.25 var(--serif); margin-top: 18px; }
.done-panel p { color: var(--muted); margin: 8px 0 26px; max-width: 280px; }
@media (max-width: 480px) {
  .modal { padding: 0; align-items: end; }
  .dialog { width: 100%; max-height: 100svh; border-radius: var(--r-dialog) var(--r-dialog) 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}
@media (max-height: 760px) { .dialog .keypad { --key: 58px; gap: 8px 20px; margin-top: 18px; } .dialog .key .num { font-size: 22px; } .dialog .bubble.big { width: 52px; height: 52px; } }

/* ============ Toast, privacy veil ============ */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 80; max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: var(--r-control); font-size: 14px; font-weight: 500;
  color: var(--bg); background: var(--ink); box-shadow: var(--shadow-lg);
  transform: translateX(-50%); animation: toast-in .55s var(--bouncy) both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 24px) scale(.9); } }
.privacy { position: fixed; inset: 0; z-index: 100; background: var(--bg); opacity: 0; pointer-events: none; transition: opacity .15s; }
body.veiled .privacy { opacity: 1; }

::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

@media (max-width: 520px) {
  .topbar-inner { gap: 10px; padding-left: 14px; padding-right: 14px; }
  .bar-actions { gap: 6px; }
  .bar-actions .round-icon { width: 40px; height: 40px; }
  .heading h1 { font-size: 22px; }
}
@media (max-width: 520px) { .timer { height: 32px; padding: 0 10px; gap: 5px; font-size: 12.5px; } .timer .icon { width: 13px; height: 13px; } }
@media (max-width: 360px) { .timer .icon { display: none; } }

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

/* Phones: buttons + timer on the first line, the (possibly long) folder title gets its own full-width line. */
@media (max-width: 520px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 6px; }
  .topbar-inner .heading { order: 2; flex-basis: 100%; }
  .topbar-inner .bar-actions { margin-left: auto; }
  .heading h1 { font-size: 26px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}
