/* Keshav Fresh CRM v2 - green theme, responsive, light + dark */
:root {
  --green: #27ae60; --green-d: #229954; --green-l: #eafaf1;
  --bg: #f4f7f6; --card: #ffffff; --ink: #1f2d3d; --mu: #6b7c8f; --bd: #e3e9ee;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.14);
  --blue: #2980b9; --orange: #e67e22; --red: #e74c3c; --purple: #8e44ad; --warn: #f39c12;
  --radius: 14px; --sb-w: 250px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181d; --card: #1b232b; --ink: #e6edf3; --mu: #93a4b3; --bd: #2b3742; --green-l: #16302259;
    --shadow: 0 1px 3px rgba(0,0,0,.4); --shadow-lg: 0 12px 34px rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"] {
  --bg: #12181d; --card: #1b232b; --ink: #e6edf3; --mu: #93a4b3; --bd: #2b3742; --green-l: #16302259;
  --shadow: 0 1px 3px rgba(0,0,0,.4); --shadow-lg: 0 12px 34px rgba(0,0,0,.55);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.5; font-size: 15px; -webkit-tap-highlight-color: transparent; }
body.modal-open, body.nav-open { overflow: hidden; }
h1,h2,h3,h4 { line-height: 1.25; }
h3 { font-size: 1.05rem; margin-bottom: 12px; }
a { color: var(--green-d); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--mu); }
.small { font-size: .8rem; color: var(--mu); }
.hint { font-size: .8rem; color: var(--mu); }
.center { text-align: center; }
.mb { margin-bottom: 14px; } .mb0 { margin-bottom: 0; } .mt { margin-top: 14px; }
.pos { color: var(--green-d); } .neg, .red { color: var(--red); }
.link { color: var(--green-d); cursor: pointer; } .link:hover { text-decoration: underline; }

/* boot / spinner */
#boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 60; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--bd); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== auth ===== */
#auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 28px; width: 100%; max-width: 420px; }
.auth-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.auth-logo { width: 52px; height: 52px; border-radius: 12px; background: linear-gradient(135deg, var(--green), var(--green-d)); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; }
.auth-card h2 { margin-bottom: 4px; }
.lang-switch { display: flex; gap: 4px; background: var(--bg); border-radius: 9px; padding: 3px; }
.lang-switch button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--mu); font-size: .85rem; font-family: inherit; }
.lang-switch button.active { background: var(--card); color: var(--green-d); font-weight: 700; box-shadow: var(--shadow); }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.check input { width: auto; }

