:root {
  --ink: #153125;
  --ink-2: #335044;
  --muted: #6f7f76;
  --paper: #f3f1ea;
  --surface: #fffefb;
  --surface-2: #e9eee8;
  --green: #173c2a;
  --green-2: #285d41;
  --lime: #bed15a;
  --lime-soft: #eef4cf;
  --gold: #b98942;
  --danger: #a83e34;
  --danger-soft: #f9e8e5;
  --warning: #9b681c;
  --warning-soft: #fff1d4;
  --success: #1f6f49;
  --success-soft: #e3f3ea;
  --border: rgba(23, 60, 42, .13);
  --shadow: 0 24px 70px rgba(19, 48, 34, .12);
  --shadow-sm: 0 10px 28px rgba(19, 48, 34, .08);
  --radius: 24px;
  --radius-sm: 14px;
  --sidebar: 272px;
  --topbar: 78px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(190, 209, 90, .10), transparent 36%),
    linear-gradient(145deg, #f8f6ef, #efeee8);
  font-family: "DM Sans", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-variant-numeric: tabular-nums; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(420px, .85fr);
  overflow: hidden;
}
.login-visual {
  min-height: 100vh;
  position: relative;
  padding: clamp(34px, 6vw, 90px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  background:
    linear-gradient(120deg, rgba(14, 46, 31, .96), rgba(23, 60, 42, .84)),
    radial-gradient(circle at 80% 20%, rgba(190, 209, 90, .28), transparent 35%);
}
.login-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .14;
  background-image: linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}
.brand-mark {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: Manrope, sans-serif;
  font-weight: 800;
  letter-spacing: -.03em;
}
.brand-symbol {
  width: 42px;
  height: 42px;
  border-radius: 50% 50% 46% 54% / 58% 43% 57% 42%;
  background: var(--lime);
  box-shadow: inset -8px -8px 18px rgba(23,60,42,.25);
  transform: rotate(-12deg);
}
.login-copy { position: relative; z-index: 1; max-width: 720px; }
.login-copy h1 {
  margin: 0 0 20px;
  max-width: 800px;
  font: 800 clamp(3rem, 7vw, 7rem)/.92 Manrope, sans-serif;
  letter-spacing: -.065em;
}
.login-copy p { margin: 0; max-width: 620px; color: rgba(255,255,255,.78); font-size: clamp(1.05rem, 2vw, 1.28rem); line-height: 1.7; }
.login-features { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 10px; }
.login-features span { padding: 10px 14px; border: 1px solid rgba(255,255,255,.16); border-radius: 99px; background: rgba(255,255,255,.07); backdrop-filter: blur(12px); font-size: .9rem; }
.login-panel { min-height: 100vh; display: grid; place-items: center; padding: 34px; background: rgba(255,255,255,.48); backdrop-filter: blur(22px); }
.login-card { width: min(100%, 470px); background: rgba(255,254,251,.92); border: 1px solid var(--border); border-radius: 30px; padding: clamp(28px, 4vw, 48px); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 12px; color: var(--green-2); font-weight: 800; text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; }
.login-card h2 { margin: 0 0 10px; font: 800 2rem/1.1 Manrope, sans-serif; letter-spacing: -.04em; }
.login-card > p { margin: 0 0 28px; color: var(--muted); line-height: 1.6; }

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { font-weight: 700; font-size: .9rem; }
.input, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
  outline: none;
  transition: .2s ease;
}
.field textarea { min-height: 108px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 4px rgba(40,93,65,.10); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; padding: 8px; color: var(--muted); }

.btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-weight: 800;
  text-decoration: none;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--green); box-shadow: 0 10px 24px rgba(23,60,42,.22); }
.btn-primary:hover { background: #0f3020; }
.btn-accent { color: var(--green); background: var(--lime); }
.btn-secondary { color: var(--green); background: #fff; border-color: var(--border); }
.btn-ghost { color: var(--green); background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 8px 11px; border-radius: 10px; font-size: .86rem; }
.login-links { display: flex; justify-content: space-between; gap: 16px; margin-top: 18px; font-size: .9rem; }
.login-links button { border: 0; background: transparent; padding: 0; color: var(--green-2); font-weight: 700; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  z-index: 30;
  display: flex;
  flex-direction: column;
  color: #fff;
  background: linear-gradient(180deg, #173c2a, #102d20);
  border-right: 1px solid rgba(255,255,255,.08);
}
.sidebar-head { min-height: var(--topbar); padding: 18px 22px; display: flex; align-items: center; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand-mark { font-size: 1rem; }
.sidebar .brand-symbol { width: 34px; height: 34px; }
.nav { display: grid; gap: 5px; padding: 22px 14px; overflow: auto; }
.nav-item {
  width: 100%;
  border: 0;
  color: rgba(255,255,255,.68);
  background: transparent;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-weight: 700;
}
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.10); }
.nav-icon { width: 22px; text-align: center; font-size: 1.05rem; }
.sidebar-foot { margin-top: auto; padding: 18px 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.07); }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--green); background: var(--lime); font-weight: 800; }
.user-chip strong, .user-chip span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip span { color: rgba(255,255,255,.55); font-size: .75rem; }
.logout-btn { border: 0; background: transparent; color: rgba(255,255,255,.7); padding: 7px; }

