/* ─────────────────────────────────────────────────────────────
   WhatsApp Agri Automation — admin styles
   Plain CSS, no framework, no CDN. Mobile first.
   ───────────────────────────────────────────────────────────── */

:root {
  --green:        #226b3d;
  --green-dark:   #17512d;
  --green-light:  #e8f3ec;
  --wa:           #25d366;
  --ink:          #1c2321;
  --muted:        #6b7772;
  --line:         #e2e8e4;
  --bg:           #f6f8f7;
  --card:         #ffffff;
  --amber:        #b7791f;
  --amber-bg:     #fdf6e3;
  --red:          #c0392b;
  --red-bg:       #fdecea;
  --blue:         #2b6cb0;
  --blue-bg:      #ebf3fb;
  --radius:       10px;
  --shadow:       0 1px 2px rgba(16, 32, 24, .06), 0 4px 12px rgba(16, 32, 24, .04);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Noto Sans Devanagari", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--green); }

/* ── Top bar ────────────────────────────────────────────── */
.topbar {
  background: var(--green);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.topbar .spacer { flex: 1; }

.topbar .who {
  font-size: 13px;
  opacity: .85;
  white-space: nowrap;
}

.topbar a.logout {
  color: #fff;
  font-size: 13px;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, .35);
  padding: 5px 11px;
  border-radius: 20px;
}

.topbar a.logout:hover { background: rgba(255, 255, 255, .12); }

/* ── Navigation ─────────────────────────────────────────── */
.nav {
  background: var(--green-dark);
  display: flex;
  gap: 2px;
  padding: 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 49px;
  z-index: 49;
}

.nav::-webkit-scrollbar { display: none; }

.nav a {
  color: rgba(255, 255, 255, .78);
  text-decoration: none;
  padding: 11px 14px;
  font-size: 14px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}

.nav a:hover { color: #fff; }

.nav a.active {
  color: #fff;
  font-weight: 600;
  border-bottom-color: var(--wa);
}

/* ── Layout ─────────────────────────────────────────────── */
.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 14px 60px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.page-head h1 {
  font-size: 21px;
  margin: 0;
  flex: 1;
  min-width: 180px;
}

.page-head .sub {
  color: var(--muted);
  font-size: 13px;
  width: 100%;
  margin-top: -4px;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.card > h2 {
  font-size: 15px;
  margin: 0;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.card .body { padding: 16px; }

/* ── Stat tiles ─────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: block;
}

.stat:hover { border-color: var(--green); }

.stat .n {
  font-size: 27px;
  font-weight: 700;
  color: var(--green);
  line-height: 1.15;
}

.stat .l {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Tables ─────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  background: #fbfcfb;
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr:hover { background: #fafbfa; }

tbody tr:last-child td { border-bottom: 0; }

td.num, th.num { text-align: right; white-space: nowrap; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2.5px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.green  { background: var(--green-light); color: var(--green-dark); }
.badge.amber  { background: var(--amber-bg);    color: var(--amber); }
.badge.red    { background: var(--red-bg);      color: var(--red); }
.badge.blue   { background: var(--blue-bg);     color: var(--blue); }
.badge.grey   { background: #eef1f0;            color: var(--muted); }

/* ── Forms ──────────────────────────────────────────────── */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

input[type="text"], input[type="password"], input[type="number"],
input[type="search"], input[type="email"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 107, 61, .12);
}

textarea { min-height: 84px; resize: vertical; }

.field { margin-bottom: 14px; }

.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 14px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.check input { width: auto; }

/* ── Product images ─────────────────────────────────────── */
.img-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.img-fields { flex: 1 1 240px; min-width: 200px; }

.thumb {
  width: 108px;
  height: 108px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
  display: block;
}

.thumb.sm { width: 52px; height: 52px; border-radius: 6px; }

.empty-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  background: #f4f6f5;
  border-style: dashed;
  text-decoration: none;
}

.empty-thumb:hover { border-color: var(--green); color: var(--green); }

input[type="file"] {
  width: 100%;
  font-size: 13px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: var(--green-dark); border-color: var(--green-dark); }

.btn.ghost {
  background: #fff;
  color: var(--green);
}

.btn.ghost:hover { background: var(--green-light); }

.btn.grey {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
}

.btn.grey:hover { background: #f2f4f3; }

.btn.danger { background: var(--red); border-color: var(--red); }

.btn.sm { padding: 5px 11px; font-size: 12.5px; }

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Inline edit panel revealed by <details> inside a table cell. */
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
summary.btn::marker { content: ''; }

.edit-pop {
  margin-top: 8px;
  text-align: left;
  min-width: 210px;
}

.edit-pop + .edit-pop { margin-top: 6px; }

/* ── Filter bar ─────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
}

.filters .f { flex: 1 1 150px; min-width: 130px; }
.filters label { margin-bottom: 4px; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid;
}

.alert.ok   { background: var(--green-light); border-color: #bcd9c7; color: var(--green-dark); }
.alert.warn { background: var(--amber-bg);    border-color: #f0dfae; color: var(--amber); }
.alert.err  { background: var(--red-bg);      border-color: #f3c4bd; color: var(--red); }

/* ── Chat transcript ────────────────────────────────────── */
.chat {
  background: #ece5dd;
  padding: 14px;
  max-height: 620px;
  overflow-y: auto;
}

.bubble {
  max-width: 78%;
  padding: 8px 11px;
  border-radius: 9px;
  margin-bottom: 9px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
}

.bubble.in  { background: #fff; }
.bubble.out { background: #d9fdd3; margin-left: auto; }

.bubble .meta {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 4px;
  text-align: right;
}

/* ── Login ──────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%);
}

.login-box {
  background: #fff;
  border-radius: 14px;
  padding: 30px 26px;
  width: 100%;
  max-width: 370px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}

.login-box h1 {
  font-size: 19px;
  margin: 0 0 4px;
  text-align: center;
}

.login-box .tag {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.login-box .btn { width: 100%; justify-content: center; margin-top: 4px; }

/* On narrow phones the card padding alone can push past the viewport. */
@media (max-width: 420px) {
  .login-wrap { padding: 12px; }
  .login-box  { padding: 24px 18px; }
}

/* ── Pagination ─────────────────────────────────────────── */
.pager {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  padding: 14px;
  flex-wrap: wrap;
  font-size: 13px;
}

.pager a, .pager span {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
}

.pager .cur { background: var(--green); color: #fff; border-color: var(--green); }

/* ── Utilities ──────────────────────────────────────────── */
.muted    { color: var(--muted); }
.small    { font-size: 12.5px; }
.nowrap   { white-space: nowrap; }
.right    { text-align: right; }
.mt       { margin-top: 14px; }
.hide-sm  { }

/* ── Responsive: stack tables into cards on small screens ── */
@media (max-width: 720px) {
  .wrap { padding: 14px 10px 50px; }

  .page-head h1 { font-size: 19px; }

  .hide-sm { display: none !important; }

  table, thead, tbody, th, td, tr { display: block; }

  thead { display: none; }

  tbody tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 0;
    background: #fff;
  }

  td {
    border: 0;
    padding: 7px 13px;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    text-align: right;
  }

  /* Uses the data-label attribute set on every cell. */
  td::before {
    content: attr(data-label);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }

  td.num { text-align: right; }

  /* The action cell holds a pop-out form — stack it full width so the
     form cannot spill outside the card. */
  td.right {
    display: block;
    text-align: left;
  }

  td.right::before {
    display: block;
    margin-bottom: 6px;
  }

  .edit-pop {
    min-width: 0;
    width: 100%;
  }

  .bubble { max-width: 90%; }

  .stat .n { font-size: 23px; }
}

/* ── Branding assets grid ───────────────────────────────── */
.brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.brand-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfcfb;
}

.brand-label { font-weight: 600; font-size: 13.5px; margin-bottom: 10px; }

.brand-img {
  width: 100%;
  height: 130px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}
