:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel-2: #f8f4ea;
  --text: #252525;
  --muted: #6e6a61;
  --line: #ded7c8;
  --primary: #2d5a4a;
  --primary-2: #24483c;
  --accent: #b86b31;
  --danger: #b84b45;
  --warning: #bd8a28;
  --shadow: 0 18px 40px rgba(30, 27, 22, .09);
  --radius: 18px;
  --sidebar-w: 276px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #fbf7ef 0, var(--bg) 44%, #eee6d7 100%);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
code { background: #eee5d7; padding: 1px 5px; border-radius: 6px; }
[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid rgba(141, 128, 101, .24);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.login-logo {
  width: 80%;
  height: auto;
  display: block;
  object-fit: contain;
  object-position: center;
  margin: 0 auto -8px;
}
.login-eyebrow { margin-top: 0; }
.login-card h1 { font-size: 30px; }
.login-form { display: grid; gap: 15px; margin-top: 24px; }
.login-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 750; }
.login-form .btn { margin-top: 4px; }
.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 11px;
  background: #f2d7d2;
  color: #94342d;
  font-size: 13px;
}

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: #262b28;
  color: #f8f4ea;
  padding: 24px 18px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 7px 7px 22px;
}
.brand-logo {
  width: 140px !important;
  height: 140px !important;
  max-width: 140px;
  max-height: 140px;
  border-radius: 16px;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.brand-copy { min-width: 0; }
.brand strong { display: block; font-size: 18px; line-height: 1.25; }
.brand small { display: block; color: #c9c2b6; margin-top: 2px; }

.nav { display: grid; gap: 7px; margin-top: 10px; }
.nav-item {
  border: 0;
  width: 100%;
  text-align: left;
  border-radius: 13px;
  background: transparent;
  color: #e9e1d6;
  padding: 12px 13px;
}
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: #f4f1ea; color: #1f2a25; font-weight: 700; }
.sidebar-note {
  margin-top: 28px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 16px;
  background: rgba(255,255,255,.06);
}
.sidebar-note span, .sidebar-note small { color: #c9c2b6; display: block; }
.sidebar-note strong { display: block; margin: 4px 0 8px; }
.sidebar-note code { color: #252525; }

.main { margin-left: var(--sidebar-w); width: calc(100% - var(--sidebar-w)); padding: 28px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
.eyebrow { margin: 0 0 6px; color: var(--accent); text-transform: uppercase; font-weight: 800; font-size: 12px; letter-spacing: .09em; }
h1 { margin: 0; font-size: clamp(26px, 3vw, 38px); line-height: 1.1; }
h2 { margin: 0; font-size: 18px; }
h3 { margin: 24px 0 12px; }
p { color: var(--muted); margin: 6px 0 0; }
.top-actions, .inline-actions, .form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.user-session {
  display: grid;
  min-width: 110px;
  padding-right: 4px;
  text-align: right;
}
.user-session strong { font-size: 13px; }
.user-session small { color: var(--muted); text-transform: capitalize; }
.month-picker { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.month-picker input, .search, input, select, textarea {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
.month-picker input:focus, .search:focus, input:focus, select:focus, textarea:focus { border-color: #879e8e; box-shadow: 0 0 0 3px rgba(45,90,74,.12); }

.btn {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 750;
  box-shadow: 0 5px 14px rgba(30,27,22,.04);
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--danger); }
.icon-btn { border: 0; background: transparent; font-size: 32px; line-height: 1; color: var(--muted); }

.view { display: none; }
.view.active { display: block; }
.grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.two-col { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-bottom: 18px; }
.compact-top { align-items: start; }
.panel, .stat-card {
  background: var(--panel);
  border: 1px solid rgba(141, 128, 101, .24);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 20px; }
.soft-panel { background: #f7efe2; }
.stat-card { padding: 18px; }
.stat-card span { display: block; color: var(--muted); font-weight: 700; font-size: 13px; }
.stat-card strong { display: block; font-size: 25px; margin: 8px 0 3px; letter-spacing: -.02em; }
.stat-card small { color: var(--muted); }
.panel-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 7px 10px; font-weight: 800; font-size: 12px; background: #e9eee7; color: #2d5a4a; white-space: nowrap; }
.pill.warn { background: #f5e3bd; color: #7c5510; }
.pill.danger { background: #f2d7d2; color: #94342d; }
.pill.ok { background: #dcebdd; color: #255834; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: #756e62; text-transform: uppercase; letter-spacing: .04em; padding: 12px; border-bottom: 1px solid var(--line); }
td { padding: 13px 12px; border-bottom: 1px solid #ebe4d7; vertical-align: top; }
tr:hover td { background: #fffaf1; }
.right { text-align: right; }
.muted { color: var(--muted); }
.stack { display: grid; gap: 10px; }
.empty-state { color: var(--muted); background: var(--panel-2); padding: 14px; border-radius: 14px; border: 1px dashed var(--line); }
.alert-line, .stock-line {
  padding: 12px;
  border-radius: 14px;
  background: #fff8eb;
  border: 1px solid #ead8b7;
}
.alert-line strong, .stock-line strong { display: block; margin-bottom: 2px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tiny-btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 9px; font-weight: 700; }
.status-list { display: flex; gap: 5px; flex-wrap: wrap; }
.status-tag { font-size: 11px; border-radius: 999px; padding: 4px 7px; background: #e7ece4; color: #315848; font-weight: 800; }
.status-tag.warning { background: #f3e1ba; color: #745114; }
.status-tag.danger { background: #efd1cc; color: #8e2e29; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label { display: grid; gap: 6px; font-weight: 750; color: #403b33; font-size: 13px; }
.form-grid label small { color: var(--muted); font-weight: 500; }
.form-grid .full, .full { grid-column: 1 / -1; }
.check-label { display: flex !important; align-items: center; gap: 8px !important; align-self: end; }
.check-label input { width: auto; }
.form-actions { justify-content: flex-end; margin-top: 8px; }
.mini-checklist { display: grid; gap: 9px; margin-top: 16px; }
.mini-checklist span { background: #fff9ef; border: 1px solid #eadfcb; border-radius: 13px; padding: 11px 12px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 27, 23, .48);
  display: grid;
  place-items: center;
  padding: 22px;
  z-index: 20;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(940px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.22);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; margin-bottom: 16px; }
.assistant-box {
  background: #eff4ee;
  border: 1px solid #d7e1d3;
  color: #324b3d;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
}

.report-paper { background: #fff; }
.report-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #292929; padding-bottom: 18px; margin-bottom: 18px; }
.report-brand { display: flex; align-items: center; gap: 14px; }
.report-logo {
  width: 48px !important;
  height: 48px !important;
  max-width: 48px;
  max-height: 48px;
  border-radius: 10px;
  flex: 0 0 auto;
  object-fit: contain;
}
.report-period { font-weight: 900; font-size: 18px; color: var(--primary); }
.report-sign { display: flex; justify-content: space-between; gap: 30px; margin-top: 36px; color: #555; }
.report-actions { margin: 16px 0 0; }
.sop-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.sop-card { padding: 16px; border-radius: 16px; background: #fffaf1; border: 1px solid #eadfcb; }
.sop-card h3 { margin: 0 0 6px; }
.sop-card ul { margin: 14px 0 0; padding-left: 19px; color: #403b33; }
.sop-card li { margin-bottom: 8px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #262b28;
  color: #fff;
  border-radius: 14px;
  padding: 13px 16px;
  box-shadow: 0 18px 45px rgba(0,0,0,.18);
  z-index: 40;
}
.toast[hidden] { display: none; }

@media (max-width: 980px) {
  .sidebar { position: static; width: 100%; border-radius: 0 0 22px 22px; }
  .app-shell { display: block; }
  .main { margin-left: 0; width: 100%; padding: 18px; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid, .two-col, .sop-list { grid-template-columns: 1fr; }
  .topbar, .panel-head, .report-head { flex-direction: column; }
  .top-actions { width: 100%; }
  .top-actions .btn, .month-picker, .month-picker input { width: 100%; }
}

@media (max-width: 620px) {
  .form-grid, .form-grid.wide { grid-template-columns: 1fr; }
  .sidebar { padding: 18px 14px; }
  .modal { padding: 16px; }
  .inline-actions { width: 100%; }
  .inline-actions .search, .inline-actions .btn { width: 100%; }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .report-actions, .nav, .toast { display: none !important; }
  .main { margin: 0; width: 100%; padding: 0; }
  .view { display: none !important; }
  #view-reports { display: block !important; }
  .panel, .stat-card { box-shadow: none; border-color: #aaa; }
}
