:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --text: #111111;
  --muted: #71717a;
  --border: #e4e4e7;
  --black: #09090b;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --yellow: #ca8a04;
  --yellow-soft: #fef9c3;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.14);
  --radius: 16px;
  --radius-sm: 12px;
  --header-h: 118px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
code {
  background: #f4f4f5;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  word-break: break-all;
}

/* ── Brand ── */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand.compact strong { display: block; font-size: 1rem; line-height: 1.3; }
.brand.compact small { color: rgba(255,255,255,0.65); font-size: 0.78rem; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.03em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.brand-logo-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}
.brand-logo-frame {
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
  border: 2px solid rgba(255, 255, 255, 0.9);
}
.brand-logo-frame--header {
  width: 56px;
  height: 56px;
  padding: 3px;
}
.brand-logo-frame--auth {
  width: 96px;
  height: 96px;
  padding: 5px;
  margin: 0 auto;
}
.auth-card .brand-logo {
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}
.auth-card .brand-logo p {
  margin: 0;
}
.settings-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.settings-form .form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.settings-panel {
  max-width: 720px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #fff;
  color: var(--black);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Login ── */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top right, rgba(0,0,0,0.04), transparent 45%),
    var(--bg);
}
.auth-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px 24px;
}
.auth-card .brand { margin-bottom: 24px; }
.auth-card .form { margin-top: 8px; }

/* ── Top banner ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--black);
  color: #fff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
  padding-top: var(--safe-top);
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px 10px;
  max-width: 1200px;
  margin: 0 auto;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.header-user-link {
  font-size: 0.86rem;
  color: rgba(255,255,255,0.85);
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  transition: background 0.15s, color 0.15s;
}
.header-user-link:hover {
  background: rgba(255,255,255,0.16);
  color: #fff;
}
.header-user {
  font-size: 0.86rem;
  color: rgba(255,255,255,0.7);
}
.site-header .btn-ghost {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
}
.site-header .btn-ghost:hover {
  background: rgba(255,255,255,0.16);
}

.header-nav {
  display: flex;
  gap: 8px;
  padding: 0 20px 14px;
  max-width: 1200px;
  margin: 0 auto;
}
.header-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.72);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.header-nav-link:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.header-nav-link.active {
  background: #fff;
  color: var(--black);
  border-color: #fff;
  font-weight: 600;
}
.nav-count {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: rgba(0,0,0,0.15);
  order: 2;
}
.nav-label {
  order: 1;
  line-height: 1.2;
}
.header-nav-link.active .nav-count {
  background: #f4f4f5;
  color: var(--black);
}

/* ── Main ── */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  min-width: 0;
}

/* ── Stats ── */
.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--black);
  opacity: 0.15;
}
.stat-card:nth-child(2)::before { background: var(--green); opacity: 1; }
.stat-card:nth-child(3)::before { background: var(--red); opacity: 1; }
.stat-card:nth-child(4)::before { background: var(--yellow); opacity: 1; }
.stat-card span { color: var(--muted); font-size: 0.88rem; }
.stat-card strong { display: block; font-size: 1.75rem; margin-top: 4px; line-height: 1.2; }

