/* Lendr — warm neighborly-ledger design. Vanilla, no build step. */
/* Palette derived from the logo: navy #031d37, orange #fa4c22, yellow #fcac1d.
   Solid buttons use a slightly deeper orange than the logo's: white text on
   #fa4c22 is only 3.43:1, under the 4.5:1 needed at this weight, while #d63a12
   reads as the same orange and clears it at 4.69:1. The artwork keeps the
   true logo orange. */
:root{
  --paper:#f6f8fb; --ink:#031d37; --muted:#5b6c7e; --faint:#78889a;
  --line:#dce4ed; --line-soft:#e8eef4;
  --brand:#d63a12; --brand-ink:#b8300c; --brand-wash:#fdeae4;
  --card:#ffffff; --card-2:#f1f5f9;
  --out:#d63a12; --in:#14507d; --in-wash:#e3eef8;
  --warn:#c07a06; --warn-ink:#8a5704; --warn-wash:#fef4de;   /* logo yellow, darkened for text */
  --danger:#b42318; --overdue:#a5231a; --overdue-wash:#fdeceb;
  --ok:#0f7a52;
  --shadow:0 1px 2px rgba(3,29,55,.05), 0 6px 20px rgba(3,29,55,.07);
  --shadow-lg:0 8px 40px rgba(3,29,55,.20);
  --r:16px; --r-sm:11px;
  --safe-b:env(safe-area-inset-bottom,0px);
  --safe-t:env(safe-area-inset-top,0px);
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--paper);color:var(--ink);line-height:1.45;
  -webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent;
}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit}
input,select,textarea{font-family:inherit;font-size:16px;color:inherit}
.icon{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round;flex:none}
.brand-img{width:32px;height:auto;display:block}

/* ── App frame ─────────────────────────────────────────────────────────────── */
#app{min-height:100%}
.shell{max-width:720px;margin:0 auto;min-height:100%;display:flex;flex-direction:column}
.topbar{
  position:sticky;top:0;z-index:20;background:rgba(246,248,251,.92);backdrop-filter:blur(10px);
  border-bottom:1px solid var(--line-soft);padding:calc(var(--safe-t) + 12px) 18px 12px;
  display:flex;align-items:center;gap:12px;
}
.topbar .title{font-size:21px;font-weight:800;letter-spacing:-.02em;display:flex;align-items:center;gap:9px}
.topbar .spacer{flex:1}
.iconbtn{width:40px;height:40px;border-radius:11px;display:flex;align-items:center;justify-content:center;color:var(--ink);background:transparent}
.iconbtn:active{background:var(--brand-wash)}
.content{flex:1;padding:16px 18px calc(120px + var(--safe-b));}
.wide .content{padding-bottom:32px}

/* ── Bottom nav (phone) ────────────────────────────────────────────────────── */
.tabbar{
  position:fixed;left:0;right:0;bottom:0;z-index:30;
  background:rgba(255,255,255,.93);backdrop-filter:blur(14px);border-top:1px solid var(--line);
  display:flex;padding:8px 8px calc(8px + var(--safe-b));gap:4px;
}
.tabbar button{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;padding:7px 0;color:var(--faint);border-radius:12px;font-size:11px;font-weight:600;letter-spacing:.01em}
.tabbar button.active{color:var(--brand)}
.tabbar button .icon{width:24px;height:24px}
.tabbar button.active .icon{stroke-width:2.1}

