@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Work+Sans:wght@400;500;600;700&display=swap');

:root{
  --ink:#17130F;
  --ink-soft:#3A342B;
  --forest:#22422B;
  --forest-dim:#2F5233;
  --forest-tint:#E7EEE4;
  --soil:#8B5A2B;
  --soil-light:#C98A4B;
  --soil-tint:#F1E4D3;
  --paper:#F7F5EF;
  --card:#FFFFFF;
  --line:#E5DFD1;
  --good:#3E7C4A;
  --alert:#A5432B;
  --alert-tint:#F5E3DB;
  --muted:#726B5C;
  --shadow: 0 1px 2px rgba(23,19,15,0.05), 0 6px 16px rgba(23,19,15,0.06);
  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 22px;
  --font-display: 'Fraunces', serif;
  --font-ui: 'Work Sans', sans-serif;
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  background:var(--paper);
  color:var(--ink);
  font-family:var(--font-ui);
  -webkit-font-smoothing:antialiased;
  overscroll-behavior-y:none;
}
button{font-family:inherit;}
a{color:inherit;}
::selection{background:var(--forest-tint);}
:focus-visible{outline:2px solid var(--forest); outline-offset:2px;}

.app-shell{
  max-width:480px;
  margin:0 auto;
  min-height:100vh;
  background:var(--paper);
  display:flex;
  flex-direction:column;
  position:relative;
  box-shadow: 0 0 60px rgba(0,0,0,0.06);
}

/* ---------- Top bar ---------- */
.topbar{
  position:sticky; top:0; z-index:20;
  background:var(--paper);
  padding:18px 20px 10px;
  display:flex; align-items:center; justify-content:space-between;
  border-bottom:1px solid transparent;
}
.topbar.scrolled{border-bottom-color:var(--line);}
.brandmark{
  display:flex; align-items:center; gap:10px;
}
.brandmark .mark{
  width:34px; height:34px; border-radius:9px;
  background:var(--forest);
  display:flex; align-items:center; justify-content:center;
  color:var(--paper); font-family:var(--font-display); font-weight:700; font-size:15px;
}
.brandmark .word{font-family:var(--font-display); font-weight:600; font-size:19px; letter-spacing:0.2px;}
.topbar .avatar{
  width:36px;height:36px;border-radius:50%;
  background:var(--soil-tint); color:var(--soil);
  display:flex;align-items:center;justify-content:center;
  font-weight:600; font-size:14px; font-family:var(--font-ui);
  border:1px solid var(--line);
}

/* ---------- Screen container ---------- */
.screen{
  flex:1;
  padding:6px 20px 100px;
  animation:fadeIn .22s ease;
}
@keyframes fadeIn{from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;}}
@media (prefers-reduced-motion: reduce){ .screen{animation:none;} }

h1.page-title{
  font-family:var(--font-display);
  font-weight:600;
  font-size:26px;
  margin:10px 0 2px;
  color:var(--ink);
}
p.page-sub{
  margin:0 0 18px;
  color:var(--muted);
  font-size:14.5px;
}

/* ---------- Cards ---------- */
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius-m);
  padding:16px;
  margin-bottom:14px;
}
.card-tight{padding:12px 14px;}

/* Sector summary grid on home */
.sector-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
  margin-bottom:14px;
}
.sector-tile{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius-m);
  padding:14px;
}
.sector-tile .num{font-family:var(--font-display); font-size:28px; font-weight:600; line-height:1;}
.sector-tile .label{color:var(--muted); font-size:12.5px; margin-top:4px;}

/* Income hero */
.income-hero{
  background:var(--forest);
  color:var(--paper);
  border-radius:var(--radius-l);
  padding:20px;
  margin-bottom:16px;
  position:relative;
  overflow:hidden;
}
.income-hero::after{
  content:"";
  position:absolute; right:-40px; top:-40px;
  width:140px; height:140px; border-radius:50%;
  background:rgba(247,245,239,0.06);
}
.income-hero .eyebrow{font-size:13px; opacity:0.75; margin-bottom:2px;}
.income-hero .amount{font-family:var(--font-display); font-size:34px; font-weight:600; margin:2px 0 4px;}
.income-hero .detail{font-size:13px; opacity:0.8;}
.quick-actions{display:flex; gap:8px; margin-top:16px; flex-wrap:wrap;}
.qa-btn{
  background:rgba(247,245,239,0.14);
  color:var(--paper);
  border:1px solid rgba(247,245,239,0.28);
  padding:8px 12px;
  border-radius:999px;
  font-size:13px;
  font-weight:500;
  cursor:pointer;
}
.qa-btn:hover{background:rgba(247,245,239,0.22);}

