:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --text: #1f2a3a;
  --muted: #5e6b7f;
  --border: #d4deea;
  --accent: #244a73;
  --accent-hover: #1b3b5d;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(22, 35, 52, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1000px 500px at 10% -20%, #dce7f4 0%, transparent 60%),
    radial-gradient(900px 420px at 120% 0%, #e7edf6 0%, transparent 58%),
    var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

a.link--underlined {
  text-decoration: underline;
  text-underline-offset: 2px;
}
a.link--underlined:hover {
  color: var(--accent-hover);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  transition: grid-template-columns 0.2s ease;
}

.app.menu-collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #21384f 0%, #1b2f45 55%, #182a3d 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  overflow: hidden;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}

.app.menu-collapsed .sidebar {
  opacity: 0;
  border-right-color: transparent;
  pointer-events: none;
}

.sidebar__brand {
  display: block;
  padding: 0 1.25rem 1rem;
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: #edf3fb;
  text-decoration: none;
}
.sidebar__brand:hover {
  text-decoration: none;
  opacity: 0.9;
}

.sidebar__close-btn {
  display: none;
  align-self: flex-end;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: #f5f9ff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  margin-bottom: 0.6rem;
}

.sidebar__nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.75rem;
}

.sidebar__link {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: #d8e3f0;
  text-decoration: none;
  font-size: 0.95rem;
}
.sidebar__link:hover {
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
}
.sidebar__link.is-active {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  font-weight: 600;
}