/* iPad / desktop: sidebar */
.sidebar{display:none}
@media (min-width:768px){
  .wide .shell{max-width:100%;flex-direction:row}
  .wide .tabbar{display:none}
  .wide .sidebar{
    display:flex;flex-direction:column;gap:4px;width:230px;flex:none;
    border-right:1px solid var(--line);padding:calc(var(--safe-t) + 22px) 14px 22px;position:sticky;top:0;height:100vh;height:100dvh;
  }
  /* Desktop brand lockup: the 30px mark used in the phone top bar reads small
     against the sidebar's larger type, so scale both up together. */
  .wide .sidebar .side-brand{display:flex;align-items:center;gap:11px;font-size:24px;font-weight:800;letter-spacing:-.025em;padding:2px 8px 20px}
  .wide .sidebar .side-brand .brand-img{width:40px;height:auto}
  .wide .sidebar button.nav{display:flex;align-items:center;gap:12px;padding:11px 13px;border-radius:12px;color:var(--muted);font-size:15px;font-weight:600;text-align:left}
  .wide .sidebar button.nav.active{background:var(--brand-wash);color:var(--brand-ink)}
  /* Profile block, pinned to the bottom of the sidebar. Entry point to the
     account controls, which live on the Circle screen. */
  .wide .sidebar .side-profile{
    margin-top:auto;display:flex;align-items:center;gap:10px;width:100%;
    padding:9px 10px;border-radius:13px;border:1px solid var(--line);
    background:var(--card);text-align:left;transition:background .15s ease,border-color .15s ease;
  }
  .wide .sidebar .side-profile:hover{background:var(--card-2)}
  .wide .sidebar .side-profile.active{border-color:var(--brand);background:var(--brand-wash)}
  .wide .sidebar .side-profile .who{flex:1;min-width:0}
  .wide .sidebar .side-profile .nm{font-weight:700;font-size:14px;letter-spacing:-.01em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .wide .sidebar .side-profile .em{font-size:11.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .wide .sidebar .side-profile .icon{width:16px;height:16px;color:var(--faint)}
  .avatar.sm{width:34px;height:34px;font-size:12.5px}
  .wide .main{flex:1;min-width:0;display:flex;flex-direction:column;max-width:820px}
  .wide .content{padding:20px 30px 40px}
}

/* ── Segmented control ─────────────────────────────────────────────────────── */
.seg{display:flex;background:var(--card-2);border:1px solid var(--line);border-radius:12px;padding:3px;gap:2px;margin-bottom:16px}
.seg button{flex:1;padding:8px 6px;border-radius:9px;font-size:13.5px;font-weight:600;color:var(--muted);letter-spacing:.01em}
.seg button.active{background:var(--card);color:var(--ink);box-shadow:0 1px 2px rgba(3,29,55,.08)}

/* ── Cards / list rows ─────────────────────────────────────────────────────── */
.stack{display:flex;flex-direction:column;gap:11px}
.row{
  display:flex;gap:14px;align-items:center;background:var(--card);border:1px solid var(--line);
  border-radius:var(--r);padding:13px 14px;box-shadow:var(--shadow);text-align:left;width:100%;
  transition:transform .06s ease;
}
.row:active{transform:scale(.992)}
.row.done{opacity:.62}
.thumb{width:52px;height:52px;border-radius:12px;flex:none;object-fit:cover;background:var(--brand-wash)}
.thumb-ph{width:52px;height:52px;border-radius:12px;flex:none;display:flex;align-items:center;justify-content:center;background:var(--brand-wash);color:var(--brand-ink)}
.thumb-ph.in{background:var(--in-wash);color:var(--in)}
.thumb-ph .icon{width:26px;height:26px}
.row .body{flex:1;min-width:0}
.row .item{font-weight:700;font-size:16px;letter-spacing:-.01em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row .sub{color:var(--muted);font-size:13.5px;margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row .sub .who{color:var(--ink);font-weight:600}
.row .end{display:flex;flex-direction:column;align-items:flex-end;gap:5px;flex:none}
.pill{font-size:11.5px;font-weight:700;padding:3px 9px;border-radius:999px;letter-spacing:.02em;white-space:nowrap}
.pill.out{background:var(--brand-wash);color:var(--brand-ink)}
.pill.in{background:var(--in-wash);color:var(--in)}
.pill.done{background:#e6ebf1;color:var(--muted)}
.pill.overdue{background:var(--overdue-wash);color:var(--overdue)}
.due{font-size:12px;color:var(--muted);display:flex;align-items:center;gap:4px}
.due.overdue{color:var(--overdue);font-weight:600}
.due .icon{width:13px;height:13px}
.tag-owner{font-size:11px;color:var(--faint);font-weight:600}

/* ── Search bar (loans + library) ─────────────────────────────────────────── */
.searchbar{position:relative;margin-bottom:14px}
.searchbar .icon{position:absolute;left:14px;top:50%;transform:translateY(-50%);width:18px;height:18px;color:var(--faint);pointer-events:none}
.searchbar .input{padding-left:42px;height:44px;background:var(--card)}

/* ── Library availability + due-soon pills ────────────────────────────────── */
.pill.free{background:#e2f4ec;color:var(--ok)}
.pill.soon{background:var(--warn-wash);color:var(--warn-ink)}

/* ── Sheet helper copy ────────────────────────────────────────────────────── */
.sheet-sub{color:var(--muted);font-size:14.5px;margin:2px 0 14px}
.sheet-sub strong{color:var(--ink)}

/* ── Circle stats tiles ───────────────────────────────────────────────────── */
.stat-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-bottom:16px}
.stat{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:12px 6px;text-align:center;box-shadow:var(--shadow)}
.stat .n{font-size:22px;font-weight:800;letter-spacing:-.02em}
.stat .l{font-size:11px;font-weight:600;color:var(--muted);margin-top:2px;letter-spacing:.02em}
@media (max-width:379px){ .stat-grid{grid-template-columns:repeat(2,1fr)} }

/* ── Activity feed ────────────────────────────────────────────────────────── */
.feed{background:var(--card);border:1px solid var(--line);border-radius:var(--r);box-shadow:var(--shadow);padding:4px 0;margin-bottom:16px}
.feed-row{display:flex;align-items:center;gap:11px;padding:10px 14px;border-bottom:1px solid var(--line-soft)}
.feed-row:last-child{border-bottom:none}
.feed-ic{width:30px;height:30px;border-radius:9px;background:var(--card-2);color:var(--muted);display:flex;align-items:center;justify-content:center;flex:none}
.feed-ic .icon{width:16px;height:16px}
.feed-txt{flex:1;min-width:0;font-size:13.5px;line-height:1.35}
.feed-at{font-size:11.5px;color:var(--faint);flex:none}

/* ── Section headers ───────────────────────────────────────────────────────── */
.sec-head{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.07em;color:var(--faint);margin:22px 4px 10px}
.sec-head:first-child{margin-top:4px}

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty{text-align:center;padding:56px 24px;color:var(--muted)}
.empty .ec{width:66px;height:66px;border-radius:20px;background:var(--brand-wash);color:var(--brand-ink);display:flex;align-items:center;justify-content:center;margin:0 auto 18px}
.empty .ec .icon{width:32px;height:32px}
.empty h3{font-size:18px;color:var(--ink);letter-spacing:-.01em;margin-bottom:6px}
.empty p{font-size:14.5px;max-width:300px;margin:0 auto 20px}

/* ── FAB ───────────────────────────────────────────────────────────────────── */
.fab{
  position:fixed;right:20px;bottom:calc(84px + var(--safe-b));z-index:25;
  width:58px;height:58px;border-radius:19px;background:var(--brand);color:#fff;
  display:flex;align-items:center;justify-content:center;box-shadow:0 6px 20px rgba(214,58,18,.38);
  transition:transform .07s ease, background .15s ease;
}
.fab:active{transform:scale(.94)}
.fab .icon{width:28px;height:28px;stroke-width:2.3}
@media (min-width:768px){ .wide .fab{bottom:32px;right:32px} }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;background:var(--brand);color:#fff;font-weight:600;font-size:15px;padding:13px 20px;border-radius:13px;width:100%;transition:background .15s ease, transform .06s ease}
.btn:active{transform:translateY(1px)}
.btn:hover{background:var(--brand-ink)}
.btn.ghost{background:var(--card);color:var(--ink);border:1px solid var(--line)}
.btn.ghost:hover{background:var(--card-2)}
.btn.sm{width:auto;padding:9px 15px;font-size:14px;border-radius:11px}
.btn.danger{background:var(--danger)}
.btn.danger:hover{background:#8f1d13}
.btn:disabled{opacity:.55;pointer-events:none}
.btn .icon{width:19px;height:19px}
.linkbtn{color:var(--brand-ink);font-weight:600;font-size:14.5px;padding:6px}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.field{margin-bottom:15px}
.field label{display:block;font-size:13px;font-weight:600;color:var(--muted);margin-bottom:6px;letter-spacing:.01em}
.input, .select, textarea.input{
  width:100%;height:48px;background:var(--card);border:1px solid var(--line);border-radius:12px;
  padding:0 14px;font-size:16px;color:var(--ink);outline:none;transition:border .15s ease, box-shadow .15s ease;
}
textarea.input{height:auto;min-height:84px;padding:12px 14px;line-height:1.45;resize:vertical}
.select{appearance:none;-webkit-appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236f6559' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;padding-right:40px}
.input:focus,.select:focus,textarea.input:focus{border-color:var(--brand);box-shadow:0 0 0 3px rgba(214,58,18,.16)}
.row-2{display:flex;gap:11px}
.row-2 > *{flex:1}
.hint{font-size:12.5px;color:var(--faint);margin-top:6px}
.err{background:var(--overdue-wash);color:var(--overdue);font-size:13.5px;padding:10px 13px;border-radius:11px;margin-bottom:14px}

/* photo picker */
.photo-pick{display:flex;align-items:center;gap:13px}
.photo-pick .prev{width:66px;height:66px;border-radius:13px;object-fit:cover;background:var(--brand-wash);flex:none}
.photo-pick .prev-ph{width:66px;height:66px;border-radius:13px;background:var(--card-2);border:1px dashed var(--line);display:flex;align-items:center;justify-content:center;color:var(--faint);flex:none}

/* segmented direction toggle in add form */
.dir-toggle{display:flex;gap:10px;margin-bottom:16px}
.dir-toggle button{flex:1;display:flex;flex-direction:column;align-items:center;gap:7px;padding:15px 10px;border-radius:14px;border:1.5px solid var(--line);background:var(--card);color:var(--muted);font-weight:600;font-size:14px}
.dir-toggle button .icon{width:24px;height:24px}
.dir-toggle button.active[data-dir=out]{border-color:var(--out);background:var(--brand-wash);color:var(--brand-ink)}
.dir-toggle button.active[data-dir=in]{border-color:var(--in);background:var(--in-wash);color:var(--in)}

/* ── Sheet / modal ─────────────────────────────────────────────────────────── */
.scrim{position:fixed;inset:0;z-index:40;background:rgba(3,29,55,.45);backdrop-filter:blur(2px);display:flex;align-items:flex-end;justify-content:center;animation:fade .18s ease}
@media (min-width:768px){.scrim{align-items:center}}
.sheet{
  background:var(--paper);width:100%;max-width:560px;border-radius:22px 22px 0 0;
  max-height:92vh;max-height:92dvh;overflow-y:auto;overscroll-behavior:contain;box-shadow:var(--shadow-lg);animation:slideup .24s cubic-bezier(.2,.8,.2,1);
  padding:8px 20px calc(24px + var(--safe-b));
}
@media (min-width:768px){.sheet{border-radius:22px;max-height:88vh;max-height:88dvh;animation:pop .2s ease}}
.sheet .grab{width:38px;height:4px;border-radius:2px;background:var(--line);margin:8px auto 4px}
.sheet-head{display:flex;align-items:center;justify-content:space-between;padding:8px 0 16px}
.sheet-head h2{font-size:20px;font-weight:800;letter-spacing:-.02em}
.sheet-head .x{width:34px;height:34px;border-radius:10px;display:flex;align-items:center;justify-content:center;color:var(--muted);background:var(--card-2)}
@keyframes slideup{from{transform:translateY(100%)}to{transform:translateY(0)}}
@keyframes pop{from{transform:scale(.96);opacity:0}to{transform:scale(1);opacity:1}}
@keyframes fade{from{opacity:0}to{opacity:1}}

/* detail sheet bits */
.detail-photo{width:100%;max-height:240px;object-fit:cover;border-radius:16px;margin-bottom:16px;background:var(--brand-wash)}
.kv{display:flex;justify-content:space-between;gap:16px;padding:12px 2px;border-bottom:1px solid var(--line-soft);font-size:15px}
.kv:last-of-type{border-bottom:none}
.kv .k{color:var(--muted)}
.kv .v{font-weight:600;text-align:right}
.detail-actions{display:flex;flex-direction:column;gap:10px;margin-top:20px}
.detail-actions .two{display:flex;gap:10px}
.detail-actions .two > *{flex:1}
.notes-block{background:var(--card-2);border:1px solid var(--line-soft);border-radius:12px;padding:12px 14px;font-size:14.5px;color:var(--ink);margin-top:6px;white-space:pre-wrap}

/* ── Auth ──────────────────────────────────────────────────────────────────── */
/* `safe center` keeps the form centred when it fits, but falls back to
   flex-start when it doesn't. With plain `center`, overflowing flex content is
   clipped equally at both ends and the top (the logo) becomes unreachable —
   which the taller brand lockup made easy to hit on short windows. Browsers
   without `safe` keep the previous behaviour from the first declaration. */
.auth{max-width:400px;margin:0 auto;padding:calc(var(--safe-t) + 40px) 24px 40px;min-height:100%;display:flex;flex-direction:column;justify-content:center;justify-content:safe center}
.auth .logo{text-align:center;margin-bottom:8px}
.auth-logo{width:132px;height:auto;display:block;margin:0 auto}
.auth h1{text-align:center;font-size:27px;font-weight:800;letter-spacing:-.02em;margin-top:16px}
.auth .tag{text-align:center;color:var(--muted);font-size:15px;margin:6px 0 26px}
.auth .btn{margin-top:6px}
.auth .switch{text-align:center;margin-top:20px;color:var(--muted);font-size:14.5px}
.auth .switch button{color:var(--brand-ink);font-weight:700}
.social{display:flex;flex-direction:column;gap:10px}
.social button{display:flex;align-items:center;justify-content:center;gap:10px;height:48px;border-radius:13px;font-weight:600;font-size:15px;border:1px solid var(--line);background:var(--card)}
.social .apple{background:#000;color:#fff;border-color:#000}
/* Google: our own button, visually identical to the Apple one, with the real
   GIS button laid over it transparently to take the click. Styling the iframe's
   own wrapper instead produced a double outline, since GIS always draws its
   own border. */
.social .gbtn{
  position:relative;overflow:hidden;cursor:pointer;
  display:flex;align-items:center;justify-content:center;gap:10px;height:48px;
  border-radius:13px;border:1px solid var(--line);background:#fff;
  font-weight:600;font-size:15px;color:var(--ink);
  transition:background .15s ease;
}
.social .gbtn:hover{background:var(--card-2)}
.social .gbtn > .gis{position:absolute;inset:0;opacity:0;z-index:2}
/* Scaled up so the 40px-tall GIS button covers the full 48px hit area. It is
   invisible, so the scaling costs nothing visually. */
.social .gbtn > .gis > div{transform:scale(1.6);transform-origin:center}
/* The social row leads the auth form, so the "or" trails its buttons and the
   bottom margin is what separates it from the first field. */
.divider{display:flex;align-items:center;gap:12px;color:var(--faint);font-size:12.5px;margin:10px 0 14px}
.divider::before,.divider::after{content:"";flex:1;height:1px;background:var(--line)}

/* ── Circle / members ──────────────────────────────────────────────────────── */
.member{display:flex;align-items:center;gap:13px;padding:12px 14px;background:var(--card);border:1px solid var(--line);border-radius:14px}
.avatar{width:42px;height:42px;border-radius:50%;background:var(--brand);color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:15px;flex:none}
.member .nm{font-weight:600}
.member .badge{margin-left:auto;font-size:11.5px;font-weight:700;color:var(--brand-ink);background:var(--brand-wash);padding:3px 9px;border-radius:999px}
.card-box{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:18px;box-shadow:var(--shadow);margin-bottom:16px}
.card-box h3{font-size:16px;letter-spacing:-.01em;margin-bottom:4px}
.card-box p{color:var(--muted);font-size:14px;margin-bottom:14px}
.invite-link{display:flex;gap:8px;margin-top:12px}
.invite-link input{flex:1;font-size:13px;background:var(--card-2)}

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast{
  position:fixed;left:50%;transform:translateX(-50%);bottom:calc(96px + var(--safe-b));z-index:60;
  background:var(--ink);color:var(--paper);padding:12px 18px;border-radius:13px;font-size:14px;font-weight:500;
  box-shadow:var(--shadow-lg);display:flex;align-items:center;gap:14px;max-width:88vw;animation:toastin .2s ease;
}
.toast-action{color:#ff9e7d;font-weight:700;font-size:14px}
@keyframes toastin{from{opacity:0;transform:translate(-50%,10px)}to{opacity:1;transform:translate(-50%,0)}}
@media (min-width:768px){.wide .toast{bottom:28px}}

.spin{width:22px;height:22px;border:2.5px solid var(--brand-wash);border-top-color:var(--brand);border-radius:50%;animation:sp .7s linear infinite;margin:40px auto}
@keyframes sp{to{transform:rotate(360deg)}}
.center-load{display:flex;justify-content:center;padding:40px}

/* ── Native feel (web half, .Process/NATIVE-FEEL.md Tier 1) ───────────────── */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
button,a,[role=button],.row,.tabbar button,.seg button,.dir-toggle button,.fab,.iconbtn,.linkbtn{
  -webkit-user-select:none;user-select:none;-webkit-touch-callout:none;touch-action:manipulation;
}
input,textarea,select,[contenteditable],.notes-block,.kv .v,.feed-txt{
  -webkit-user-select:text;user-select:text;-webkit-touch-callout:default;
}
img{-webkit-user-drag:none}
/* Press states: buttons and tabs squish; list rows press after 100ms so a
   finger landing to scroll doesn't flash them (release stays instant). */
.tabbar button,.seg button,.dir-toggle button,.linkbtn,.sheet-head .x,.social button,.social .gbtn,.wide .sidebar button.nav{transition:transform .08s ease}
.tabbar button:active,.seg button:active,.dir-toggle button:active,.linkbtn:active,.sheet-head .x:active,.social button:active,.social .gbtn:active,.wide .sidebar button.nav:active{transform:scale(.97)}
.row:active{transition-delay:.1s}
@media (prefers-reduced-motion:reduce){
  .tabbar button:active,.seg button:active,.dir-toggle button:active,.linkbtn:active,.sheet-head .x:active,
  .social button:active,.social .gbtn:active,.wide .sidebar button.nav:active,.row:active,.fab:active{transform:none}
}