/* ===== app shell ===== */
#app { min-height: 100vh; }
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sb-w); background: linear-gradient(170deg, var(--green), var(--green-d)); color: #fff; display: flex; flex-direction: column; z-index: 40; transition: transform .25s ease; }
.brand { padding: 20px 18px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand .logo { width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.brand .bn { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand .bs { font-size: .72rem; opacity: .85; }
.menu { flex: 1; overflow-y: auto; padding: 10px 0; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: transparent; color: rgba(255,255,255,.9); padding: 12px 18px; font-size: .95rem; cursor: pointer; text-align: left; font-family: inherit; border-left: 3px solid transparent; }
.menu-item .ic { font-size: 1.15rem; width: 22px; text-align: center; }
.menu-item:hover { background: rgba(255,255,255,.1); }
.menu-item.active { background: rgba(255,255,255,.18); border-left-color: #fff; font-weight: 600; }
.user-box { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.15); }
.u-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-role { font-size: .75rem; opacity: .8; margin-bottom: 8px; }

.main { margin-left: var(--sb-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: var(--card); border-bottom: 1px solid var(--bd); padding: 12px 20px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.topbar h1 { font-size: 1.15rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; background: transparent; border: 0; font-size: 1.5rem; cursor: pointer; color: var(--ink); line-height: 1; }
#range { max-width: 170px; }
.icon-btn { background: transparent; border: 1px solid var(--bd); border-radius: 9px; width: 38px; height: 38px; cursor: pointer; font-size: 1.05rem; color: var(--ink); flex-shrink: 0; }
.icon-btn.spin { animation: spin .8s linear infinite; }
.content { padding: 18px 20px 60px; flex: 1; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; }
body.nav-open .scrim { display: block; }
#offline { background: var(--warn); color: #fff; text-align: center; padding: 7px; font-size: .85rem; }

.section { display: none; } .section.active { display: block; }

/* ===== cards & grids ===== */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; border: 1px solid var(--bd); }
.card.flat { box-shadow: none; padding: 0; border: 0; background: transparent; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.row-between h3 { margin-bottom: 0; }

/* stats / KPI */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stats.mb0 { margin-bottom: 0; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border-left: 4px solid var(--green); position: relative; border: 1px solid var(--bd); border-left: 4px solid var(--green); }
.stat-card.info { border-left-color: var(--blue); } .stat-card.warn { border-left-color: var(--warn); } .stat-card.red { border-left-color: var(--red); }
.stat-card h4 { font-size: .82rem; color: var(--mu); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.stat-card .number { font-size: 1.7rem; font-weight: 800; margin: 5px 0 2px; letter-spacing: -.5px; }
.stat-card .number small { font-size: 1rem; color: var(--mu); font-weight: 600; }
.stat-card .sub { font-size: .78rem; color: var(--mu); }
.stat-card.click { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.stat-card.click:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .go { color: var(--green); font-weight: 700; font-size: 1.2rem; opacity: .5; }
.stat-card.click:hover .go { opacity: 1; }
.delta.up { color: var(--green-d); font-weight: 700; } .delta.down { color: var(--red); font-weight: 700; }

/* charts */
.chart-box { position: relative; height: 300px; }
.chart-box.sm { height: 240px; } .chart-box.xs { height: 150px; }

/* ===== tables ===== */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--bd); }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .4px; color: var(--mu); font-weight: 700; white-space: nowrap; }
th.r, td.r { text-align: right; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--green-l); }
tr.empty td { text-align: center; color: var(--mu); padding: 26px; }
table.wide { min-width: 640px; }
td b { font-weight: 700; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .74rem; font-weight: 700; background: var(--green-l); color: var(--green-d); white-space: nowrap; }
.badge.b-b { background: rgba(41,128,185,.14); color: var(--blue); }
.badge.b-o { background: rgba(230,126,34,.14); color: var(--orange); }
.badge.b-r { background: rgba(231,76,60,.14); color: var(--red); }
.badge.b-m { background: rgba(127,140,141,.16); color: var(--mu); }

/* buttons */
.btn { background: var(--green); color: #fff; border: 0; border-radius: 9px; padding: 10px 16px; font-size: .9rem; font-weight: 600; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 6px; justify-content: center; transition: background .15s, opacity .15s; }
.btn:hover { background: var(--green-d); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.loading { color: transparent; position: relative; }
.btn.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-o { background: transparent; border: 1px solid var(--green); color: var(--green-d); }
.btn-o:hover { background: var(--green-l); }
.btn-o.danger { border-color: var(--red); color: var(--red); } .btn-o.danger:hover { background: rgba(231,76,60,.1); }
.btn-red { background: var(--red); } .btn-red:hover { background: #c0392b; }
.btn-ghost { background: rgba(255,255,255,.18); color: #fff; border: 0; }
.btn-ghost:hover { background: rgba(255,255,255,.28); }
.btn-sm { padding: 6px 11px; font-size: .8rem; border-radius: 8px; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row.center { justify-content: center; }
.btn-x { background: transparent; border: 0; color: var(--mu); cursor: pointer; font-size: 1rem; padding: 4px 7px; border-radius: 6px; line-height: 1; }
.btn-x:hover { background: rgba(231,76,60,.12); color: var(--red); }

/* forms */
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--bd); border-radius: 9px; font-size: .92rem; font-family: inherit; background: var(--card); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-l); }
select { cursor: pointer; }
.ta { resize: vertical; font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: .82rem; }
.f { display: block; margin-bottom: 4px; font-size: .82rem; color: var(--mu); font-weight: 600; }
.f input, .f select, .f textarea { margin-top: 5px; }
.f .plain, .plain { margin-top: 6px; padding: 9px 0; font-weight: 700; color: var(--ink); font-size: .95rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.tight { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.span2 { grid-column: span 2; } .span-all { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 160px; } .toolbar select { width: auto; min-width: 130px; } .toolbar .btn { margin-left: auto; }
.inp-sm { width: 90px; padding: 5px 8px; font-size: .85rem; }

/* item rows (bill) */
.item-head { display: grid; grid-template-columns: 1fr 80px 90px 34px; gap: 8px; padding: 0 2px 4px; font-weight: 700; }
.item-row { display: grid; grid-template-columns: 1fr 80px 90px 34px; gap: 8px; margin-bottom: 8px; align-items: center; }
.item-row input, .item-row select { padding: 8px 9px; }
.total-row { display: flex; justify-content: space-between; padding: 12px 2px; border-top: 2px solid var(--bd); margin-top: 10px; font-size: 1.05rem; }
.total-row b { font-size: 1.2rem; color: var(--green-d); }

/* chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; overflow-x: auto; padding-bottom: 2px; }
.chips.static { margin-bottom: 10px; }
.chip { background: var(--card); border: 1px solid var(--bd); border-radius: 20px; padding: 7px 14px; font-size: .84rem; cursor: pointer; white-space: nowrap; color: var(--ink); font-family: inherit; }
.chip.active { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
.chips.static .chip { cursor: default; }

/* notes / alerts */
.note { background: var(--green-l); border-radius: 10px; padding: 12px 14px; font-size: .87rem; margin: 10px 0; line-height: 1.55; }
.note.warn { background: rgba(243,156,18,.12); }
.note.red { background: rgba(231,76,60,.1); color: var(--red); }
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); border-left: 3px solid var(--mu); cursor: pointer; }
.alert-item.up { border-left-color: var(--green); } .alert-item.down { border-left-color: var(--red); }
.alert-item:hover { background: var(--green-l); }
.big-answer { font-size: 1.2rem; font-weight: 700; color: var(--green-d); margin: 6px 0 10px; line-height: 1.4; }

/* empty state */
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state .big-ic { font-size: 3rem; margin-bottom: 10px; }
.empty-state h3 { font-size: 1.3rem; }
.empty-state p { max-width: 460px; margin: 8px auto 20px; }

/* progress bar */
.pbar { height: 8px; background: var(--bd); border-radius: 5px; overflow: hidden; margin: 8px 0; }
.pbar > div { height: 100%; background: var(--green); border-radius: 5px; transition: width .3s; }
.goal { padding: 12px 0; border-bottom: 1px solid var(--bd); }
.goal:last-child { border-bottom: 0; }

/* key-value (tally / feed) */
.kv { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.kv span { font-size: .8rem; color: var(--mu); min-width: 80px; }
.kv code { background: var(--bg); padding: 6px 10px; border-radius: 7px; font-size: .8rem; flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; border: 1px solid var(--bd); }
.kv code.trunc { text-overflow: ellipsis; overflow: hidden; }
.steps { padding-left: 20px; } .steps li { margin: 10px 0; line-height: 1.55; }
.flow { display: flex; align-items: stretch; gap: 6px; overflow-x: auto; padding: 6px 0 10px; }
.flow .box { background: var(--bg); border: 1px solid var(--bd); border-radius: 10px; padding: 10px 12px; min-width: 150px; font-size: .78rem; color: var(--mu); }
.flow .box b { display: block; color: var(--ink); font-size: .82rem; margin-bottom: 4px; }
.flow .arr { display: grid; place-items: center; color: var(--green); font-weight: 700; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.ok { background: var(--green); } .dot.late { background: var(--warn); } .dot.off { background: var(--red); } .dot.never { background: var(--mu); }

/* import/export */
.drop { border: 2px dashed var(--bd); border-radius: 12px; padding: 24px; text-align: center; position: relative; cursor: pointer; margin-top: 8px; }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.map-row { display: flex; align-items: center; gap: 8px; } .map-row span { font-size: .82rem; flex: 1; } .map-row select { width: auto; min-width: 130px; } .req { color: var(--red); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.col-row { display: flex; align-items: center; gap: 8px; } .col-row input[type=checkbox] { width: auto; } .col-row input[type=text] { flex: 1; padding: 6px 9px; font-size: .82rem; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--bd); flex-wrap: wrap; }
.set-row:last-child { border-bottom: 0; }
.heat { display: block; padding: 6px 8px; border-radius: 6px; font-size: .8rem; text-align: right; cursor: pointer; color: var(--ink); }

/* ===== modal ===== */
#modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-start; justify-content: center; padding: 30px 16px; background: rgba(0,0,0,.5); overflow-y: auto; }
#modal.show { display: flex; }
.modal-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 720px; max-height: calc(100vh - 60px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-bar { position: sticky; top: 0; background: var(--card); display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--bd); z-index: 2; }
.modal-bar button { background: transparent; border: 0; font-size: 1.1rem; cursor: pointer; color: var(--mu); padding: 4px 10px; border-radius: 7px; }
.modal-bar button:hover { background: var(--bg); }
.modal-body { padding: 18px; }
.modal-body h3 { margin-top: 16px; } .modal-body h3:first-child, .modal-body > h3.mt:first-child { margin-top: 0; }

/* toast */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--green-d); color: #fff; padding: 12px 22px; border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 70; font-size: .9rem; font-weight: 600; opacity: 0; transition: transform .3s, opacity .3s; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.bad { background: var(--red); }

/* ===== responsive ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .content { padding: 14px 16px 60px; }
  .card { padding: 14px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-card .number { font-size: 1.35rem; }
  .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  #range { max-width: 130px; font-size: .82rem; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar h1 { font-size: 1rem; }
  .modal-box { max-width: 100%; max-height: 100vh; border-radius: 0; min-height: 100vh; }
  #modal { padding: 0; }

  /* responsive table -> cards */
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt thead { display: none; }
  table.rt tr { margin-bottom: 10px; border: 1px solid var(--bd); border-radius: 10px; padding: 6px 12px; background: var(--card); }
  table.rt tr.empty { padding: 20px; text-align: center; }
  table.rt td { border-bottom: 1px solid var(--bd); padding: 8px 0; text-align: right; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  table.rt td:last-child { border-bottom: 0; }
  table.rt td::before { content: attr(data-l); font-weight: 700; color: var(--mu); font-size: .74rem; text-transform: uppercase; letter-spacing: .3px; text-align: left; }
  table.rt td:empty { display: none; }
  .item-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border: 1px solid var(--bd); border-radius: 9px; }
  .item-row .ir-p { grid-column: 1 / -1; }
  .item-row .btn-x { grid-column: 2; justify-self: end; }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) { .stats { grid-template-columns: 1fr; } }
@media print {
  .sidebar, .topbar, .btn, .btn-row, .chips, .menu-btn { display: none !important; }
  .main { margin-left: 0; } .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
