/* MilkAdda farmer self-service — mobile first, no build step. */
:root {
    --green: #1b6b22;
    --green-dark: #145218;
    --green-soft: #eaf6e4;
    --amber: #b7791f;
    --amber-soft: #fdf3dc;
    --red: #b42318;
    --red-soft: #fde8e6;
    --blue: #0b4fa8;
    --blue-soft: #e8f1fb;
    --ink: #1a1d21;
    --ink-2: #4b5563;
    --ink-3: #8a94a3;
    --line: #e3e7ec;
    --bg: #f4f6f8;
    --card: #ffffff;
    --radius: 14px;
    --tap: 52px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", "Nirmala UI", Mangal, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.45;
    color: var(--ink);
    background: var(--bg);
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.45rem; margin: 0 0 6px; }
p { margin: 0 0 12px; }
.lead { color: var(--ink-2); }
.center { text-align: center; }
[hidden] { display: none !important; }

/* Header */
.top {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--green); color: #fff;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: #fff; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 1.2rem; letter-spacing: .2px; }
.brand-sub { font-size: .85rem; opacity: .85; }
.lang-btn {
    min-height: 40px; min-width: 64px; padding: 0 12px;
    border: 1.5px solid rgba(255,255,255,.7); border-radius: 999px;
    background: transparent; color: #fff; font: inherit; font-weight: 600; font-size: .95rem;
}
.lang-btn:active { background: rgba(255,255,255,.15); }

