:root {
  --ink: #17231f;
  --muted: #69756f;
  --paper: #f5f3ed;
  --card: #fffefa;
  --green: #18392f;
  --green-2: #285b49;
  --mint: #dce9df;
  --orange: #d9793b;
  --orange-soft: #f6e2d3;
  --red: #b6453d;
  --line: #dedfd9;
  --shadow: 0 14px 36px rgba(31, 48, 41, .08);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -.035em; }

.eyebrow {
  color: var(--orange);
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.brand-mark {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border-radius: 20px;
  color: white;
  background: var(--orange);
  font: 800 32px/1 Georgia, serif;
  box-shadow: 0 12px 28px rgba(104, 46, 15, .2);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 22px; }
.login-screen {
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 28px;
  padding: 32px 20px;
  color: white;
  background:
    radial-gradient(circle at 90% 5%, rgba(217,121,59,.24), transparent 24rem),
    linear-gradient(145deg, #10271f, #1c4437);
}
.login-brand { max-width: 480px; }
.login-brand .brand-mark { margin-bottom: 32px; }
.login-brand h1 { margin-bottom: 14px; font: 700 clamp(38px, 10vw, 64px)/.98 Georgia, serif; }
.login-brand > p:last-child { color: #cbd9d2; font-size: 17px; }
.login-card {
  display: grid;
  gap: 18px;
  padding: 24px;
  color: var(--ink);
  background: var(--card);
  border-radius: 26px;
  box-shadow: 0 24px 70px rgba(0,0,0,.22);
}
.login-card h2 { margin-bottom: 0; font-size: 25px; }
label { display: grid; gap: 7px; color: #3e4b45; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  color: var(--ink);
  background: #fbfbf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(40,91,73,.12); }
textarea { min-height: 88px; resize: vertical; }
.btn {
  min-height: 42px;
  padding: 10px 15px;
  color: var(--ink);
  background: white;
  border: 0;
  border-radius: 12px;
  font-weight: 800;
}
.btn-primary { color: white; background: var(--green); box-shadow: 0 8px 18px rgba(24,57,47,.18); }
.btn-primary:hover { background: var(--green-2); }
.btn-orange { color: white; background: var(--orange); }
.btn-soft { background: #edf1ed; }
.btn-large { min-height: 54px; display: flex; justify-content: space-between; align-items: center; padding-inline: 18px; }
.form-error { color: var(--red); font-weight: 700; }
.demo-logins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.demo-logins p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 11px; text-align: center; text-transform: uppercase; letter-spacing: .1em; }
.demo-logins .btn { padding: 8px; font-size: 12px; }
.login-footer { margin: 0; color: #a7bdb3; font-size: 12px; text-align: center; }

.app-shell { min-height: 100vh; }
.sidebar { display: none; }
.main { min-width: 0; padding-bottom: calc(84px + var(--safe-bottom)); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 18px 14px;
}
.topbar h1 { margin: 0; font: 700 29px/1.1 Georgia, serif; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.notification-button, .icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: white;
  color: var(--orange);
}
.page-content { padding: 8px 16px 28px; }
.mobile-nav {
  position: fixed;
  z-index: 20;
  right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  left: 10px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 8px;
  background: rgba(255,254,250,.94);
  border: 1px solid rgba(222,223,217,.8);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(20,41,33,.16);
  backdrop-filter: blur(14px);
}
.nav-button {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 14px;
  font-size: 10px;
  font-weight: 800;
}
.nav-button .nav-icon { font-size: 19px; line-height: 1; }
.nav-button.active { color: var(--green); background: var(--mint); }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.quick-action {
  min-height: 88px;
  padding: 14px 10px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(31,48,41,.05);
}
.quick-action strong, .quick-action span { display: block; }
.quick-action strong { margin-top: 8px; font-size: 13px; }
.quick-action span:first-child { color: var(--orange); font-size: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 14px; margin: 24px 0 12px; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.text-button { padding: 5px; color: var(--green-2); background: none; border: 0; font-weight: 800; }
.card {
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-card {
  position: relative;
  overflow: hidden;
  padding: 24px;
  color: white;
  background: var(--green);
  border: 0;
}
.hero-card::after {
  content: "";
  position: absolute;
  width: 170px; height: 170px; right: -60px; top: -80px;
  border: 30px solid rgba(255,255,255,.05); border-radius: 50%;
}
.hero-card .eyebrow { color: #edaa75; }
.hero-card h2 { margin: 4px 0 8px; font: 700 34px Georgia, serif; }
.hero-card p { margin-bottom: 20px; color: #cad9d2; }
.metric-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric-card { padding: 17px; background: var(--card); border: 1px solid var(--line); border-radius: 17px; }
.metric-card span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card strong { display: block; margin-top: 6px; font: 700 24px Georgia, serif; }
.metric-card.accent { color: white; background: var(--orange); border-color: var(--orange); }
.metric-card.accent span { color: #fff0e5; }
.metric-card.warn strong { color: var(--red); }
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.kpi-card { min-height: 118px; padding: 17px; background: var(--card); border: 1px solid var(--line); border-radius: 17px; }
.kpi-card .kpi-icon { display: grid; width: 34px; height: 34px; place-items: center; color: var(--green); background: var(--mint); border-radius: 10px; }
.kpi-card strong { display: block; margin: 17px 0 2px; font: 700 24px Georgia, serif; }
.kpi-card span { color: var(--muted); font-size: 12px; font-weight: 700; }

.production-form { display: grid; gap: 14px; }
.product-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.product-option { position: relative; }
.product-option input { position: absolute; opacity: 0; pointer-events: none; }
.product-option label {
  min-height: 98px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
  color: var(--ink);
  background: #f7f7f3;
  border: 2px solid transparent;
  border-radius: 15px;
}
.product-option input:checked + label { background: var(--mint); border-color: var(--green-2); }
.product-option label span { color: var(--muted); font-size: 12px; font-weight: 600; }
.product-option label strong { font-size: 15px; }
.pieces-input { font-size: 30px; font-weight: 800; text-align: center; }
.calculation-box { display: flex; justify-content: space-between; padding: 14px; background: var(--orange-soft); border-radius: 13px; }
.calculation-box strong { color: #9f4a1f; }
.entry-list, .retailer-list, .invoice-list { display: grid; gap: 10px; }
.list-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 15px; background: var(--card); border: 1px solid var(--line); border-radius: 15px; }
.list-card h3 { margin: 0 0 4px; font-size: 15px; letter-spacing: -.01em; }
.list-card p { margin: 0; color: var(--muted); font-size: 12px; }
.list-value { text-align: right; white-space: nowrap; }
.list-value strong, .list-value span { display: block; }
.list-value strong { font-size: 16px; }
.list-value span { color: var(--muted); font-size: 11px; }
.positive { color: var(--green-2); }
.negative, .overdue { color: var(--red) !important; }
.status { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.status-paid { color: var(--green-2); background: var(--mint); }
.status-due { color: #a95426; background: var(--orange-soft); }
.filter-row { display: flex; gap: 8px; overflow: auto; padding-bottom: 4px; }
.filter-chip { white-space: nowrap; padding: 9px 13px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; font-weight: 800; }
.filter-chip.active { color: white; background: var(--green); border-color: var(--green); }
.search-box { position: relative; margin-bottom: 12px; }
.search-box input { padding-left: 42px; }
.search-box::before { content: "⌕"; position: absolute; z-index: 1; left: 15px; top: 8px; color: var(--muted); font-size: 22px; }
.balance-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; overflow: hidden; margin-bottom: 16px; background: var(--line); border: 1px solid var(--line); border-radius: 17px; }
.balance-strip > div { padding: 16px; background: var(--card); }
.balance-strip span, .balance-strip strong { display: block; }
.balance-strip span { color: var(--muted); font-size: 11px; font-weight: 700; }
.balance-strip strong { margin-top: 4px; font: 700 22px Georgia, serif; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 17px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
td { font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.line-items { display: grid; gap: 10px; }
.line-item { display: grid; grid-template-columns: 1fr 72px 90px 36px; gap: 7px; align-items: end; }
.line-item label { font-size: 10px; }
.line-item input, .line-item select { min-height: 43px; padding: 9px; }
.remove-line { width: 36px; height: 43px; color: var(--red); background: #f9e8e6; border: 0; border-radius: 10px; }
.invoice-total { display: flex; justify-content: space-between; align-items: center; padding: 17px; background: var(--green); color: white; border-radius: 15px; }
.invoice-total strong { font: 700 25px Georgia, serif; }
.form-grid { display: grid; gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.app-dialog { width: min(680px, calc(100% - 24px)); max-height: 88vh; padding: 0; border: 0; border-radius: 24px; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.app-dialog::backdrop { background: rgba(13,29,24,.6); backdrop-filter: blur(4px); }
.dialog-head { position: sticky; z-index: 3; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 20px 20px 12px; background: var(--card); }
.dialog-head h2 { margin: 0; }
#dialog-content { padding: 8px 20px 22px; }
.empty-state { padding: 36px; text-align: center; color: var(--muted); }
.empty-icon { display: grid; width: 50px; height: 50px; margin: 0 auto 14px; place-items: center; color: var(--green); background: var(--mint); border-radius: 50%; font-weight: 900; }
.toast { position: fixed; z-index: 100; right: 16px; bottom: 100px; left: 16px; padding: 13px 16px; color: white; background: var(--green); border-radius: 13px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: none; }
.skeleton { min-height: 110px; background: linear-gradient(100deg, #ecece7 30%, #f7f7f3 50%, #ecece7 70%); background-size: 300% 100%; animation: shimmer 1.5s infinite; border-radius: 16px; }
@keyframes shimmer { to { background-position: -150% 0; } }

@media (min-width: 760px) {
  .login-screen { grid-template-columns: minmax(300px, 1fr) minmax(360px, 430px); align-items: center; padding: 7vw; }
  .login-footer { grid-column: 1 / -1; }
  .app-shell { display: grid; grid-template-columns: 248px 1fr; }
  .sidebar { position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column; padding: 24px 16px; color: white; background: var(--green); }
  .sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
  .sidebar-brand strong, .sidebar-brand span { display: block; }
  .sidebar-brand span { color: #91ac9f; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
  .nav-list { display: grid; gap: 5px; }
  .nav-list .nav-button { min-height: 46px; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; color: #bcd0c7; font-size: 13px; }
  .nav-list .nav-button.active { color: white; background: rgba(255,255,255,.11); }
  .sidebar-user { display: grid; grid-template-columns: 38px 1fr 34px; gap: 10px; align-items: center; margin-top: auto; padding: 14px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
  .avatar { display: grid; width: 38px; height: 38px; place-items: center; color: var(--green); background: #e7d7c5; border-radius: 50%; font-weight: 900; }
  .sidebar-user strong, .sidebar-user span { display: block; }
  .sidebar-user strong { font-size: 12px; }
  .sidebar-user span { color: #91ac9f; font-size: 10px; }
  .sidebar-user .icon-button { width: 34px; height: 34px; color: white; background: rgba(255,255,255,.1); }
  .main { padding-bottom: 0; }
  .topbar { padding: 32px 38px 18px; }
  .page-content { max-width: 1180px; padding: 12px 38px 48px; }
  .mobile-nav { display: none; }
  .toast { left: auto; bottom: 24px; width: 360px; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .metric-row { grid-template-columns: repeat(4, 1fr); }
  .dashboard-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
  .production-layout { display: grid; grid-template-columns: minmax(360px, .8fr) 1.2fr; gap: 20px; align-items: start; }
  .khata-layout { display: grid; grid-template-columns: minmax(310px, .75fr) 1.25fr; gap: 18px; align-items: start; }
}

@media print {
  body { background: white; }
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; inset: 0; padding: 28px; }
  .no-print { display: none !important; }
}