.sidebar__user-line {
  margin-left: 0.75rem;
  margin-right: 0.75rem;
  margin-bottom: 0.35rem;
  margin-top: auto;
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #f4f8fd;
  line-height: 1.3;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.sidebar__link--logout {
  margin-top: 0;
  padding-top: 0.65rem;
  border-top: none;
}

.main {
  padding: 1.75rem 2rem 3rem;
  min-width: 0;
}

.main__header {
  position: relative;
  margin-bottom: 1.5rem;
  min-height: 42px;
}

.main__header-logo {
  display: block;
  position: absolute;
  top: 4px;
  right: 6px;
  width: auto;
  max-width: 130px;
  max-height: 44px;
  height: auto;
  margin: 0;
}

.main__header-logo-link:hover {
  text-decoration: none;
}

.menu-toggle {
  border: 1px solid #c7d4e3;
  background: #f7fafe;
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  width: 40px;
  height: 36px;
  padding: 0;
  cursor: pointer;
  margin-bottom: 0.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.menu-toggle:hover {
  background: #eaf1f9;
}

.menu-toggle__icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.menu-toggle__icon::before,
.menu-toggle__icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.menu-toggle__icon::before {
  top: -6px;
}

.menu-toggle__icon::after {
  top: 6px;
}

.main__title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.main__meta {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card--spaced-top {
  margin-top: 1.75rem;
}

.card__head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #dce5f0;
  background: linear-gradient(180deg, #f9fbfe 0%, #f1f6fc 100%);
  font-weight: 600;
  font-size: 0.95rem;
}

.card__body {
  padding: 0;
}

/* Leads: admin summary by branch (above main list card) */
.leads-branch-summary-card {
  margin-bottom: 1.15rem;
}
.leads-branch-summary-card__body {
  padding: 0;
}
form.leads-filters.leads-summary-filters {
  padding: 0.75rem 1.15rem 0.85rem;
  margin: 0;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.08));
}
.leads-branch-summary-note {
  margin: 0;
  padding: 0.65rem 1.25rem 1rem;
  font-size: 0.76rem;
  color: var(--muted);
}
table.leads-summary-table .leads-summary-table__location {
  font-weight: 500;
  text-transform: capitalize;
  overflow-wrap: anywhere;
}
table.leads-summary-table thead th:nth-child(n + 2),
table.leads-summary-table tbody td.leads-summary-table__count,
table.leads-summary-table tbody td.leads-summary-table__conv,
table.leads-summary-table tbody td.leads-summary-table__amt {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.leads-summary-table tbody td.leads-summary-table__count,
table.leads-summary-table tbody td.leads-summary-table__conv,
table.leads-summary-table tbody td.leads-summary-table__amt {
  font-weight: 600;
  color: var(--accent);
}
table.leads-summary-table tfoot th,
table.leads-summary-table tfoot td {
  border-top: 2px solid var(--border);
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
  background: linear-gradient(180deg, #f5f9ff 0%, #eef4fc 100%);
}
table.leads-summary-table tfoot th {
  font-weight: 600;
  text-align: left;
  color: var(--text);
  text-transform: none;
  font-size: 0.9rem;
  letter-spacing: normal;
}
table.leads-summary-table .leads-summary-table__total-label {
  font-weight: 600;
}
table.leads-summary-table td.leads-summary-table__total-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
}

.leads-conversion-summary-card {
  margin-bottom: 1.15rem;
}
table.leads-conversion-summary-table th,
table.leads-conversion-summary-table td.leads-conversion-summary-table__num {
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.gift-code-completed-check {
  margin-left: 0.35rem;
  color: #15803d;
  font-weight: 700;
  font-size: 0.82rem;
  vertical-align: baseline;
}
.gift-code-amount--completed {
  color: #15803d;
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}
.gift-order-status--redeemed {
  color: #15803d;
  font-weight: 700;
}

/* Leads list: highlight converted status in green. */
.lead-status--converted {
  color: #15803d;
  font-weight: 600;
}

details.card {
  overflow: visible;
}

.card__toggle {
  list-style: none;
  cursor: pointer;
}

.card__toggle::-webkit-details-marker {
  display: none;
}

.card__toggle::marker {
  content: "";
}

.card__toggle-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.card__chevron {
  color: var(--muted);
  font-size: 0.95rem;
  transition: transform 0.2s ease;
}

details.card[open] .card__chevron {
  transform: rotate(180deg);
}

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data th,
table.data td {
  padding: 0.75rem 1.25rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.data th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.data tbody tr:last-child td {
  border-bottom: none;
}

table.data tbody tr:hover td {
  background: #f2f7fd;
}

.empty {
  padding: 2rem 1.25rem;
  color: var(--muted);
  text-align: center;
}

.form {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form--invoice-search {
  max-width: 520px;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.form--invoice-search .form__row {
  flex: 1 1 200px;
  margin-bottom: 0;
  min-width: 0;
}

.form--invoice-search .form__row--submit {
  flex: 0 0 auto;
}

.form--invoice-search .form__row--submit .btn {
  min-width: 6.5rem;
}

.form--inline-sales-period {
  max-width: none;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.form--inline-sales-period .form__row {
  flex: 0 0 auto;
  margin-bottom: 0;
  min-width: 0;
}

.form--inline-sales-period .form__row--submit {
  flex: 0 0 auto;
}

.form--inline-sales-period .form__row--month select {
  min-width: 10rem;
}

.form--inline-sales-period .form__row--year select {
  min-width: 5.5rem;
}

@media (max-width: 560px) {
  .form--inline-sales-period {
    flex-wrap: wrap;
  }
}

.form__row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.required-mark {
  color: #b91c1c;
}

.form__row input,
.form__row select,
.form__row textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fbfcfe;
}
.form__row textarea {
  min-height: 80px;
  resize: vertical;
}

.form__row--check {
  margin-bottom: 0;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}

.check-label input {
  width: auto;
}

.form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
}

table.data td.table-actions {
  white-space: nowrap;
  width: 1%;
}

.form__row input:focus,
.form__row select:focus,
.form__row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: linear-gradient(180deg, #2f5f90 0%, var(--accent) 100%);
  border-color: #1f446a;
  color: #fff;
}
.btn--primary:hover {
  background: linear-gradient(180deg, #2a5684 0%, var(--accent-hover) 100%);
}
.btn--danger {
  background: #b91c1c;
  border: 1px solid #991b1b;
  color: #fff;
}
.btn--danger:hover {
  background: #991b1b;
  border-color: #7f1d1d;
}
.btn--ghost {
  background: #f8fbff;
  border-color: #cedae8;
  color: var(--text);
}
.btn--ghost:hover {
  background: #eaf1f8;
}
.btn--light-green {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}
.btn--light-green:hover {
  background: #bbf7d0;
  border-color: #4ade80;
}
.btn--block {
  width: 100%;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
}
.alert--error {
  background: #fff5f5;
  border: 1px solid #efcdcd;
  color: #8a2b2b;
}
.alert--ok {
  background: #eefaf3;
  border: 1px solid #b9ddc7;
  color: #1d5a39;
}

.invoice-api-json {
  margin: 0;
  padding: 0.75rem 1rem;
  max-height: 28rem;
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #e9eff6 0%, var(--bg) 45%, #f9fbfd 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.08);
  padding: 2rem;
}

.login-card h1.login-heading {
  margin: 0 0 0.5rem;
  line-height: 0;
  text-align: center;
}

.login-logo {
  display: inline-block;
  max-width: min(280px, 100%);
  width: auto;
  height: auto;
  vertical-align: middle;
}

.login-card .sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card .form {
  max-width: none;
}

/* Leads list (desktop/tablet): hide mobile-only short date */
table.data--meta-leads .lead-list-date--short {
  display: none;
}

/* Leads list page: filters + summary (desktop) */
.leads-summary {
  padding: 1rem 1.25rem 0.5rem;
  margin: 0;
}
.leads-summary__count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
}
form.leads-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: flex-end;
  padding: 0 1.25rem 1rem;
  margin: 0;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.08));
}
form.leads-filters .form__row {
  margin: 0;
  min-width: 10rem;
}
form.leads-filters .leads-filter-fu-inner {
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: flex-end;
}
form.leads-filters .leads-filter-fu-inner .form__row {
  min-width: 11rem;
}
form.leads-filters > .btn {
  align-self: flex-end;
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }
  .app.menu-collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(82vw, 320px);
    height: 100vh;
    z-index: 1200;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    border-bottom: none;
    padding: 0.9rem 1rem;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow-y: auto;
    transform: translateX(0);
    transition: transform 0.24s ease, opacity 0.24s ease;
  }
  .sidebar__brand {
    width: auto;
    padding: 0 0 0.9rem;
  }
  .sidebar__close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .sidebar__nav {
    flex-direction: column;
    flex-wrap: nowrap;
    flex: 0 0 auto;
    padding: 0;
    gap: 0.28rem;
  }
  .sidebar__link {
    padding: 0.55rem 0.7rem;
    font-size: 1rem;
  }
  .sidebar__user-line {
    width: auto;
    flex-basis: auto;
    margin-left: 0;
    margin-right: 0;
    margin-top: 0.65rem;
    order: 0;
  }
  .main {
    padding: 1.25rem 1rem 2rem;
  }
  .main__header-logo {
    max-width: 50px;
    max-height: 30px;
    top: 4px;
    right: 6px;
  }
  .main__meta {
    display: none;
  }
  .main__meta.main__meta--mobile-visible {
    display: block;
  }

  /* Leads page mobile: summary badge, stacked filters, card-style rows */
  .leads-summary {
    padding: 0.55rem 0.85rem !important;
    margin: 0 0 0.85rem !important;
    border-radius: 10px;
    background: linear-gradient(145deg, #f4f8fd 0%, #e9f1f9 100%);
    border: 1px solid rgba(37, 99, 235, 0.12);
    font-size: 0.875rem !important;
    font-weight: 600;
    color: var(--text) !important;
    line-height: 1.35;
  }
  .leads-summary__count {
    font-size: 1.05rem;
    vertical-align: baseline;
  }

  form.leads-filters {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.75rem !important;
    padding: 0 0 1rem !important;
    border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.06));
  }
  form.leads-filters .form__row {
    width: 100%;
    min-width: 0 !important;
  }
  form.leads-filters .form__row label {
    margin-bottom: 0.3rem;
    font-size: 0.82rem;
  }
  form.leads-filters .form__row select,
  form.leads-filters input[type="date"] {
    min-height: 44px;
    box-sizing: border-box;
  }
  form.leads-filters #leads_filter_fu_wrap {
    width: 100%;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }
  form.leads-filters #leads_filter_fu_wrap .form__row {
    min-width: 0 !important;
  }
  form.leads-filters > .btn.btn--primary {
    width: 100%;
    justify-content: center;
    align-self: stretch !important;
    min-height: 44px;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    margin-top: 0.15rem;
  }

  .table-wrap--leads-mobile {
    padding-top: 0.35rem;
  }

  table.data--franchise-leads th:nth-child(4),
  table.data--franchise-leads td:nth-child(4),
  table.data--franchise-leads th:nth-child(5),
  table.data--franchise-leads td:nth-child(5) {
    display: none;
  }
  table.data--gift-codes th:nth-child(1),
  table.data--gift-codes td:nth-child(1),
  table.data--gift-codes th:nth-child(4),
  table.data--gift-codes td:nth-child(4) {
    display: none;
  }
  table.data--dashboard-gift-codes th:nth-child(3),
  table.data--dashboard-gift-codes td:nth-child(3) {
    display: none;
  }

  /* Leads list: mobile stack, hide phone, short date; compact card rows */
  table.data--meta-leads {
    display: block;
    width: 100%;
  }
  table.data--meta-leads thead {
    display: none;
  }
  table.data--meta-leads tbody {
    display: block;
  }
  table.data--meta-leads tbody tr {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
    margin: 0 0 0.65rem;
    border: 1px solid var(--border, rgba(0, 0, 0, 0.07));
    border-radius: 12px;
    background: linear-gradient(180deg, #fcfdfe 0%, #f7f9fc 100%);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
    overflow: hidden;
  }
  table.data--meta-leads tbody td {
    display: block;
    width: 100%;
    padding: 0.45rem 0.75rem;
    margin: 0;
    border: none;
    box-sizing: border-box;
    line-height: 1.38;
    font-size: 0.92rem;
  }
  table.data--meta-leads tbody td + td {
    border-top: 1px solid rgba(0, 0, 0, 0.05);
  }
  table.data--meta-leads tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.55;
    margin-bottom: 0.22rem;
  }
  table.data--meta-leads td.lead-list-col--name {
    font-size: 0.94rem;
  }
  table.data--meta-leads td.lead-list-col--name a {
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.4;
    display: inline;
  }
  table.data--meta-leads td.lead-list-col--loc {
    text-transform: capitalize;
    font-weight: 500;
  }
  table.data--meta-leads td.lead-list-col--date .lead-list-date {
    font-weight: 500;
  }
  table.data--meta-leads td.lead-list-col--phone {
    display: none !important;
  }
  table.data--meta-leads .lead-list-date--short {
    display: inline;
  }
  table.data--meta-leads .lead-list-date--full {
    display: none;
  }
  /* Admin: Location is first in markup; stacked order follows DOM */
  table.data--meta-leads:not(.data--meta-leads--with-loc) td.lead-list-col--name {
    order: 1;
  }
  table.data--meta-leads:not(.data--meta-leads--with-loc) td.lead-list-col--status {
    order: 2;
  }
  table.data--meta-leads:not(.data--meta-leads--with-loc) td.lead-list-col--date {
    order: 3;
  }
  .app.menu-collapsed .sidebar {
    display: flex;
    transform: translateX(-108%);
    opacity: 0;
    pointer-events: none;
  }
  .app.menu-collapsed .sidebar {
    border-right-color: rgba(255, 255, 255, 0.12);
  }
}