/* Screens */
#main { max-width: 560px; margin: 0 auto; padding: 18px 16px 24px; }
.screen { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Forms */
.form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
label { font-weight: 600; font-size: .95rem; color: var(--ink-2); }
input[type="text"], input[type="tel"], input[type="password"], input[type="month"], input[type="date"], select {
    width: 100%; min-height: var(--tap);
    padding: 10px 14px; font: inherit; font-size: 1.1rem;
    border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus { outline: 3px solid rgba(27,107,58,.3); border-color: var(--green); }
.otp-input { letter-spacing: .4em; text-align: center; font-size: 1.6rem !important; }
.phone-wrap { display: flex; align-items: stretch; }
.phone-prefix {
    display: flex; align-items: center; padding: 0 12px; font-weight: 600; color: var(--ink-2);
    border: 1.5px solid var(--line); border-right: 0; border-radius: 12px 0 0 12px; background: #f1f3f5;
}
.phone-wrap input { border-radius: 0 12px 12px 0; }

.btn {
    min-height: var(--tap); padding: 10px 18px; width: 100%;
    font: inherit; font-size: 1.08rem; font-weight: 700;
    border-radius: 12px; border: 1.5px solid transparent; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.secondary { background: var(--green-soft); color: var(--green-dark); border-color: #cfe5d6; }
.btn.ghost { background: transparent; color: var(--green-dark); border-color: var(--line); }
.btn.danger { background: #fff; color: var(--red); border-color: #f1c4c0; margin-top: 8px; }
.btn.sm { min-height: 42px; width: auto; padding: 6px 14px; font-size: .95rem; }
.btn[disabled] { opacity: .55; cursor: default; }
.link-btn {
    background: none; border: 0; padding: 8px 0; min-height: 40px;
    font: inherit; color: var(--green-dark); font-weight: 600; cursor: pointer;
}
.back { margin: -8px 0 6px; }

.error {
    color: var(--red); background: var(--red-soft);
    padding: 10px 12px; border-radius: 10px; font-size: .97rem; margin: 0;
}
.error.banner { margin: 0 0 12px; }
.ok { color: var(--green-dark); background: var(--green-soft); padding: 10px 12px; border-radius: 10px; margin: 0; }
.debug {
    background: var(--amber-soft); color: #6b4a0b; border: 1px dashed var(--amber);
    padding: 8px 12px; border-radius: 10px; font-size: .95rem;
}
.hint { color: var(--ink-3); font-size: .9rem; margin: 8px 0 0; }
.hint.warn { color: #7a5209; background: var(--amber-soft); padding: 8px 10px; border-radius: 8px; font-weight: 600; }

/* App */
.who { margin: -4px 0 14px; }
.who-name { font-size: 1.3rem; font-weight: 700; }
.who-sub { color: var(--ink-2); font-size: .95rem; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 12px 14px; margin-bottom: 10px; min-width: 0;
}
.cards .card { margin-bottom: 0; }
.card.balance { grid-column: 1 / -1; background: var(--green); color: #fff; border-color: var(--green); }
.card.balance .card-title { color: rgba(255,255,255,.85); }
.card-title { font-size: .9rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.card-big { font-size: 2rem; font-weight: 800; letter-spacing: -.5px; line-height: 1.15; }
.card-foot { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: .85rem; opacity: .9; }
.card.period .card-amt { font-size: 1.35rem; font-weight: 800; }
.card.period .card-row { display: flex; justify-content: space-between; font-size: .9rem; color: var(--ink-2); }
.card.period .card-row b { color: var(--ink); font-weight: 600; }
.card.period.wide { grid-column: 1 / -1; }

.chart { width: 100%; margin-top: 6px; }
.chart svg { width: 100%; height: auto; max-height: 220px; display: block; }
.chart .bar { fill: var(--green); }
.chart .bar.empty { fill: #d9e4dc; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .lbl { font-size: 10px; fill: var(--ink-3); font-family: var(--font); }
.chart-legend { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-2); margin-top: 4px; }
.sw { width: 12px; height: 12px; border-radius: 3px; background: var(--green); display: inline-block; }

/* Filters & lists */
.filter-row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.filter-row label { display: block; margin-bottom: 4px; }
.filter-row > div { flex: 1; min-width: 0; }
.filter-row .btn { width: auto; flex: 1; }
.total-line { color: var(--ink-2); font-size: .92rem; margin: 2px 0 8px; }
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 10px 14px;
}
.row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.row-date { font-weight: 700; }
.row-amt { font-weight: 800; font-size: 1.15rem; white-space: nowrap; }
.row-amt.neg { color: var(--red); }
.row-mid { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-2); font-size: .93rem; margin-top: 2px; }
.row-mid b { color: var(--ink); font-weight: 600; }
.row-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.badge {
    display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
    background: #eef0f3; color: var(--ink-2);
}
.badge.ok { background: var(--green-soft); color: var(--green-dark); }
.badge.warn { background: var(--amber-soft); color: #7a5209; }
.badge.bad { background: var(--red-soft); color: var(--red); }
.badge.info { background: var(--blue-soft); color: var(--blue); }
.row-note { color: var(--ink-3); font-size: .85rem; margin-left: 6px; }
.empty { text-align: center; color: var(--ink-3); padding: 24px 10px; }

.st-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.st-summary .card { margin: 0; padding: 10px 12px; }
.st-summary .v { font-size: 1.15rem; font-weight: 800; }
.st-summary .v.neg { color: var(--red); }
.row.entry .row-mid { justify-content: space-between; }
.cr { color: var(--green-dark); font-weight: 700; }
.dr { color: var(--red); font-weight: 700; }

.kv { display: grid; grid-template-columns: 1fr; gap: 6px; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 6px 0; }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--ink-2); font-size: .93rem; margin: 0; }
.kv dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }

.seg { display: flex; gap: 8px; }
.seg-btn {
    flex: 1; min-height: 48px; font: inherit; font-size: 1.05rem; font-weight: 600;
    border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink-2);
}
.seg-btn.on { background: var(--green); color: #fff; border-color: var(--green); }

/* Bottom tab bar */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 62px; border: 0; background: none; font: inherit; font-size: .78rem; color: var(--ink-2);
    -webkit-tap-highlight-color: transparent;
}
.tab-btn .ico { font-size: 1.3rem; line-height: 1; }
.tab-btn.on { color: var(--green-dark); font-weight: 700; }
.tab-btn.on .ico { transform: translateY(-1px); }

/* Busy / toast */
.busy {
    position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.45);
}
.spinner {
    width: 44px; height: 44px; border-radius: 50%;
    border: 4px solid var(--green-soft); border-top-color: var(--green);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
    position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    z-index: 30; max-width: 90vw; padding: 10px 16px; border-radius: 999px;
    background: var(--ink); color: #fff; font-size: .95rem; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

@media (min-width: 640px) {
    .cards { grid-template-columns: 1fr 1fr 1fr; }
    .card.balance { grid-column: 1 / -1; }
    .tabbar { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