/* ── Panels ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-head {
  padding: 18px 20px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.panel-head h3 { margin: 0 0 4px; font-size: 1.05rem; }
.panel-head p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.panel-head p strong { color: var(--text); font-weight: 600; }

.search-form {
  flex: 1 1 320px;
  max-width: 460px;
  margin-left: auto;
  padding-bottom: 18px;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 6px 6px 6px 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.search-bar:focus-within {
  border-color: #c4c4cc;
  background: #fff;
  box-shadow:
    0 0 0 4px rgba(9, 9, 11, 0.06),
    0 8px 20px rgba(0, 0, 0, 0.06);
}
.search-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #a1a1aa;
}
.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 0;
  font: inherit;
  font-size: 0.94rem;
  color: var(--text);
}
.search-input::placeholder {
  color: #a1a1aa;
}
.search-input:focus {
  outline: none;
}
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}
.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--muted);
  background: #f4f4f5;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.search-clear:hover {
  background: #e4e4e7;
  color: var(--text);
}
.search-submit {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  background: var(--black);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.search-submit:hover { opacity: 0.92; }
.search-submit:active { transform: scale(0.98); }

/* ── Forms ── */
.form, .form-grid {
  display: grid;
  gap: 14px;
}
.form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 18px 20px 20px;
}
.form label,
.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}
.form input,
.form-grid input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus,
.form-grid input:focus {
  outline: none;
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(9, 9, 11, 0.08);
}
.form-actions { grid-column: 1 / -1; }

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--black); color: #fff; }
.btn-primary:hover { opacity: 0.92; }
.btn-ghost { background: #f4f4f5; color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { padding: 8px 12px; font-size: 0.86rem; }
.btn-block { width: 100%; }

/* ── Alerts ── */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.92rem;
}
.alert-success { background: var(--green-soft); color: #065f46; border: 1px solid #bbf7d0; }
.alert-error { background: var(--red-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert-warn { background: var(--yellow-soft); color: #92400e; border: 1px solid #fde68a; }

/* ── Table / Cards list ── */
.table-wrap { padding: 0 12px 16px; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
th, td {
  padding: 14px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 500; font-size: 0.88rem; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline; }

.mobile-list { display: none; padding: 0 12px 16px; }
.subscriber-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.subscriber-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.subscriber-card-head strong { font-size: 1rem; }
.subscriber-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-bottom: 12px;
}
.subscriber-meta div { display: grid; gap: 2px; }
.subscriber-meta span { color: var(--muted); font-size: 0.78rem; }
.subscriber-meta b { font-size: 0.92rem; font-weight: 600; }
.subscriber-card .actions { margin-top: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  flex-shrink: 0;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }

/* ── Modal ── */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 0;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  max-height: 92dvh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}
.modal-body strong { color: var(--text); }
.modal-card--confirm .form { margin-top: 0; }
.icon-btn {
  border: none;
  background: #f4f4f5;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}
.modal-actions {
  display: flex;
  justify-content: stretch;
  gap: 10px;
  margin-top: 8px;
}
.modal-actions .btn { flex: 1; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --header-h: 108px; }
  .table-wrap { display: none; }
  .mobile-list { display: block; }
}

@media (min-width: 901px) {
  .modal {
    place-items: center;
    padding: 20px;
  }
  .modal-card {
    border-radius: var(--radius);
    max-height: 90vh;
  }
  .modal-actions { justify-content: flex-end; }
  .modal-actions .btn { flex: unset; }
}

@media (max-width: 640px) {
  :root { --header-h: 132px; }

  .site-header {
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
  }

  .header-top {
    padding: 10px 12px 8px;
    gap: 8px;
  }

  .brand-logo-frame--header {
    width: 48px;
    height: 48px;
    padding: 2px;
  }

  .settings-form { grid-template-columns: 1fr; }

  .brand.compact strong { font-size: 0.92rem; }

  .header-user-link {
    display: inline-flex;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .site-header .btn-ghost {
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .header-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 12px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .header-nav-link {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    min-height: 58px;
    border-radius: 10px;
    font-size: 0.72rem;
    text-align: center;
    white-space: normal;
  }

  .nav-count {
    order: 0;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    font-size: 0.78rem;
  }

  .nav-label {
    order: 1;
    width: 100%;
    font-size: 0.72rem;
    line-height: 1.25;
  }

  .main { padding: 12px; }

  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { padding: 12px 14px; }
  .stat-card span { font-size: 0.8rem; }
  .stat-card strong { font-size: 1.35rem; }

  .form-grid { grid-template-columns: 1fr; }
  .subscriber-meta { grid-template-columns: 1fr; }
  .panel-head { align-items: stretch; }
  .search-form {
    max-width: none;
    margin-left: 0;
    width: 100%;
    padding-bottom: 16px;
  }
  .search-submit {
    padding: 10px 14px;
  }
}

@media (max-width: 380px) {
  :root { --header-h: 128px; }

  .header-nav-link {
    min-height: 54px;
    padding: 6px 2px;
  }

  .nav-label { font-size: 0.68rem; }
  .cards { grid-template-columns: 1fr 1fr; }
}
