:root {
  --bg: #f3eee4;
  --bg-deep: #e7dfd0;
  --ink: #1c1914;
  --muted: #6b645a;
  --panel: rgba(255, 252, 246, 0.86);
  --line: rgba(28, 25, 20, 0.1);
  --accent: #c45c26;
  --accent-2: #1f6f5b;
  --warn: #b7791f;
  --danger: #a33b2d;
  --info: #2f5d8c;
  --ok: #1f6f5b;
  --shadow: 0 18px 50px rgba(45, 32, 18, 0.08);
  --radius: 18px;
  --sidebar: 280px;
  --font: "Manrope", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at -10% -20%, #f7d9b8 0%, transparent 55%),
    radial-gradient(900px 500px at 110% 0%, #cfe3d8 0%, transparent 50%),
    linear-gradient(160deg, #f7f2e8, #ebe3d4 45%, #e4dccb);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  padding: 1.4rem 1.1rem;
  background: linear-gradient(180deg, #241f19 0%, #1a1713 100%);
  color: #f6efe4;
  display: flex; flex-direction: column; gap: 1.2rem;
}
.brand { display: flex; gap: .85rem; align-items: center; padding: .4rem .5rem 1rem; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #e07a3d, #c45c26);
  font-family: var(--display); font-weight: 700; font-size: .95rem;
  letter-spacing: -.04em;
}
.brand strong { display: block; font-size: 1.05rem; }
.brand small, .side-user small, .muted { color: var(--muted); }
.side-nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.side-nav a {
  padding: .75rem .9rem; border-radius: 12px; color: #d9d0c3;
  transition: .2s ease;
}
.side-nav a:hover, .side-nav a.active {
  background: rgba(255,255,255,.08); color: #fff;
}
.side-user {
  display: flex; justify-content: space-between; align-items: center;
  gap: .75rem; padding: .9rem; border-radius: 14px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08);
}
.side-user strong { display: block; font-size: .92rem; }
.side-user small { color: #b7ae9f; }

.main { padding: 1.4rem 1.6rem 2.5rem; }
.topbar {
  display: flex; justify-content: space-between; align-items: end;
  gap: 1rem; margin-bottom: 1.2rem;
}
.topbar h1 {
  margin: 0; font-family: var(--display); font-weight: 700;
  font-size: clamp(1.6rem, 2.4vw, 2.2rem); letter-spacing: -.02em;
}
.topbar-meta {
  padding: .45rem .8rem; border-radius: 999px;
  background: rgba(255,255,255,.55); border: 1px solid var(--line);
  color: var(--muted); font-size: .88rem;
}

.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.stat { padding: 1.1rem 1.2rem; }
.stat span { display: block; color: var(--muted); font-size: .86rem; margin-bottom: .35rem; }
.stat strong { font-size: 1.55rem; letter-spacing: -.02em; }
.stat.accent strong { color: var(--accent); }
.stat.ok strong { color: var(--ok); }
.stat.warn strong { color: var(--warn); }

.panel { padding: 1.15rem 1.2rem; }
.panel h2, .panel h3 { margin: 0 0 1rem; font-family: var(--display); font-size: 1.2rem; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-bottom: 1rem;
}
.panel-head h2, .panel-head h3 { margin: 0; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: .75rem .55rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
tr:hover td { background: rgba(255,255,255,.35); }

.badge {
  display: inline-flex; align-items: center; padding: .25rem .55rem;
  border-radius: 999px; font-size: .75rem; font-weight: 700; text-transform: capitalize;
}
.badge-ok { background: #d9f0e7; color: #145544; }
.badge-warn { background: #f8e7c4; color: #7a4d0d; }
.badge-info { background: #d8e7f7; color: #1d446b; }
.badge-danger { background: #f5d7d2; color: #7a241a; }
.badge-muted { background: #ece7de; color: #5b554c; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 0; border-radius: 12px; padding: .7rem 1rem; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700;
  transition: transform .15s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-secondary { background: #2b2620; }
.btn-ghost {
  background: transparent; color: inherit; border: 1px solid currentColor; opacity: .9;
}
.btn-sm { padding: .4rem .7rem; border-radius: 10px; font-size: .85rem; }
.btn-ok { background: var(--accent-2); }
.btn-danger { background: var(--danger); }

.form-grid { display: grid; gap: .9rem; grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: .35rem; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem .8rem; background: #fffdf8; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .4rem; }

.alert {
  margin-bottom: 1rem; padding: .85rem 1rem; border-radius: 14px;
  border: 1px solid var(--line); background: #fff;
}
.alert-success { background: #e7f6ef; border-color: #b7e0cf; }
.alert-error { background: #fbeaea; border-color: #efc4bd; }
.alert-info { background: #eaf2fb; border-color: #c5d8ef; }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    linear-gradient(120deg, rgba(28,25,20,.55), rgba(28,25,20,.25)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23c45c26' stroke-opacity='.12'%3E%3Cpath d='M0 80h160M80 0v160'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(145deg, #2a2219, #4a3424 40%, #8a4e2a);
}
.login-card {
  width: min(420px, 100%);
  padding: 2rem 1.6rem;
  border-radius: 24px;
  background: rgba(255,250,243,.94);
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
}
.login-card h1 {
  margin: 0 0 .35rem; font-family: var(--display); font-size: 2rem;
}
.login-card p { margin: 0 0 1.4rem; color: var(--muted); }
.login-card .stack { display: grid; gap: .9rem; }
.login-hint {
  margin-top: 1.1rem; padding: .85rem; border-radius: 12px;
  background: #f3ebe0; color: var(--muted); font-size: .82rem;
}

.empty {
  padding: 1.4rem; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 14px;
}

.qty-input { max-width: 110px; }
.split { display: flex; gap: 1rem; align-items: start; }
.split > * { flex: 1; }

.stat small { display: block; margin-top: .35rem; font-size: .78rem; font-weight: 500; }
.panel-full { width: 100%; }
.table-wide { min-width: 980px; }
tr.row-active td { background: rgba(196, 92, 38, .08); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 1rem;
  background: rgba(28, 25, 20, .48);
  backdrop-filter: blur(4px);
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  width: min(560px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  padding: 1.2rem 1.25rem 1.35rem;
  border-radius: 20px;
  background: #fffdf8;
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(28, 25, 20, .28);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-bottom: 1rem;
}
.modal-head h2 { margin: 0; font-family: var(--display); font-size: 1.35rem; }
body.modal-open { overflow: hidden; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .grid-4, .grid-3, .grid-2, .form-grid, .split { grid-template-columns: 1fr; display: grid; }
}
