:root {
  --bg: #f6f1ea;
  --card-bg: #ffffff;
  --text: #2b2320;
  --muted: #6b5f53;
  --border: #e6ddd0;
  --primary: #8a5a34;
  --primary-dark: #6f4527;
  --primary-contrast: #ffffff;
  --success: #2f7d4f;
  --success-bg: #e7f5ec;
  --danger: #c0392b;
  --danger-bg: #fbeae7;
  --warning: #b8860b;
  --warning-bg: #fdf3d9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1815;
    --card-bg: #26211c;
    --text: #f1ebe3;
    --muted: #a99c8c;
    --border: #3a322b;
    --primary: #c98a52;
    --primary-dark: #e0a066;
    --primary-contrast: #201a14;
    --success: #6fce93;
    --success-bg: #1c3327;
    --danger: #f0796a;
    --danger-bg: #3a201c;
    --warning: #e0b84a;
    --warning-bg: #3a3018;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Heebo", Arial, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 90px;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  right: 10px;
  top: -60px;
  background: var(--primary);
  color: var(--primary-contrast);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 200;
  transition: top 0.15s ease;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 10px;
}

a,
button,
input,
[tabindex] {
  outline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

.center-screen {
  min-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h1 {
  font-size: 1.35rem;
  margin: 0 0 6px;
}

.card p.subtitle {
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 0.95rem;
}

label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 14px 0 6px;
}

label:first-of-type {
  margin-top: 0;
}

input[type="text"],
input[type="tel"],
input[type="number"],
input[type="password"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 1rem;
  font-weight: 600;
  margin-top: 18px;
}

.btn:active {
  background: var(--primary-dark);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  width: auto;
  padding: 8px 14px;
  font-size: 0.9rem;
  margin-top: 0;
}

.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-top: 14px;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 6px;
}

/* Header / summary bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 10px 0 8px;
  margin-bottom: 4px;
}

.dept-name-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dept-name-row h2 {
  margin: 0;
  font-size: 1.1rem;
}

.dept-name-row .employees {
  color: var(--muted);
  font-size: 0.82rem;
}

.budget-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.budget-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}

.budget-item .label {
  color: var(--muted);
  font-size: 0.78rem;
}

.budget-item .value {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 2px;
}

.budget-item.warn .value {
  color: var(--danger);
}

.budget-warning {
  margin-top: 10px;
  background: var(--warning-bg);
  color: var(--warning);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Tabs */

.tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.tab-btn {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight: 600;
  color: var(--muted);
}

.tab-btn.active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

/* Product list */

.product-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.product-info {
  min-width: 0;
  flex: 1;
}

.product-info .name {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.product-info .meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.qty-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.qty-btn:active {
  background: var(--border);
}

.qty-input {
  width: 46px;
  text-align: center;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

/* Cart */

.cart-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.cart-row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.cart-row .name {
  font-weight: 700;
}

.cart-row .meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 3px;
}

.cart-row .line-total {
  font-weight: 700;
  white-space: nowrap;
}

.cart-summary {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 6px;
}

.cart-summary .total-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.15rem;
  font-weight: 700;
  padding-top: 6px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 12px;
}

/* Notifications toast */

.toast-stack {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 50;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--success-bg);
  color: var(--success);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.toast button {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
}

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90vh;
  color: var(--muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 4px;
}

/* Admin specific */

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.admin-header h1 {
  font-size: 1.2rem;
  margin: 0;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 22px 0 10px;
}

.dept-admin-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.dept-admin-row .top {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.dept-admin-row .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 6px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge.over {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.ok {
  background: var(--success-bg);
  color: var(--success);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.action-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.action-card h2 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.action-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal-sheet {
  background: var(--card-bg);
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: var(--radius);
  }
}

.modal-sheet h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

table.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 8px;
}

table.report-table th,
table.report-table td {
  text-align: right;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
}

table.report-table th {
  color: var(--muted);
  font-weight: 600;
}

.tag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.tag-row:last-child {
  border-bottom: none;
}

.close-x {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  line-height: 1;
}

.stack-buttons {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.stack-buttons .btn {
  margin-top: 0;
}
