/* =====================
   Reset & Base
   ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:      #1a56db;
  --blue-dark: #1240a8;
  --blue-light:#e8eefb;
  --red:       #e02424;
  --green:     #057a55;
  --green-light:#def7ec;
  --yellow-light:#fdf6b2;
  --gray-50:   #f9fafb;
  --gray-100:  #f3f4f6;
  --gray-200:  #e5e7eb;
  --gray-400:  #9ca3af;
  --gray-600:  #4b5563;
  --gray-800:  #1f2937;
  --sidebar-w: 220px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body { font-family: var(--font); font-size: 14px; color: var(--gray-800); background: var(--gray-50); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* =====================
   Layout
   ===================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-800);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand h2 { font-size: 14px; font-weight: 700; color: #fff; letter-spacing: 0.03em; }
.sidebar-brand p  { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

.sidebar-user {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--gray-400);
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #d1d5db;
  font-size: 13px;
  transition: background 0.15s;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar nav a .nav-icon { width: 16px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
}
.sidebar-footer button {
  background: none; border: none; color: var(--gray-400); cursor: pointer;
  font-size: 13px; padding: 0;
}
.sidebar-footer button:hover { color: #fff; }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
}

/* =====================
   Page Header
   ===================== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 22px; font-weight: 700; color: var(--gray-800); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.back-link { font-size: 13px; color: var(--gray-600); display: block; margin-bottom: 4px; }
.back-link:hover { color: var(--blue); }

/* =====================
   Stats Grid
   ===================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 18px 20px;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--blue); line-height: 1; }
.stat-label { font-size: 12px; color: var(--gray-600); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.04em; }

/* =====================
   Buttons
   ===================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer; transition: background 0.15s, border-color 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn-primary   { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--gray-800); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-100); }
.btn-danger    { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #c81e1e; }
.btn-ghost     { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-large     { padding: 11px 24px; font-size: 15px; }
.btn-full      { width: 100%; justify-content: center; }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }

/* =====================
   Tables
   ===================== */
.section-header { margin-bottom: 12px; }
.section-header h3 { font-size: 16px; font-weight: 600; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}
.table th {
  background: var(--gray-50);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }
.table-sm td, .table-sm th { padding: 7px 12px; }
.table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.sortable:hover { color: var(--blue); background: var(--blue-light); }
.table th.sort-active { color: var(--blue); }
.table th .sort-icon { font-size: 11px; }

.count-label { font-size: 13px; color: var(--gray-600); margin-bottom: 10px; }

/* =====================
   Forms
   ===================== */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 500; color: var(--gray-700, #374151); }
.field.required label::after { content: ' *'; color: var(--red); }

input[type="text"], input[type="email"], input[type="tel"],
input[type="number"], input[type="password"], input[type="search"],
input[type="file"], select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--gray-800);
  background: #fff;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
textarea { resize: vertical; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-row .field { margin-bottom: 0; }
.field { margin-bottom: 16px; }
.field-actions { display: flex; gap: 8px; align-items: center; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }

.input-search { max-width: 380px; margin-bottom: 12px; }

.total-display {
  background: var(--blue-light);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--blue-dark);
}

/* =====================
   Cards
   ===================== */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card-narrow { max-width: 680px; }

.customer-meta { font-size: 13px; color: var(--gray-600); margin-top: 2px; }

/* =====================
   Sale blocks on customer page
   ===================== */
.sale-block {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}
.sale-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
  gap: 8px;
}
.sale-block-title { font-weight: 600; font-size: 14px; }
.sale-block-meta  { font-size: 12px; color: var(--gray-600); }
.sale-block-actions { display: flex; gap: 6px; }
.sale-block-body  { padding: 12px 16px; }

.ticket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}
.ticket-row:last-child { border-bottom: none; }

