:root {
  --ink: #241c16;
  --paper: #f7f2ea;
  --paper-raised: #fffdf9;
  --line: #e4d9c9;
  --clay: #b6502f;
  --clay-dark: #8f3c22;
  --clay-soft: #f3e2d9;
  --moss: #52662f;
  --gold: #a5781f;
  --muted: #776b5c;
  --danger: #a3312a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(36, 28, 22, .06);
  --shadow-md: 0 6px 20px -6px rgba(36, 28, 22, .18);
  --ease: cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Manrope", -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.num { font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace; font-variant-numeric: tabular-nums; font-size: .93em; }

a { color: var(--clay-dark); }

h1, h2, h3 { font-family: inherit; font-weight: 800; margin: 0 0 .5rem; letter-spacing: -0.02em; }
h1 { font-size: 1.5rem; }

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

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #fff;
  margin-bottom: .15rem;
}

.brand-sub {
  font-size: .68rem;
  color: #c9bda9;
  text-transform: uppercase;
  letter-spacing: .12em;
  margin-bottom: 1.75rem;
  font-weight: 600;
}

.nav-group { margin-bottom: 1.25rem; }

.nav-label {
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #a3937c;
  margin: 0 0 .4rem .1rem;
  font-weight: 700;
}

.nav-link {
  display: block;
  padding: .42rem .55rem;
  border-radius: var(--radius-sm);
  color: #e8ddcd;
  text-decoration: none;
  font-size: .91rem;
  font-weight: 600;
  margin-bottom: .1rem;
  transition: background .12s var(--ease), color .12s var(--ease);
}

.nav-link:hover { background: rgba(255,255,255,.08); }
.nav-link.active { background: var(--clay); color: #fff; }

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,.15);
  padding-top: 1rem;
  font-size: .82rem;
}

.sidebar-foot form { margin-top: .4rem; }

.btn-link-plain {
  background: none;
  border: none;
  color: #c9bda9;
  cursor: pointer;
  padding: 0;
  font-size: .82rem;
  text-decoration: underline;
  font-family: inherit;
}

.main { flex: 1; padding: 2rem 2.5rem; max-width: 1240px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--clay);
  color: #fff;
  border: none;
  padding: .6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: background .12s var(--ease), transform .08s var(--ease), box-shadow .12s var(--ease);
}
.btn:hover { background: var(--clay-dark); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.secondary:hover { background: var(--paper-raised); border-color: var(--clay); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #7f241f; }
.btn.small { padding: .35rem .7rem; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: default; pointer-events: none; }

.search-bar { position: relative; max-width: 320px; margin-bottom: 1rem; }
.search-bar input {
  width: 100%;
  padding: .55rem .8rem .55rem 2.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .88rem;
  background: var(--paper-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23776b5c' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E") no-repeat .7rem center;
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
.search-bar input:focus { outline: none; border-color: var(--clay); box-shadow: 0 0 0 3px var(--clay-soft); }
.search-count { font-size: .75rem; color: var(--muted); margin-top: .3rem; }

table { width: 100%; border-collapse: collapse; background: var(--paper-raised); }
thead th {
  text-align: left;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 800;
  color: var(--muted);
  border-bottom: 2px solid var(--ink);
  padding: .55rem .65rem;
}
tbody td { padding: .6rem .65rem; border-bottom: 1px solid var(--line); font-size: .91rem; }
tbody tr { transition: background .1s var(--ease); }
tbody tr:hover { background: var(--clay-soft); }
tbody tr[hidden] { display: none; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat { background: var(--paper-raised); border: 1px solid var(--line); border-left: 4px solid var(--clay); padding: 1rem 1.1rem; border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.stat.moss { border-left-color: var(--moss); }
.stat.gold { border-left-color: var(--gold); }
.stat.danger { border-left-color: var(--danger); }
.stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted); margin-bottom: .3rem; }
.stat-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; }

.pill { display: inline-block; padding: .18rem .6rem; border-radius: 999px; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; transition: opacity .15s var(--ease); }
.pill.pendiente { background: #ede0c8; color: #7a5a17; }
.pill.confirmada { background: #dbe6cc; color: var(--moss); }
.pill.entregada { background: #cfe0d6; color: #2d5a3f; }
.pill.cancelada { background: #ecd4d1; color: var(--danger); }
.pill.fijo { background: #e2d9ec; color: #5b3e85; }
.pill.variable { background: #d9e6ee; color: #2a5875; }
.pill.updating { opacity: .5; }

form.stack { display: flex; flex-direction: column; gap: 1.1rem; max-width: 640px; }
.field label { display: block; font-size: .82rem; font-weight: 700; margin-bottom: .35rem; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: .58rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .92rem;
  background: #fff;
  color: var(--ink);
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-soft);
}
.field .hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
.field .error { font-size: .78rem; color: var(--danger); margin-top: .3rem; font-weight: 600; }
.checkline { display: flex; align-items: center; gap: .5rem; }
.checkline input { width: auto; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }

.flash { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; font-size: .9rem; font-weight: 600; box-shadow: var(--shadow-sm); }
.flash.status { background: #dbe6cc; border: 1px solid #a9c187; color: #2f4a1a; }
.flash.error { background: #ecd4d1; border: 1px solid #d19c95; color: var(--danger); }

.line-items { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; background: var(--paper-raised); }
.line-item-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: .5rem; margin-bottom: .5rem; align-items: end; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mt-2 { margin-top: 2rem; }
.empty { padding: 2.5rem; text-align: center; color: var(--muted); }

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ink); }
.login-card { background: var(--paper); padding: 2.5rem; border-radius: var(--radius); width: 100%; max-width: 360px; box-shadow: var(--shadow-md); }
.login-brand { font-size: 1.8rem; font-weight: 800; margin-bottom: .1rem; letter-spacing: -.03em; }
.login-sub { color: var(--muted); font-size: .85rem; margin-bottom: 1.5rem; }

/* Toasts — confirmación en tiempo real sin recargar la página */
.toast-stack { position: fixed; top: 1.25rem; right: 1.25rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--ink);
  color: #fff;
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: toast-in .18s var(--ease);
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.main { transition: opacity .1s var(--ease); }
.main.is-loading { opacity: .55; }
