*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── LOGIN ─────────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
}

.login-box h1 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#login-form label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
}

#login-form input {
  padding: 0.6rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

#login-form input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

.field-error {
  color: #dc2626;
  font-size: 0.8rem;
  min-height: 1em;
}

/* ── LAYOUT ────────────────────────────────────────────────────────────────── */
#dashboard {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: #1a1a2e;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
}

.sidebar-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid #374151;
  margin-bottom: 0.75rem;
}

nav { flex: 1; }

.nav-item {
  display: block;
  padding: 0.65rem 1.25rem;
  color: #d1d5db;
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s;
}

.nav-item:hover  { background: #374151; color: #fff; }
.nav-item.active { background: #312e81; color: #fff; border-left-color: #818cf8; }

.btn-logout {
  margin: 1rem;
  padding: 0.5rem;
  background: transparent;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #9ca3af;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.1s;
}

.btn-logout:hover { background: #374151; color: #fff; }

/* ── CONTENT ───────────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 2rem;
  overflow-x: hidden;
}

/* ── STATS BAR ─────────────────────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (max-width: 1100px) {
  .stats-bar { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 700px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: #4f46e5;
  line-height: 1;
}

.stat-label {
  font-size: 0.8rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── VIEW HEADER ───────────────────────────────────────────────────────────── */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.view-header h2 {
  font-size: 1.25rem;
}

.view-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.view-actions input {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  width: 240px;
}

.view-actions input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

/* ── BUTTONS ───────────────────────────────────────────────────────────────── */
.btn-primary {
  background: #4f46e5;
  color: #fff;
  border: none;
  padding: 0.65rem 1.5rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: #4338ca; }

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: #e5e7eb; }

.btn-danger {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover { background: #ffe4e6; }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* ── ADD CODE FORM ─────────────────────────────────────────────────────────── */
.add-code-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.add-code-form input {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
}

.add-code-form input[type="text"]   { width: 180px; }
.add-code-form input[type="number"] { width: 100px; }

.add-code-form input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

/* ── TABLES ────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: #f9fafb;
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
thead th.sortable:hover { background: #f3f4f6; }
thead th.sort-asc::after  { content: ' ▲'; font-size: 0.7em; color: #6b7280; }
thead th.sort-desc::after { content: ' ▼'; font-size: 0.7em; color: #6b7280; }

tbody td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f9fafb; }

.empty {
  text-align: center;
  color: #9ca3af;
  padding: 2.5rem !important;
}

/* ── BADGES ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-yes  { background: #dcfce7; color: #15803d; }
.badge-no   { background: #f3f4f6; color: #6b7280; }
.badge-code { background: #ede9fe; color: #6d28d9; font-family: monospace; }

/* ── PROGRESS BAR ──────────────────────────────────────────────────────────── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 120px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #4f46e5;
  border-radius: 999px;
  transition: width 0.3s;
}

.progress-fill.full { background: #dc2626; }

.progress-label {
  font-size: 0.75rem;
  color: #6b7280;
  white-space: nowrap;
}

/* ── TYPE PILL ─────────────────────────────────────────────────────────────── */
.type-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.badge-hint {
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 0.75rem;
  min-height: 1.2em;
}

/* ── INLINE QTY EDIT ───────────────────────────────────────────────────────── */
.qty-input {
  width: 70px;
  padding: 0.3rem 0.4rem;
  border: 1px solid #4f46e5;
  border-radius: 4px;
  font-size: 0.875rem;
  text-align: center;
}

.qty-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(79,70,229,0.2);
}

/* ── NEWSLETTER EDIT MODAL ──────────────────────────────────────────────────── */
.nl-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.nl-modal {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  width: 100%; max-width: 360px;
  margin: 1rem;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.nl-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}
.nl-modal-header h3 { font-size: 1rem; font-weight: 700; }
.nl-modal-close {
  background: none; border: none; color: #9ca3af;
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0;
}
.nl-modal-close:hover { color: #111; }

.nl-modal-body {
  padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}

.nl-modal-body .edit-field { display: flex; flex-direction: column; gap: 0.3rem; }
.nl-modal-body .edit-field label { font-size: 0.78rem; font-weight: 600; color: #6b7280; }
.nl-modal-body .edit-field input {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #111;
}
.nl-modal-body .edit-field input:focus {
  outline: none; border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

.nl-modal-footer {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid #e5e7eb;
}

/* ── FAIR SELECTOR ──────────────────────────────────────────────────────────── */
#fair-selector {
  min-height: 100vh;
  background: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.fair-selector-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  width: 100%;
  max-width: 860px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.fair-selector-header {
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid #f3f4f6;
}
.fair-selector-header h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.3rem; }
.fair-selector-header p  { font-size: 0.875rem; color: #6b7280; }

.fair-selector-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 360px;
}

.fair-col {
  padding: 1.25rem 1.5rem;
  border-right: 1px solid #f3f4f6;
}
.fair-col:last-child { border-right: none; }

.fair-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.fair-col-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fair-list { display: flex; flex-direction: column; gap: 0.4rem; }

.fair-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.fair-item:hover        { background: #f9fafb; border-color: #d1d5db; }
.fair-item.selected     { background: #eef2ff; border-color: #a5b4fc; }

.fair-item-main  { flex: 1; min-width: 0; }
.fair-item-name  { font-size: 0.9rem; font-weight: 600; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fair-item-meta  { font-size: 0.78rem; color: #9ca3af; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.fair-item-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; margin-left: 0.5rem; }
.btn-delete-fair-selector { font-size: 0.75rem; padding: 0.25rem 0.45rem; }

.fair-empty { font-size: 0.85rem; color: #9ca3af; padding: 0.5rem 0; }
.fair-err   { font-size: 0.8rem;  color: #ef4444;  display: block; margin-top: 0.25rem; }

.fair-inline-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.fair-inline-form input,
.fair-inline-form select {
  padding: 0.45rem 0.65rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  width: 100%;
}
.fair-inline-form .btn-sm { align-self: flex-start; }

.fair-selector-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #f3f4f6;
  display: flex;
  justify-content: flex-end;
}

/* ── ACTIVE FAIR BAR (sidebar) ───────────────────────────────────────────────── */
.active-fair-bar {
  margin: 0 0 0.5rem;
  padding: 0.6rem 0.85rem;
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.active-fair-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-switch-fair {
  flex-shrink: 0;
  padding: 2px 8px;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-switch-fair:hover { background: rgba(255,255,255,0.25); }

.nav-item-settings {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 0.5rem;
}

/* ── FAIR SETTINGS VIEW ─────────────────────────────────────────────────────── */
.fair-settings-form { max-width: 680px; padding: 0.5rem 0 2rem; }

.fs-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #f3f4f6;
}
.fs-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.fs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.fs-field { display: flex; flex-direction: column; gap: 0.3rem; }
.fs-field span { font-size: 0.8rem; font-weight: 500; color: #4b5563; }
.fs-field input, .fs-field textarea {
  padding: 0.5rem 0.7rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
}
.fs-field-wide { grid-column: 1 / -1; }

.color-input-wrap { display: flex; gap: 0.5rem; align-items: center; }
.color-input-wrap input[type="color"] { width: 42px; height: 36px; padding: 2px; border: 1px solid #d1d5db; border-radius: 6px; cursor: pointer; }
.color-input-wrap input[type="text"]  { flex: 1; }

.fs-logo-section { margin-top: 1rem; }
.fs-label        { font-size: 0.8rem; font-weight: 500; color: #4b5563; display: block; margin-bottom: 0.5rem; }
.fs-logo-row     { display: flex; align-items: center; gap: 1rem; }
.fs-logo-preview {
  width: 120px; height: 60px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: #f9fafb; overflow: hidden; flex-shrink: 0;
}
.fs-logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.fs-logo-none    { font-size: 0.78rem; color: #9ca3af; }
.fs-logo-actions { display: flex; gap: 0.5rem; }

.fs-types { display: flex; gap: 1.5rem; }
.fs-type-check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; cursor: pointer; }
.fs-type-check input { width: 16px; height: 16px; cursor: pointer; }

.fs-actions { display: flex; align-items: center; gap: 1rem; margin-top: 0.5rem; }
.fs-status  { font-size: 0.85rem; color: #16a34a; }

.fs-danger-section { border-color: #fee2e2; }
.fs-danger-section h3 { color: #dc2626; }
.fs-danger-desc { font-size: 0.85rem; color: #6b7280; margin-bottom: 0.75rem; }