.email-log-list { margin-top: 10px; }
.email-log-entry {
  font-size: 12px;
  color: var(--gray-600);
  padding: 4px 0;
  border-top: 1px solid var(--gray-100);
}
.email-sent-tag   { color: var(--green); font-weight: 600; }
.email-error-tag  { color: var(--red);   font-weight: 600; }
.email-bounce-tag { color: #d97706;      font-weight: 600; }

/* Inline email status line shown in the sale header */
.email-status-line {
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}
.email-status-sent    { color: var(--green); }
.email-status-failed  { color: var(--red); }
.email-status-bounced { color: #d97706; }

/* Unobtrusive inline "Mark Bounced" link-style button */
.btn-mark-bounced {
  background: none;
  border: none;
  padding: 0;
  font-size: 11px;
  color: #9ca3af;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
}
.btn-mark-bounced:hover { color: #d97706; }

/* =====================
   Badges
   ===================== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-blue   { background: var(--blue-light); color: var(--blue-dark); }
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-yellow { background: var(--yellow-light); color: #92400e; }
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }
.badge-green  { background: #d1fae5; color: #065f46; }

.bulk-ops-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.bulk-ops-label { font-size: 12px; color: #92400e; font-weight: 600; }

/* =====================
   Alerts
   ===================== */
.error-msg   { color: var(--red); font-size: 13px; padding: 8px 12px; background: #fde8e8; border-radius: 6px; }
.success-msg { color: var(--green); font-size: 13px; padding: 8px 12px; background: var(--green-light); border-radius: 6px; }
.info-msg    { color: #1e40af; font-size: 13px; padding: 8px 12px; background: var(--blue-light); border-radius: 6px; }
.note        { font-size: 12px; color: var(--gray-600); margin-top: 8px; }
.help-text   { font-size: 13px; color: var(--gray-600); margin-bottom: 12px; }

/* =====================
   Modals
   ===================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.modal-note { font-size: 13px; color: var(--gray-600); margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }

/* =====================
   Template page
   ===================== */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.template-preview-container {
  min-height: 200px;
  border: 2px dashed var(--gray-200);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.template-preview-container.interactive {
  display: block;
  position: relative;
  cursor: default;
}
.template-preview-container img { width: 100%; display: block; user-select: none; pointer-events: none; }
.placeholder-text { color: var(--gray-400); font-size: 13px; text-align: center; padding: 40px 0; }

/* ── Draggable field chips ── */
.field-chip {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 8px;
  border-radius: 4px;
  border: 2px solid currentColor;
  box-sizing: border-box;
  background: rgba(255,255,255,0.88);
  white-space: nowrap;
  overflow: hidden;
  transform-origin: 0 0;
  user-select: none;
  cursor: grab;
  box-shadow: 0 1px 5px rgba(0,0,0,0.25);
  font-family: inherit;
  transition: box-shadow 0.1s;
  z-index: 10;
}
.field-chip:active { cursor: grabbing; box-shadow: 0 3px 12px rgba(0,0,0,0.3); }
.field-chip::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 1px dashed currentColor;
  opacity: 0.35;
  pointer-events: none;
}
.field-chip .chip-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: 0.65;
}
.field-chip .chip-text {
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-chip .chip-rotate {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 0 0 0 4px;
  opacity: 0.55;
  line-height: 1;
  color: inherit;
  flex-shrink: 0;
}
.field-chip .chip-rotate:hover { opacity: 1; }

/* Chip colors */
.chip-name   { color: #1d4ed8; }
.chip-email  { color: #065f46; }
.chip-phone  { color: #92400e; }
.chip-ticket { color: #4c1d95; }
.chip-date   { color: #374151; }

/* ── Fields settings table ── */
.fields-settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.fields-settings-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-500);
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--gray-200);
}
.fields-settings-table td {
  padding: 8px 12px 8px 0;
  vertical-align: middle;
  border-bottom: 1px solid var(--gray-100);
}
.fields-settings-table input[type=number] { width: 64px; }
.field-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 4px;
  border: 2px solid currentColor;
  background: rgba(255,255,255,0.5);
}
.rotation-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  background: var(--gray-100);
  border-radius: 4px;
  padding: 2px 8px;
  min-width: 36px;
  text-align: center;
}

/* =====================
   Login page
   ===================== */
.login-page {
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 20px; font-weight: 800; color: var(--gray-800); }
.login-logo p  { font-size: 13px; color: var(--gray-600); margin-top: 4px; }

/* =====================
   Buyer-facing sale page
   ===================== */
.sale-page {
  min-height: 100vh;
  background: #f8fafc;
}

.sale-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 24px 16px 32px;
}

.sale-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.sale-kicker {
  color: var(--gray-600);
  font-size: 13px;
  font-weight: 600;
}

.sale-header h1 {
  font-size: 30px;
  line-height: 1.1;
  margin-top: 2px;
}

.sale-admin-link {
  color: var(--gray-600);
  font-size: 13px;
  padding: 8px 0;
}

.sale-form {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

.sale-section {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.sale-grid {
  grid-template-columns: minmax(130px, 0.55fr) minmax(180px, 1fr);
}

.sale-page .field {
  margin-bottom: 0;
}

.sale-page .field label {
  font-size: 14px;
}

.sale-page input[type="text"],
.sale-page input[type="email"],
.sale-page input[type="tel"],
.sale-page input[type="number"],
.sale-page select,
.sale-page textarea {
  min-height: 48px;
  font-size: 16px;
  border-color: #cbd5e1;
}

.sale-page textarea {
  min-height: 88px;
}

.payment-destination-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.payment-destination-row span {
  color: var(--gray-600);
  font-size: 16px;
  white-space: nowrap;
}

.sale-total {
  background: var(--blue-light);
  border-radius: 8px;
  color: var(--blue-dark);
  font-size: 17px;
  font-weight: 700;
  margin: 4px 0 14px;
  padding: 13px 14px;
  text-align: center;
}

.sale-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.sale-actions .btn {
  justify-content: center;
  min-height: 48px;
}

.sale-success-panel {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
  padding: 28px 22px;
  text-align: center;
}

.sale-success-kicker {
  color: var(--green);
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 6px;
}

.sale-success-panel h2 {
  font-size: 28px;
  line-height: 1.15;
  margin-bottom: 10px;
}

.sale-success-panel p:not(.sale-success-kicker) {
  color: var(--gray-600);
  font-size: 15px;
  margin: 0 auto 18px;
  max-width: 460px;
}

/* =====================
   Mobile top bar
   ===================== */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--gray-800);
  color: #fff;
  z-index: 200;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.mobile-topbar-brand {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}
.mobile-topbar-brand span {
  font-size: 11px;
  font-weight: 400;
  color: var(--gray-400);
  margin-left: 6px;
}
.hamburger-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.1); }

/* Overlay backdrop when sidebar is open on mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* Scrollable table wrapper injected by nav.js */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  /* Preserve rounded-corner appearance */
}
.table-scroll .table {
  border-radius: 0; /* outer wrapper owns the radius */
  min-width: 540px;
}

/* =====================
   Responsive
   ===================== */
@media (max-width: 768px) {
  .form-row { grid-template-columns: 1fr; }
  .two-col  { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  /* Show mobile topbar */
  .mobile-topbar { display: flex; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
  }
  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Main content: no left margin, top padding for topbar */
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: calc(52px + 16px);
  }

  /* Stats: two columns */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Page header: stack on very narrow screens */
  .page-header { flex-direction: column; align-items: flex-start; }

  /* Modal: full width with side margins */
  .modal {
    max-width: calc(100vw - 32px);
    margin: 16px;
    padding: 18px;
  }
  .modal-overlay {
    align-items: flex-end;
    padding-bottom: 0;
  }
  .modal {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  /* Bulk ops bar: wrap tightly */
  .bulk-ops-bar { gap: 6px; }
}

@media (max-width: 560px) {
  .sale-shell {
    padding: 18px 12px 28px;
  }

  .sale-header h1 {
    font-size: 26px;
  }

  .sale-form {
    padding: 14px;
  }

  .sale-grid,
  .sale-actions,
  .payment-destination-row {
    grid-template-columns: 1fr;
  }

  .payment-destination-row {
    gap: 5px;
  }
}