.main { grid-column: 2; min-width: 0; }
.topbar {
  height: var(--topbar);
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(20px, 4vw, 48px);
  background: rgba(248,246,239,.82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.topbar-title strong { display: block; font: 800 1.05rem Manrope, sans-serif; }
.topbar-title span { color: var(--muted); font-size: .82rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mobile-toggle { display: none; border: 0; background: transparent; font-size: 1.35rem; }
.page { padding: clamp(24px, 4vw, 48px); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 28px; }
.page-head h1 { margin: 0; font: 800 clamp(2rem, 4vw, 3.7rem)/1 Manrope, sans-serif; letter-spacing: -.055em; }
.page-head p { margin: 10px 0 0; max-width: 740px; color: var(--muted); line-height: 1.65; }
.page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 26px; }
.kpi {
  min-height: 150px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,254,251,.88);
  box-shadow: var(--shadow-sm);
}
.kpi-top { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-weight: 700; font-size: .86rem; }
.kpi-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; color: var(--green); background: var(--lime-soft); }
.kpi-value { margin-top: 18px; font: 800 clamp(1.6rem, 2.8vw, 2.55rem)/1 Manrope, sans-serif; letter-spacing: -.04em; }
.kpi-note { margin-top: 10px; color: var(--muted); font-size: .8rem; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 20px; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: rgba(255,254,251,.90); box-shadow: var(--shadow-sm); overflow: hidden; }
.panel-head { padding: 20px 22px; display: flex; justify-content: space-between; align-items: center; gap: 14px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font: 800 1.05rem Manrope, sans-serif; }
.panel-body { padding: 20px 22px; }

.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar .input { width: auto; min-width: 170px; min-height: 42px; padding: 10px 12px; }
.toolbar .search { flex: 1; min-width: 220px; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #f5f5f0; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; }
tbody tr:hover { background: #fafbf6; }
tbody tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 10px; background: #fff; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }

.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 99px; padding: 6px 9px; font-size: .75rem; font-weight: 800; white-space: nowrap; }
.badge-success { color: var(--success); background: var(--success-soft); }
.badge-warning { color: var(--warning); background: var(--warning-soft); }
.badge-danger { color: var(--danger); background: var(--danger-soft); }
.badge-neutral { color: var(--ink-2); background: #edf0ed; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 6px; color: var(--ink); }

.activity-list { display: grid; gap: 12px; }
.activity-item { display: grid; grid-template-columns: 38px 1fr; gap: 11px; align-items: start; }
.activity-dot { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--lime-soft); }
.activity-item strong { display: block; margin-bottom: 3px; }
.activity-item p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(8, 25, 16, .55); backdrop-filter: blur(8px); }
.modal { width: min(100%, 820px); max-height: min(92vh, 980px); display: flex; flex-direction: column; border-radius: 25px; background: var(--surface); box-shadow: 0 30px 100px rgba(0,0,0,.28); overflow: hidden; }
.modal-sm { width: min(100%, 520px); }
.modal-head { padding: 21px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font: 800 1.25rem Manrope, sans-serif; }
.modal-close { border: 0; background: transparent; font-size: 1.3rem; }
.modal-body { padding: 22px 24px; overflow: auto; }
.modal-actions { padding: 17px 24px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); background: #fafaf6; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { grid-column: 1/-1; margin: 8px 0 18px; padding-top: 14px; border-top: 1px solid var(--border); font: 800 .88rem Manrope, sans-serif; }
.checkbox-row { display: flex; align-items: flex-start; gap: 10px; }
.checkbox-row input { margin-top: 4px; }

.settlement-deliveries { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 14px; }
.settlement-line { display: grid; grid-template-columns: auto 1fr 120px; gap: 12px; align-items: center; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.settlement-line:last-child { border-bottom: 0; }
.settlement-line input[type="number"] { width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 8px; }
.totals-box { margin-top: 14px; padding: 16px; border-radius: 14px; background: var(--surface-2); }
.total-row { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; }
.total-row.final { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--border); font-weight: 800; font-size: 1.08rem; }

.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: grid; gap: 10px; }
.toast { max-width: 420px; padding: 13px 16px; border-radius: 13px; color: #fff; background: var(--green); box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.loading-screen { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(23,60,42,.14); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.setup-shell { min-height: 100vh; padding: 40px 20px; display: grid; place-items: center; }
.setup-card { width: min(100%, 880px); padding: clamp(26px, 5vw, 54px); border: 1px solid var(--border); border-radius: 30px; background: var(--surface); box-shadow: var(--shadow); }
.setup-card h1 { margin: 0 0 14px; font: 800 clamp(2rem,5vw,4rem)/1 Manrope,sans-serif; letter-spacing: -.05em; }
.setup-card code { display: block; margin: 18px 0; padding: 16px; border-radius: 12px; background: #122d21; color: #dff0d5; overflow: auto; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  :root { --sidebar: 286px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-visual { min-height: 48vh; }
  .login-panel { min-height: 52vh; }
  .sidebar { transform: translateX(-102%); transition: transform .24s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { grid-column: 1; }
  .mobile-toggle { display: inline-grid; }
  .topbar { padding: 0 18px; }
  .page { padding: 22px 16px 40px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-actions { justify-content: flex-start; }
}
@media (max-width: 620px) {
  .login-visual { padding: 28px 22px; }
  .login-panel { padding: 20px 14px 30px; }
  .login-card { padding: 26px 20px; }
  .login-links { align-items: flex-start; flex-direction: column; }
  .kpi-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-section { grid-column: 1; }
  .page-head h1 { font-size: 2.35rem; }
  .modal { max-height: 96vh; border-radius: 19px; }
  .modal-head, .modal-body, .modal-actions { padding-left: 16px; padding-right: 16px; }
  .settlement-line { grid-template-columns: auto 1fr; }
  .settlement-line > input[type="number"] { grid-column: 2; }
}