/* AI tip banner */
.ai-tip{
  display:flex; gap:10px; align-items:flex-start;
  background:var(--soil-tint);
  border:1px solid var(--soil-light);
  border-radius:var(--radius-m);
  padding:13px 14px;
  margin-bottom:16px;
  cursor:pointer;
}
.ai-tip .dot{
  width:22px;height:22px;border-radius:50%;
  background:var(--soil); color:var(--paper);
  display:flex;align-items:center;justify-content:center;
  font-size:12px; font-weight:700; flex:none;
}
.ai-tip .txt{font-size:13.5px; line-height:1.4;}
.ai-tip .txt b{color:var(--soil);}

/* ---------- Sector chooser (Farm tab) ---------- */
.sector-choice{
  display:grid; grid-template-columns:1fr 1fr; gap:10px;
}
.sector-choice button{
  text-align:left;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius-m);
  padding:16px 14px;
  cursor:pointer;
}
.sector-choice button .tag{
  display:inline-block; font-size:11px; font-weight:700; letter-spacing:.02em;
  background:var(--forest-tint); color:var(--forest-dim);
  padding:3px 8px; border-radius:6px; margin-bottom:10px;
}
.sector-choice button .title{font-family:var(--font-display); font-size:17px; font-weight:600; margin-bottom:3px;}
.sector-choice button .sub{font-size:12px; color:var(--muted);}

/* ---------- Lists / rows ---------- */
.row-list{display:flex; flex-direction:column; gap:10px;}
.item-row{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  background:var(--card); border:1px solid var(--line);
  border-radius:var(--radius-m); padding:13px 14px;
}
.item-row .left{display:flex; align-items:center; gap:11px; min-width:0;}
.item-row .chip{
  width:38px;height:38px;border-radius:11px;
  background:var(--forest-tint); color:var(--forest-dim);
  display:flex;align-items:center;justify-content:center;
  font-weight:700; font-size:11px; flex:none;
}
.item-row .name{font-weight:600; font-size:14.5px;}
.item-row .meta{font-size:12.5px; color:var(--muted); margin-top:1px;}
.item-row .right{text-align:right; flex:none;}
.item-row .metric{font-weight:600; font-size:14px;}
.item-row .metric-sub{font-size:11.5px; color:var(--muted);}

.battery-pill{
  font-size:11px; font-weight:600; padding:2px 7px; border-radius:999px;
}
.battery-good{background:var(--forest-tint); color:var(--forest-dim);}
.battery-low{background:var(--alert-tint); color:var(--alert);}

/* ---------- Map mock ---------- */
.map-mock{
  height:180px;
  border-radius:var(--radius-m);
  background:
    linear-gradient(135deg, #D8E3D2 0%, #C7D8BF 100%);
  position:relative;
  overflow:hidden;
  margin-bottom:14px;
  border:1px solid var(--line);
}
.map-mock .field{position:absolute; border-radius:10px; background:rgba(34,66,43,0.10); border:1px dashed rgba(34,66,43,0.35);}
.map-mock .pin{
  position:absolute;
  width:16px;height:16px;border-radius:50%;
  background:var(--forest); border:3px solid var(--paper);
  box-shadow:0 2px 5px rgba(0,0,0,0.25);
}
.map-mock .pin.low{background:var(--alert);}
.map-mock .pin-label{
  position:absolute; transform:translate(-50%,-140%);
  font-size:10.5px; font-weight:600; background:var(--ink); color:var(--paper);
  padding:2px 6px; border-radius:6px; white-space:nowrap;
}

/* ---------- Forms ---------- */
.field-group{margin-bottom:14px;}
.field-group label{
  display:block; font-size:12.5px; font-weight:600; color:var(--ink-soft); margin-bottom:6px;
}
.field-group input, .field-group select, .field-group textarea{
  width:100%; padding:11px 12px; border-radius:var(--radius-s);
  border:1px solid var(--line); background:var(--card);
  font-family:var(--font-ui); font-size:14.5px; color:var(--ink);
}
.field-group textarea{resize:vertical; min-height:70px;}
.two-col{display:grid; grid-template-columns:1fr 1fr; gap:12px;}

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:13px 18px; border-radius:999px; border:none;
  font-weight:600; font-size:14.5px; cursor:pointer; width:100%;
  font-family:var(--font-ui);
}
.btn-primary{background:var(--forest); color:var(--paper);}
.btn-primary:hover{background:var(--forest-dim);}
.btn-outline{background:transparent; color:var(--forest); border:1.5px solid var(--forest);}
.btn-soil{background:var(--soil); color:var(--paper);}
.btn-sm{padding:8px 14px; font-size:13px; width:auto;}
.btn:disabled{opacity:0.5; cursor:not-allowed;}

