/* =====================================================================
   Jashmin dai ko Masu Pasal — UI
   Direction: a poultry wholesaler's paper ledger. Warm butcher paper,
   ink, one confident brick-red. Figures set in monospace so the
   accounting reads like an account book. Headings in a grotesque.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,500;12..96,600;12..96,700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --paper:    #f4efe4;
  --paper-2:  #ece5d6;
  --card:     #fffdf8;
  --ink:      #211d18;
  --ink-soft: #5c554a;
  --line:     #ddd4c2;
  --brick:    #b23a2e;
  --brick-d:  #8f2c22;
  --green:    #2f7d4f;
  --green-bg: #e7f1ea;
  --amber:    #b07814;
  --amber-bg: #f6edd6;
  --red-bg:   #f6e2df;
  --shadow:   0 1px 0 #fff inset, 0 1px 2px rgba(33,29,24,.06), 0 8px 24px -16px rgba(33,29,24,.35);

  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body:    'Inter', system-ui, sans-serif;
  --mono:    'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(33,29,24,.025) 27px 28px);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brick); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--ink);
  color: #efe9dc;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}
.brand { display: flex; gap: 11px; align-items: center; margin-bottom: 4px; padding: 0 6px; }
.brand .mark {
  width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
  background: var(--brick); color: #fff;
  display: grid; place-items: center; font-size: 20px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset;
}
.brand h1 { font-family: var(--display); font-size: 16px; font-weight: 700; margin: 0; line-height: 1.15; letter-spacing: -.01em; }
.brand span { font-size: 11px; color: #b8ad99; letter-spacing: .04em; text-transform: uppercase; }

.nav { margin-top: 22px; display: flex; flex-direction: column; gap: 2px; }
.nav .label { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #8c8270; margin: 16px 8px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 8px; color: #d8d1c2;
  font-weight: 500; font-size: 14px; transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brick); color: #fff; }
.nav a .ic { width: 18px; text-align: center; opacity: .9; }

.side-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .who { font-size: 13px; color: #d8d1c2; padding: 0 8px 8px; }
.side-foot .who b { color: #fff; font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
  background: rgba(244,239,228,.85); backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-family: var(--display); font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.topbar .date-chip {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft);
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 13px; box-shadow: var(--shadow);
}
.topbar .date-chip b { color: var(--brick); }
.content { padding: 26px 28px 60px; }

/* ---------- Cards & sections ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 18px; }
.card > h2, .section-title {
  font-family: var(--display); font-size: 16px; font-weight: 600;
  margin: 0 0 14px; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 9px;
}
.section-title .bar { width: 4px; height: 17px; background: var(--brick); border-radius: 2px; display: inline-block; }

.grid { display: grid; gap: 18px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

/* ---------- Stat tiles ---------- */
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  padding: 17px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brick); }
.stat .k { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.stat .v { font-family: var(--mono); font-size: 27px; font-weight: 700; margin-top: 7px; letter-spacing: -.02em; }
.stat .sub { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.stat.green::before { background: var(--green); }
.stat.amber::before { background: var(--amber); }
.stat.ink::before   { background: var(--ink); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: 11px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: var(--card); }
thead th {
  text-align: left; font-size: 11px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-soft); font-weight: 600; padding: 11px 14px;
  background: var(--paper-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbf8f1; }
td.num, th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.muted { color: var(--ink-soft); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.pending   { background: var(--amber-bg); color: var(--amber); }
.badge.accepted  { background: #e6eef7; color: #2b5d99; }
.badge.delivered { background: var(--green-bg); color: var(--green); }
.badge.cancelled { background: var(--red-bg); color: var(--brick-d); }
.badge.active    { background: var(--green-bg); color: var(--green); }
.badge.blocked   { background: var(--red-bg); color: var(--brick-d); }
.badge.due       { background: var(--red-bg); color: var(--brick-d); }
.badge.clear     { background: var(--green-bg); color: var(--green); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-family: var(--body); font-size: 14px; font-weight: 600;
  padding: 9px 15px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); transition: .12s; text-decoration: none;
}
.btn:hover { background: var(--paper-2); text-decoration: none; }
.btn.primary { background: var(--brick); border-color: var(--brick-d); color: #fff; }
.btn.primary:hover { background: var(--brick-d); }
.btn.green { background: var(--green); border-color: #245f3c; color: #fff; }
.btn.green:hover { filter: brightness(.94); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
label.fld { display: block; margin-bottom: 14px; }
label.fld .lab { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=tel], select, textarea {
  width: 100%; font-family: var(--body); font-size: 14.5px; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brick); box-shadow: 0 0 0 3px rgba(178,58,46,.13);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; font-size: 14px; border: 1px solid; }
.flash.success { background: var(--green-bg); border-color: #bcdcca; color: var(--green); }
.flash.error   { background: var(--red-bg);  border-color: #e6c3bd; color: var(--brick-d); }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card { padding: 30px 28px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .mark {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 14px;
  background: var(--brick); color: #fff; display: grid; place-items: center; font-size: 30px;
  box-shadow: var(--shadow);
}
.auth-head h1 { font-family: var(--display); font-size: 21px; margin: 0; letter-spacing: -.01em; }
.auth-head p { color: var(--ink-soft); font-size: 13.5px; margin: 5px 0 0; }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--ink-soft); margin-top: 16px; }

/* ---------- Order item builder ---------- */
.line-items { display: flex; flex-direction: column; gap: 10px; }
.line-item {
  display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 10px; align-items: end;
  padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: #fcfaf4;
}
.line-item .rm { background: var(--red-bg); border-color: #e6c3bd; color: var(--brick-d); }
.totals-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 16px; padding: 14px 16px; border-radius: 11px;
  background: var(--ink); color: #fff;
}
.totals-bar .lbl { font-size: 13px; letter-spacing: .05em; text-transform: uppercase; color: #c9c0ae; }
.totals-bar .amt { font-family: var(--mono); font-size: 24px; font-weight: 700; }

/* ---------- Misc ---------- */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.chart-box { position: relative; height: 280px; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 20px; font-size: 14px; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; font-weight: 500; }
.hint { font-size: 12.5px; color: var(--ink-soft); }
.mono { font-family: var(--mono); }
.pos { color: var(--green); } .neg { color: var(--brick-d); }

/* ---------- Mobile ---------- */
.menu-btn { display: none; }
@media (max-width: 880px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; height: 100vh;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-grid; place-items: center; width: 40px; height: 40px;
    border: 1px solid var(--line); border-radius: 9px; background: var(--card); cursor: pointer; font-size: 18px; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
  .backdrop.show { display: block; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .line-item { grid-template-columns: 1fr 1fr; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* ---------- Order form: fields, alerts, line-item editor ---------- */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field .muted { font-weight: 400; }
.bs-line { margin-top: 7px; font-size: 13px; color: var(--ink-soft); }
.bs-line strong { color: var(--brick); }

.alert { border-radius: 9px; padding: 11px 14px; margin-bottom: 16px; font-size: 14px;
         border: 1px solid var(--line); background: var(--card); }
.alert.error { background: var(--red-bg); border-color: #e6c3bd; color: var(--brick-d); }
.alert div + div { margin-top: 3px; }

.btn.block { display: block; width: 100%; text-align: center; }

.lineitems { display: flex; flex-direction: column; gap: 8px; }
.li-head, .li-row {
  display: grid; grid-template-columns: 1fr 70px 96px 96px 30px;
  gap: 8px; align-items: center;
}
.li-head { font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
           color: var(--ink-soft); padding: 0 2px 4px; border-bottom: 1px solid var(--line); }
.li-row .li-rate, .li-row .li-amt { font-size: 13px; color: var(--ink-soft); text-align: right; }
.li-row select, .li-row input { margin: 0; }
.li-del { border: 1px solid var(--line); background: var(--card); color: var(--brick-d);
          border-radius: 7px; cursor: pointer; height: 34px; font-size: 13px; }
.li-del:hover { background: var(--red-bg); }
@media (max-width: 560px){
  .li-head { display: none; }
  .li-row { grid-template-columns: 1fr 60px 30px; grid-auto-rows: auto; }
  .li-row .li-rate { grid-column: 1 / 2; text-align: left; }
  .li-row .li-amt  { grid-column: 2 / 4; }
}

/* ============================================================
   Mobile-friendly tables: stack rows into cards at phone width.
   Add class "resp" to <table> and "cards" to the .table-wrap,
   and give each <td> a data-label="…". Action cell gets .actions.
   ============================================================ */
@media (max-width: 640px) {
  .table-wrap.cards { border: none; overflow: visible; border-radius: 0; }
  table.resp, table.resp tbody, table.resp tr, table.resp td { display: block; width: 100%; }
  table.resp thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.resp tr {
    border: 1px solid var(--line); border-radius: 12px; background: var(--card);
    margin-bottom: 12px; padding: 4px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
  }
  table.resp td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 10px 0; border-bottom: 1px dashed var(--line); text-align: right; white-space: normal;
  }
  table.resp td:last-child { border-bottom: none; }
  table.resp td::before {
    content: attr(data-label); flex: 0 0 auto; text-align: left;
    font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    color: var(--ink-soft);
  }
  table.resp td.num { font-family: var(--mono); }
  /* hide empty-label cells' colon gap cleanly */
  table.resp td[data-label=""]::before { content: ""; }

  /* Action cell: label on top, full-width tappable buttons stacked */
  table.resp td.actions { flex-direction: column; align-items: stretch; gap: 8px; }
  table.resp td.actions::before { text-align: left; }
  table.resp td.actions .btn-row { flex-direction: column; gap: 8px; width: 100%; }
  table.resp td.actions .btn-row form { width: 100%; }
  table.resp td.actions .btn { width: 100%; justify-content: center; min-height: 42px; }

  /* Comfortable tap targets for any inline action buttons on mobile */
  .btn.sm { padding: 9px 12px; font-size: 13.5px; }
}
