:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --ink: #16211f;
  --muted: #5f6f6b;
  --line: #e1e8e5;
  --line-strong: #cdd9d4;
  --brand: #0d6157;
  --brand-dark: #093f39;
  --brand-soft: #e5f2ef;
  --accent: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 40, 35, 0.04), 0 10px 30px rgba(15, 40, 35, 0.05);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1100px 440px at 8% -10%, #e4f1ed 0%, rgba(228, 241, 237, 0) 60%),
    radial-gradient(900px 360px at 100% 0%, #eef2f8 0%, rgba(238, 242, 248, 0) 55%),
    var(--bg);
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.35rem;
  font-size: clamp(1.65rem, 2.6vw, 2.15rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h2 {
  margin-bottom: 0.3rem;
  font-size: 1.12rem;
  letter-spacing: -0.01em;
}

a {
  color: var(--brand);
}

code {
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f6f9f8;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 0.86em;
}

.wrap {
  width: min(1120px, 100% - 2.5rem);
  margin-inline: auto;
}

.main {
  flex: 1;
  padding-block: 2rem 3rem;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

.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;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 100;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  background: var(--brand-dark);
  color: #fff;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Header */
.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  min-height: 72px;
  padding-block: 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 12px rgba(13, 97, 87, 0.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
}

.nav > a {
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}

.nav > a:hover {
  background: #f1f6f4;
  color: var(--ink);
}

.nav > a.is-active {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.logout-form {
  margin: 0 0 0 0.4rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 0.95rem;
  border: 1px solid transparent;
  border-radius: 9px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 6px 16px rgba(13, 97, 87, 0.2);
}

.btn-primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.btn-ghost {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink);
}

.btn-ghost:hover {
  border-color: #b7c6c0;
  background: #f5f8f7;
}

.btn-block {
  width: 100%;
  padding-block: 0.72rem;
}

/* Shared page pieces */
.eyebrow {
  margin-bottom: 0.35rem;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.page-sub {
  max-width: 62ch;
  margin-bottom: 0;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-soft {
  border-color: transparent;
  background: var(--brand-soft);
  color: var(--brand-dark);
}

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

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.4rem 1.5rem 1.1rem;
}

.card-head p {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.card-head-stack {
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.card-head-stack > div:first-child {
  flex: 1 1 320px;
}

.note {
  margin: 0;
  padding: 0.95rem 1.5rem 1.1rem;
  border-top: 1px solid var(--line);
  background: #fbfdfc;
  color: var(--muted);
  font-size: 0.83rem;
}

/* Flash messages */
.flash-stack {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.flash {
  margin: 0;
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  font-size: 0.9rem;
}

.flash-success {
  border-color: #bfe3d3;
  background: #edf8f2;
  color: #0c5b3d;
}

.flash-error {
  border-color: #f0c2bb;
  background: #fdf2f0;
  color: #9b2c1c;
}

/* Shops */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.shop-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.shop-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 1.05rem;
  font-weight: 700;
}

.shop-meta {
  min-width: 0;
  margin-right: auto;
}

.shop-label {
  margin-bottom: 0.1rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.shop-meta h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
}

.shop-state {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1a9d6c;
  box-shadow: 0 0 0 3px #e1f4eb;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

#affiliate-table {
  min-width: 600px;
}

.data-table th,
.data-table td {
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  padding-block: 0.65rem;
  background: #f8fbfa;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #fbfdfc;
}

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

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table .cell-strong {
  font-weight: 600;
}

.data-table tfoot th,
.data-table tfoot td {
  border-top: 1px solid var(--line-strong);
  border-bottom: 0;
  background: #f6faf8;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
}

.data-table tfoot th {
  text-align: left;
}

.data-table tfoot .num {
  text-align: right;
}

.empty-row td {
  padding-block: 2rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

[hidden] {
  display: none !important;
}

/* Status pills */
.status {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
}

.status-active {
  border-color: #bfe6d5;
  background: #e9f8f1;
  color: #0b6847;
}

.status-completed {
  border-color: #c9dcf3;
  background: #eef5fd;
  color: #245a94;
}

.status-scheduled {
  border-color: #f2ddb2;
  background: #fdf6e7;
  color: #8a5a09;
}

.status-paused {
  border-color: #f2ccc3;
  background: #fdf1ee;
  color: #9b4027;
}

.status-inactive {
  border-color: #dfe5e2;
  background: #f3f6f5;
  color: #64736e;
}

/* Search */
.search {
  position: relative;
  flex: 0 1 300px;
  min-width: 210px;
}

.search input {
  width: 100%;
  padding: 0.62rem 0.8rem 0.62rem 2.3rem;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  appearance: none;
}

.search input::placeholder {
  color: #93a29d;
}

.search input:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 97, 87, 0.12);
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 0.8rem;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  transform: translateY(-50%);
  pointer-events: none;
}

.table-toolbar {
  padding: 0.65rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: #fbfdfc;
}

.result-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

/* Login */
.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  max-width: 960px;
  margin: 2.5rem auto 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 20px 55px rgba(15, 40, 35, 0.1);
}

.login-card {
  padding: 2.6rem 2.4rem;
}

.login-card h1 {
  font-size: clamp(1.5rem, 2.3vw, 1.85rem);
}

.login-intro {
  margin-bottom: 1.5rem;
  font-size: 0.92rem;
}

.form-error {
  margin-bottom: 1.1rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid #f0c2bb;
  border-radius: 8px;
  background: #fdf2f0;
  color: #9b2c1c;
  font-size: 0.88rem;
}

.login-form {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field label {
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 600;
}

.field input {
  width: 100%;
  padding: 0.66rem 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.94rem;
}

.field input:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 97, 87, 0.12);
}

.login-footnote {
  margin: 1.35rem 0 0;
  color: var(--muted);
  font-size: 0.79rem;
}

.login-aside {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2.6rem 2.4rem;
  background:
    radial-gradient(500px 260px at 100% 0%, rgba(255, 255, 255, 0.14), transparent 70%),
    linear-gradient(155deg, #0e6a5f 0%, #093e39 100%);
  color: #eaf6f2;
}

.aside-badge {
  align-self: flex-start;
  margin-bottom: 1.1rem;
  padding: 0.28rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.login-aside h2 {
  max-width: 20ch;
  margin-bottom: 1.3rem;
  color: #fff;
  font-size: 1.4rem;
  line-height: 1.3;
}

.feature-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.feature-list li {
  position: relative;
  padding-left: 1.35rem;
  color: #d6ebe5;
}

.feature-list li::before {
  position: absolute;
  top: 0.55em;
  left: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7fd4bf;
  content: "";
}

.feature-list strong {
  color: #fff;
}

/* About */
.prose-card {
  max-width: 760px;
  padding: 1.7rem 1.8rem;
}

.prose-card p {
  margin: 0;
  color: #33443f;
  font-size: 1.02rem;
  line-height: 1.75;
}

/* Footer */
.footer {
  padding-block: 1.4rem 2rem;
  color: #7b8a85;
  font-size: 0.78rem;
}

.footer p {
  margin: 0;
}

/* Responsive */
@media (max-width: 900px) {
  .login-layout {
    grid-template-columns: minmax(0, 1fr);
    max-width: 520px;
    margin-top: 1rem;
  }

  .login-aside {
    order: -1;
    padding: 1.8rem 2rem;
  }

  .login-aside h2 {
    max-width: none;
    margin-bottom: 0.9rem;
    font-size: 1.2rem;
  }

  .feature-list {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .login-card {
    padding: 2rem 2rem 2.2rem;
  }
}

@media (max-width: 760px) {
  .wrap {
    width: min(100% - 1.5rem, 1120px);
  }

  .main {
    padding-block: 1.4rem 2.2rem;
  }

  .topbar-inner {
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 64px;
  }

  .nav {
    width: 100%;
    gap: 0.15rem;
    padding-top: 0.2rem;
  }

  .nav > a {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }

  .logout-form {
    margin-left: auto;
  }

  .logout-form .btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.83rem;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .shop-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .card-head {
    flex-direction: column;
    padding: 1.15rem 1.1rem 0.95rem;
  }

  .card-head-stack {
    align-items: stretch;
  }

  .search {
    flex-basis: auto;
    width: 100%;
  }

  .data-table th,
  .data-table td {
    padding-inline: 1.1rem;
  }

  .note {
    padding-inline: 1.1rem;
  }

  .table-toolbar {
    padding-inline: 1.1rem;
  }

  .prose-card {
    padding: 1.3rem 1.2rem;
  }
}

@media (max-width: 480px) {
  .login-card,
  .login-aside {
    padding-inline: 1.35rem;
  }

  .shop-state {
    display: none;
  }

  .brand-sub {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