.toast{
  position:fixed; left:50%; bottom:96px; transform:translateX(-50%);
  background:var(--ink); color:var(--paper);
  padding:10px 16px; border-radius:999px; font-size:13.5px;
  box-shadow:var(--shadow); z-index:60; opacity:0; pointer-events:none;
  transition:opacity .2s ease, bottom .2s ease;
}
.toast.show{opacity:1; bottom:106px;}

/* ---------- Tabs (filter chips) ---------- */
.chip-row{display:flex; gap:8px; overflow-x:auto; padding-bottom:2px; margin-bottom:14px;}
.chip-row::-webkit-scrollbar{display:none;}
.chip{
  flex:none; padding:8px 14px; border-radius:999px; border:1px solid var(--line);
  background:var(--card); font-size:13px; font-weight:500; color:var(--ink-soft); cursor:pointer; white-space:nowrap;
}
.chip.active{background:var(--forest); color:var(--paper); border-color:var(--forest);}

/* ---------- Marketplace listing card ---------- */
.listing-card{
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius-m);
  overflow:hidden; margin-bottom:12px;
}
.listing-thumb{
  height:96px;
  background:linear-gradient(135deg, var(--forest-tint), var(--soil-tint));
  display:flex; align-items:center; justify-content:center;
  font-family:var(--font-display); color:var(--forest-dim); font-size:13px; font-weight:600;
}
.listing-body{padding:12px 14px;}
.listing-body .title{font-weight:600; font-size:15px; margin-bottom:2px;}
.listing-body .price{color:var(--forest-dim); font-weight:700; font-size:14px; margin-bottom:4px;}
.listing-body .meta{font-size:12px; color:var(--muted); display:flex; justify-content:space-between;}
.status-pill{font-size:10.5px; font-weight:700; padding:2px 8px; border-radius:999px;}
.status-active{background:var(--forest-tint); color:var(--forest-dim);}
.status-pending{background:var(--soil-tint); color:var(--soil);}

/* ---------- Bar chart (pure CSS/SVG) ---------- */
.bars{display:flex; align-items:flex-end; gap:6px; height:64px; margin:6px 0 2px;}
.bars .bar{flex:1; background:var(--forest-tint); border-radius:5px 5px 2px 2px; position:relative;}
.bars .bar.today{background:var(--forest);}
.bars-labels{display:flex; gap:6px; font-size:10.5px; color:var(--muted);}
.bars-labels span{flex:1; text-align:center;}

/* ---------- Vet / KB ---------- */
.vet-card{
  display:flex; gap:12px; align-items:center;
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius-m);
  padding:13px 14px; margin-bottom:10px;
}
.vet-avatar{
  width:44px; height:44px; border-radius:50%;
  background:var(--forest-tint); color:var(--forest-dim);
  display:flex; align-items:center; justify-content:center;
  font-weight:700; font-size:13px; flex:none;
}
.vet-info{flex:1; min-width:0;}
.vet-info .name{font-weight:600; font-size:14.5px;}
.vet-info .spec{font-size:12.5px; color:var(--muted);}
.vet-info .clinic{font-size:11.5px; color:var(--muted);}

.kb-article{
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius-m);
  padding:14px; margin-bottom:10px; cursor:pointer;
}
.kb-article .cat{font-size:11px; font-weight:700; color:var(--soil); margin-bottom:5px;}
.kb-article .title{font-family:var(--font-display); font-weight:600; font-size:15.5px; line-height:1.35; margin-bottom:4px;}
.kb-article .snippet{font-size:12.5px; color:var(--muted); line-height:1.4;}

