:root {
  --bg: #eef2f0;
  --surface: #fbfcfb;
  --ink: #15231f;
  --muted: #5f716b;
  --line: #d5e0db;
  --accent: #1b6b54;
  --accent-soft: rgba(27, 107, 84, 0.12);
  --accent-2: #c45c26;
  --danger: #9b2c2c;
  --ok: #1b6b54;
  --sidebar: #10241e;
  --sidebar-2: #16352c;
  --sidebar-text: #d7e6df;
  --sidebar-muted: #8eaaa0;
  --shadow: 0 12px 36px rgba(16, 36, 30, 0.08);
  --radius: 16px;
  --sidebar-w: 268px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body.app-shell {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(27, 107, 84, 0.10), transparent 55%),
    radial-gradient(700px 360px at 0% 100%, rgba(31, 78, 121, 0.07), transparent 50%),
    linear-gradient(180deg, #f4f7f5, var(--bg));
  min-height: 100vh;
  display: flex;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* —— Sidebar —— */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(165deg, rgba(255,255,255,0.04), transparent 40%),
    linear-gradient(180deg, var(--sidebar-2), var(--sidebar));
  color: var(--sidebar-text);
  border-right: 1px solid rgba(255,255,255,0.06);
  z-index: 40;
  animation: sidebarIn 420ms cubic-bezier(.22,1,.36,1) both;
}

@keyframes sidebarIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: none; }
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.25rem 1.1rem 1rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.sidebar-brand:hover { text-decoration: none; }

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 1.45rem;
  background: linear-gradient(145deg, #2f8f72, #1b6b54);
  color: #f4fff9;
  box-shadow: 0 8px 18px rgba(0,0,0,0.22);
  flex: 0 0 auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-text strong {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.brand-text small {
  color: var(--sidebar-muted);
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

.sidebar-close {
  display: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
}

.sidebar-nav {
  flex: 1;
  overflow: auto;
  padding: 0.35rem 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-label {
  margin: 1rem 0.65rem 0.4rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  color: var(--sidebar-text);
  font-weight: 600;
  font-size: 0.94rem;
  text-decoration: none;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}
.nav-link:hover {
  background: rgba(255,255,255,0.07);
  text-decoration: none;
  transform: translateX(2px);
}
.nav-link.active {
  background: linear-gradient(90deg, rgba(47, 143, 114, 0.35), rgba(47, 143, 114, 0.12));
  color: #fff;
  box-shadow: inset 3px 0 0 #3fb58f;
}
.nav-ico {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.06);
  color: #b7d4c8;
  flex: 0 0 auto;
}
.nav-link.active .nav-ico {
  background: rgba(255,255,255,0.14);
  color: #e8fff6;
}

.sidebar-foot {
  padding: 1rem 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: grid;
  gap: 0.75rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2f8f72;
  color: #fff;
  font-weight: 700;
  flex: 0 0 auto;
}
.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.user-meta strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-meta a {
  color: var(--sidebar-muted);
  font-size: 0.78rem;
  font-weight: 600;
}
.user-meta a:hover { color: #fff; }

.logout-btn {
  width: 100%;
  justify-content: center;
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
}
.logout-btn:hover {
  background: rgba(255,255,255,0.08);
  filter: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 16, 0.45);
  backdrop-filter: blur(2px);
  z-index: 30;
}

/* —— Main —— */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  animation: mainIn 480ms cubic-bezier(.22,1,.36,1) both;
}

@keyframes mainIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.mobile-bar {
  display: none;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: rgba(251, 252, 251, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.menu-toggle {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  display: grid;
  place-content: center;
  gap: 5px;
  padding: 0;
  cursor: pointer;
}
.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.mobile-brand {
  font-family: var(--display);
  font-size: 1.3rem;
  color: var(--ink);
  text-decoration: none;
}
.mobile-user {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 2.5rem;
}

h1 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: clamp(1.8rem, 2.4vw, 2.25rem);
  font-weight: 400;
  letter-spacing: 0.01em;
}
.sub { color: var(--muted); margin: 0 0 1.25rem; }

.flash {
  background: #e8f4ef;
  border: 1px solid #b7d9cb;
  color: var(--ok);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  animation: flashIn 280ms ease both;
}
.flash-error {
  background: #fdecec;
  border-color: #e4bcbc;
  color: var(--danger);
}
@keyframes flashIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  box-shadow: var(--shadow);
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.stat:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(16, 36, 30, 0.1);
}
.stat strong {
  display: block;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 400;
  color: var(--accent);
}
.stat span { color: var(--muted); font-size: 0.9rem; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
th, td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tr:last-child td { border-bottom: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.btn, button, .btn-link {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: transform 140ms ease, filter 140ms ease, background 140ms ease;
}
.btn:hover, button:hover {
  filter: brightness(1.06);
  text-decoration: none;
  transform: translateY(-1px);
}
.btn.secondary, button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.warn, button.warn { background: var(--accent-2); }
.btn.danger, button.danger {
  background: transparent;
  color: var(--danger);
  border-color: #e4bcbc;
}
.inline-form { display: inline; margin: 0; }

label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.9rem; }
.field { margin-bottom: 1rem; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  background: white;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #7db8a4;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.35rem; }

.detail-rows { display: grid; gap: 0.75rem; }
.detail-row {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.stock-panel { padding: 0; overflow: auto; }
.stock-table { width: 100%; border-collapse: collapse; }
.stock-table th {
  background: #1f4e79;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.95rem;
  padding: 0.85rem 1rem;
  border-right: 1px solid #9db4c8;
  text-align: left;
}
.stock-table th:last-child { border-right: 0; }
.stock-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d9e2ec;
  border-right: 1px solid #e8eef4;
  font-size: 0.98rem;
}
.stock-table td:last-child { border-right: 0; }
.stock-table td:nth-child(2),
.stock-table td:nth-child(3),
.stock-table td:nth-child(4),
.stock-table th:nth-child(2),
.stock-table th:nth-child(3),
.stock-table th:nth-child(4) {
  text-align: right;
}
.stock-table tbody tr:hover td { background: #f5f9fc; }
.stock-table td.neg { color: var(--danger); font-weight: 700; }
.unit-tag {
  color: #6b7c8a;
  font-size: 0.82rem;
  font-weight: 600;
  margin-left: 0.25rem;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(27, 107, 84, 0.16), transparent 42%),
    linear-gradient(180deg, #f4f7f5, var(--bg));
}
.login-wrap { width: 100%; max-width: 420px; animation: mainIn 480ms ease both; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 1.85rem;
}
.login-brand {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.7rem;
  color: var(--accent);
  margin-bottom: 0.55rem;
}
.login-card h1 {
  margin: 0 0 0.25rem;
  font-family: var(--font);
  font-size: 1.35rem;
  font-weight: 700;
}
.login-btn { width: 100%; justify-content: center; padding: 0.75rem 1rem; border-radius: 12px; }

@media (max-width: 920px) {
  body.app-shell { display: block; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-105%);
    transition: transform 280ms cubic-bezier(.22,1,.36,1);
    animation: none;
    box-shadow: 12px 0 40px rgba(0,0,0,0.25);
  }
  body.sidebar-open .sidebar { transform: none; }
  .sidebar-close { display: grid; place-items: center; }
  .mobile-bar { display: flex; }
  .main-area { min-height: 100vh; }
}

@media (max-width: 720px) {
  .grid-2, .detail-row { grid-template-columns: 1fr; }
  .wrap { padding: 1.15rem 1rem 2rem; }
}
