:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-strong: #f0f4f1;
  --ink: #17201b;
  --muted: #647067;
  --line: #d9e1da;
  --accent: #1f7a5a;
  --accent-dark: #145d44;
  --blue: #2765ad;
  --amber: #a76312;
  --red: #b43f3f;
  --soft-red: #fff0ed;
  --soft-green: #edf8f2;
  --soft-blue: #eef4fb;
  --soft-amber: #fff6e6;
  --shadow: 0 8px 22px rgba(25, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  min-height: 40px;
  padding: 7px 12px;
}

button:hover {
  border-color: #b4c4bb;
  background: #f9fbfa;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.danger {
  border-color: #e1aaa5;
  color: var(--red);
}

button.ghost {
  background: transparent;
}

button.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  text-align: left;
}

button.link-button:hover {
  color: var(--accent);
  background: transparent;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

.login-card p {
  color: var(--muted);
  margin: 0 0 20px;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.reset-box {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.reset-box summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 700;
}

.reset-box form {
  margin-top: 12px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 360px) auto;
  gap: 14px;
  align-items: center;
  padding: 12px clamp(14px, 3vw, 28px);
  background: rgba(246, 247, 244, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 65px);
}

.tabs {
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  background: #fbfcfb;
  min-width: 0;
}

.tab-button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border: 0;
  background: transparent;
  margin-bottom: 4px;
}

.tab-button.active {
  background: var(--panel-strong);
  color: var(--accent-dark);
  font-weight: 700;
}

.content {
  min-width: 0;
  padding: clamp(14px, 3vw, 28px);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(23, 32, 27, 0.28);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 41;
  width: min(620px, 100vw);
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 20px;
  box-shadow: -12px 0 28px rgba(25, 38, 31, 0.16);
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: 24px;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 24px;
}

.metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.chart-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(120px, 2fr) 90px;
  gap: 10px;
  align-items: center;
}

.bar-label,
.bar-value {
  min-width: 0;
  font-size: 13px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-value {
  color: var(--muted);
  text-align: right;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e8eeea;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-fill.danger {
  background: var(--amber);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar .inline-control {
  flex: 0 1 170px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f2f5f2;
  color: #36443b;
  font-size: 13px;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.compact-input {
  max-width: 86px;
}

.tiny-grid {
  gap: 6px;
}

.compliance-table textarea {
  min-width: 180px;
  min-height: 54px;
}

.haccp-day-groups {
  display: grid;
  gap: 14px;
}

.day-group {
  display: grid;
  gap: 8px;
  border-top: 2px solid var(--line);
  padding-top: 10px;
}

.day-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.day-group h4 {
  margin: 0;
  font-size: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.green {
  background: var(--soft-green);
  color: var(--accent-dark);
}

.pill.blue {
  background: var(--soft-blue);
  color: var(--blue);
}

.pill.amber {
  background: var(--soft-amber);
  color: var(--amber);
}

.pill.red {
  background: var(--soft-red);
  color: var(--red);
}

.roles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chemical-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.permission-portal {
  display: grid;
  gap: 10px;
}

.permission-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
}

.permission-group h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.role-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 7px 10px;
  font-weight: 700;
}

.role-tag.selected {
  border-color: #8dc4a5;
  background: var(--soft-green);
  color: var(--accent-dark);
}

.role-tag input {
  width: auto;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.check-row label {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.check-row input {
  width: auto;
}

.check-line {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check-line input {
  width: auto;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(160px, 1fr));
  gap: 10px;
}

.day-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.day-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.day-card small {
  color: var(--muted);
}

.shift-cell {
  display: grid;
  gap: 7px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.shift-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.status-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.status-buttons button {
  min-height: 32px;
  padding: 5px 6px;
  font-size: 12px;
}

.status-buttons button.active[data-status="available"] {
  background: var(--soft-green);
  border-color: #8dc4a5;
  color: var(--accent-dark);
}

.status-buttons button.active[data-status="unavailable"] {
  background: var(--soft-red);
  border-color: #e2a09b;
  color: var(--red);
}

.status-buttons button.active[data-status="preferred"] {
  background: var(--soft-blue);
  border-color: #9abde0;
  color: var(--blue);
}

.status-buttons button.active[data-status="not_preferred"] {
  background: var(--soft-amber);
  border-color: #d7aa5a;
  color: var(--amber);
}

.status-buttons button.active[data-status="empty"] {
  background: #edf0ed;
  border-color: #c9d2cb;
  color: var(--muted);
}

.warning-text {
  color: var(--red);
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.empty-state {
  border: 1px dashed #b7c4bb;
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--muted);
  padding: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  align-items: end;
}

.assignment-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.4fr auto;
  gap: 10px;
  align-items: end;
}

.compact-title {
  margin-bottom: 8px;
}

.compact-title h3 {
  font-size: 16px;
}

.expense-list {
  display: grid;
  gap: 8px;
}

.expense-row {
  display: grid;
  grid-template-columns: 1fr 1.3fr 130px 1fr auto auto;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.incoming-item-list {
  display: grid;
  gap: 10px;
}

.template-mapping-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.template-mapping-row > .muted {
  align-self: center;
}

.template-mapping-row > button {
  align-self: end;
  white-space: nowrap;
}

.incoming-item-row {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
}

.incoming-item-row .danger {
  justify-self: start;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: #17201b;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1020px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: flex;
    max-width: 100vw;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .tab-button {
    width: auto;
    white-space: nowrap;
  }

  .metric-row,
  .grid.two,
  .grid.three,
  .grid.four,
  .calendar-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .inline-form,
  .assignment-form,
  .expense-row,
  .incoming-item-row,
  .template-mapping-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  button {
    min-height: 44px;
  }

  .content {
    padding: 12px;
  }

  .panel {
    padding: 12px;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar button {
    flex: 1 1 140px;
  }

  .toolbar .inline-control {
    flex: 1 1 100%;
  }

  table {
    min-width: 640px;
  }
}