/* ---------- AI chat ---------- */
.chat-scroll{display:flex; flex-direction:column; gap:10px; padding-bottom:12px;}
.msg{max-width:82%; padding:11px 13px; border-radius:16px; font-size:14px; line-height:1.45;}
.msg.user{align-self:flex-end; background:var(--forest); color:var(--paper); border-bottom-right-radius:4px;}
.msg.ai{align-self:flex-start; background:var(--card); border:1px solid var(--line); border-bottom-left-radius:4px;}
.msg.ai .ai-label{font-size:10.5px; font-weight:700; color:var(--soil); margin-bottom:4px; display:block;}
.chat-input-bar{
  position:fixed; bottom:64px; left:0; right:0; z-index:25;
  display:flex; justify-content:center;
}
.chat-input-inner{
  max-width:480px; width:100%; background:var(--paper);
  padding:10px 20px 14px; display:flex; gap:8px;
  border-top:1px solid var(--line);
}
.chat-input-inner input{
  flex:1; padding:12px 14px; border-radius:999px; border:1px solid var(--line);
  background:var(--card); font-size:14px; font-family:var(--font-ui);
}
.chat-send{
  width:42px; height:42px; border-radius:50%; border:none;
  background:var(--forest); color:var(--paper); font-size:16px; cursor:pointer; flex:none;
}

/* ---------- Bottom nav ---------- */
.tabbar{
  position:fixed; bottom:0; left:0; right:0; z-index:30;
  display:flex; justify-content:center;
}
.tabbar-inner{
  max-width:480px; width:100%;
  background:var(--card);
  border-top:1px solid var(--line);
  display:flex;
  padding:6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab-btn{
  flex:1; background:none; border:none; cursor:pointer;
  display:flex; flex-direction:column; align-items:center; gap:3px;
  padding:8px 2px; color:var(--muted); font-family:var(--font-ui);
  font-size:10.5px; font-weight:600;
}
.tab-btn.active{color:var(--forest);}
.tab-icon{width:22px; height:22px; display:block;}

/* ---------- Modal / sheet ---------- */
.sheet-backdrop{
  position:fixed; inset:0; background:rgba(23,19,15,0.42);
  z-index:50; display:flex; align-items:flex-end; justify-content:center;
}
.sheet{
  max-width:480px; width:100%; background:var(--paper);
  border-radius:22px 22px 0 0; padding:20px 20px calc(24px + env(safe-area-inset-bottom));
  max-height:88vh; overflow-y:auto;
  animation:slideUp .22s ease;
}
@keyframes slideUp{from{transform:translateY(24px); opacity:0.6;} to{transform:none; opacity:1;}}
.sheet-handle{width:36px; height:4px; background:var(--line); border-radius:99px; margin:0 auto 16px;}
.sheet-title{font-family:var(--font-display); font-size:19px; font-weight:600; margin-bottom:4px;}
.sheet-close{
  position:absolute; top:16px; right:16px; background:var(--card); border:1px solid var(--line);
  width:30px; height:30px; border-radius:50%; cursor:pointer; font-size:14px;
}

/* ---------- Install banner ---------- */
.install-banner{
  display:flex; align-items:center; gap:10px;
  background:var(--ink); color:var(--paper);
  border-radius:var(--radius-m); padding:12px 14px; margin-bottom:16px;
}
.install-banner .txt{flex:1; font-size:12.5px; line-height:1.4;}
.install-banner button{
  background:var(--paper); color:var(--ink); border:none; border-radius:999px;
  padding:8px 12px; font-weight:700; font-size:12.5px; cursor:pointer; flex:none;
}

.empty-state{
  text-align:center; padding:40px 20px; color:var(--muted);
}
.empty-state .glyph{font-size:30px; margin-bottom:8px;}
.empty-state .title{font-family:var(--font-display); font-size:16px; color:var(--ink); margin-bottom:4px; font-weight:600;}
.empty-state .sub{font-size:13px;}

.section-head{display:flex; align-items:baseline; justify-content:space-between; margin-bottom:10px;}
.section-head h2{font-family:var(--font-display); font-size:18px; font-weight:600; margin:0;}
.section-head .link{font-size:12.5px; color:var(--forest-dim); font-weight:600; cursor:pointer;}

@media (min-width: 540px){
  body{background:linear-gradient(180deg, var(--forest-tint), var(--paper) 240px);}
}
