:root {
  --primary: #2f7d4f;
  --primary-dark: #235e3b;
  --bg: #f7f7f6;
  --surface: #ffffff;
  --border: #d9d9d4;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --danger: #b03030;
  --ok: #2f7d4f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary-dark); }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
p { margin: 6px 0 12px; }
.muted { color: var(--muted); }

.topbar {
  background: #1f1f1f;
  color: white;
  padding: 10px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar a { color: white; text-decoration: none; margin-right: 10px; font-weight: 500; }
.topbar a:hover { text-decoration: underline; }
.topbar .brand { font-weight: 700; margin-right: auto; }
.user-chip { background: #444; padding: 3px 8px; border-radius: 4px; font-size: 12px; }
.topbar nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar nav form button { background: none; border: 1px solid #666; color: white; padding: 3px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }

.main { max-width: 1200px; margin: 0 auto; padding: 18px 20px 40px; }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--primary-dark); text-decoration: none; font-size: 14px; font-weight: 500; margin: 0 0 14px; padding: 6px 12px; border-radius: 4px; background: #eef3ef; border: 1px solid #d1e0d4; }
.back-link:hover { background: #dfe9e1; text-decoration: none; }
.back-link::before { content: "← "; font-size: 16px; font-weight: 700; }

form label { display: block; margin: 10px 0; font-weight: 500; }
form input, form textarea, form select {
  width: 100%;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  margin-top: 3px;
}
form label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
form label.checkbox input { width: auto; margin-top: 0; }

button, .button {
  display: inline-block;
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  font: inherit;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
button.primary:hover, .button.primary:hover { background: var(--primary-dark); }
button.link { background: none; border: none; color: var(--danger); padding: 0 4px; cursor: pointer; }
form.inline { display: inline-block; margin: 0; }
.inline-form { display: inline-flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.inline-form input, .inline-form select { width: auto; }

.flash-error { background: #f6d6d6; color: var(--danger); padding: 8px 12px; border-radius: 4px; margin-bottom: 12px; }
.flash-ok { background: #d6efde; color: var(--ok); padding: 8px 12px; border-radius: 4px; margin-bottom: 12px; }
.flash-warn { background: #fdf1c6; color: #7a5d00; padding: 8px 12px; border-radius: 4px; margin-bottom: 12px; }

.login-card {
  max-width: 380px;
  margin: 60px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: 8px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { font-size: 22px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 14px 18px; margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 16px; margin-bottom: 6px; }

.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.data-table th, .data-table td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table thead th { background: #efefec; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tfoot th { background: #fafaf8; }
.data-table tr.muted td { color: var(--muted); }

.badge { display: inline-block; padding: 2px 7px; border-radius: 12px; font-size: 11px; font-weight: 600; background: #ddd; }
.badge-draft { background: #eee; color: #555; }
.badge-open { background: #d6efde; color: #2f7d4f; }
.badge-closed { background: #fde3c4; color: #8a5200; }
.badge-ordered { background: #cfe0f5; color: #1a4a84; }
.badge-submitted { background: #d6efde; color: #2f7d4f; }
.badge-pending { background: #f0e2cf; color: #80551d; }
.badge-in-production { background: #d5e2f5; color: #2c4a78; }
.badge-shipped { background: #e0d4f4; color: #513a8a; }
.badge-received { background: #d6efde; color: #2f7d4f; }

.timeline { list-style: none; padding: 0; margin: 10px 0; border-left: 2px solid var(--border); }
.timeline li { padding: 6px 0 6px 14px; margin-left: 6px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }

.pw-wrap { position: relative; display: block; }
.pw-wrap input[type="password"], .pw-wrap input[type="text"] { padding-right: 62px; width: 100%; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  padding: 3px 10px; font-size: 12px; font-weight: 500;
  background: #eee; color: #333; border: 1px solid var(--border); border-radius: 4px; cursor: pointer;
}
.pw-toggle:hover { background: #e0e0e0; }

.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

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

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 4px; margin: 10px 0; }

.size-price-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.size-chip { display: inline-flex; gap: 4px; background: #eef3ef; color: #235e3b; border: 1px solid #d1e0d4; padding: 2px 7px; border-radius: 10px; font-size: 11px; white-space: nowrap; }
.size-chip-override { background: #fff4d6; color: #8a5200; border-color: #f0dca0; }
.size-chip strong { font-weight: 700; }

.size-price-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; padding: 8px 12px 10px; margin: 10px 0; border: 1px solid var(--border); border-radius: 4px; background: #fafaf8; }
.size-price-grid legend { font-weight: 500; padding: 0 6px; font-size: 13px; }
.size-price-cell { display: flex; flex-direction: column; gap: 2px; margin: 0; font-weight: 400; }
.size-price-cell .size-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; text-align: center; }
.size-price-cell input { width: 100%; text-align: right; padding: 4px 6px; margin-top: 0; }

/* Order form matrix */
.garment-block { background: var(--surface); border: 1px solid var(--border); padding: 14px; border-radius: 6px; margin-bottom: 16px; }
.garment-row { display: flex; gap: 18px; align-items: flex-start; }
.garment-image { width: 120px; height: 120px; object-fit: contain; background: #fafaf8; border: 1px solid var(--border); border-radius: 4px; flex-shrink: 0; }
.garment-thumb { width: 60px; height: 60px; object-fit: contain; background: #fafaf8; border: 1px solid var(--border); border-radius: 4px; display: block; }
.garment-info { flex: 1; min-width: 0; }
.garment-info h2 { margin-top: 0; }
@media (max-width: 640px) {
  .garment-row { flex-direction: column; }
  .garment-image { width: 100%; max-width: 200px; height: auto; }
}
.matrix { border-collapse: collapse; margin-top: 6px; }
.matrix th, .matrix td { border: 1px solid var(--border); padding: 5px; vertical-align: middle; }
.order-total { color: var(--primary-dark); font-size: 16px; }
.matrix thead th { background: #efefec; font-size: 12px; min-width: 60px; line-height: 1.3; }
.matrix .size-price { display: inline-block; margin-top: 2px; font-size: 11px; font-weight: 500; color: var(--primary-dark); }
.matrix td { text-align: center; background: #fafaf8; }
.cell-label { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.cell-input { width: 52px; padding: 2px 4px; text-align: right; font-size: 13px; }
.cell-input-order { border-color: var(--primary); background: #f3fbf6; }
.order-form .toolbar { margin-top: 20px; }
