:root {
  --front-bg: linear-gradient(145deg, #fff8ee 0%, #f8fbff 48%, #edf5ff 100%);
  --admin-bg: linear-gradient(160deg, #f4efe6 0%, #eef2f7 52%, #e6edf8 100%);
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(16, 33, 61, 0.1);
  --text: #1f2937;
  --muted: #5f6f85;
  --front-accent: #d35c37;
  --admin-accent: #1254a1;
  --ok: #1f8d61;
  --error: #bb3e34;
  --shadow: 0 24px 60px rgba(32, 59, 94, 0.12);
  --radius: 24px;
  --font-main: "IBM Plex Sans", "Segoe UI", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-main);
  min-height: 100vh;
}

body.theme-front {
  background: var(--front-bg);
}

body.theme-admin {
  background: var(--admin-bg);
}

.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

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

.topbar h1,
.panel h2,
.panel h3 {
  margin: 0;
  letter-spacing: -0.03em;
}

.nav {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.nav a,
.ghost-button,
.primary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 42px;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.nav a,
.ghost-button {
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.nav a.active {
  background: rgba(255, 255, 255, 0.95);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--front-accent), #ef8b40);
  box-shadow: 0 14px 28px rgba(211, 92, 55, 0.24);
}

.danger-button {
  color: #a63f36;
  background: rgba(181, 58, 48, 0.08);
  box-shadow: inset 0 0 0 1px rgba(181, 58, 48, 0.2);
}

.theme-admin .primary-button {
  background: linear-gradient(135deg, var(--admin-accent), #2a82ce);
  box-shadow: 0 14px 28px rgba(18, 84, 161, 0.24);
}

.nav a:hover,
.ghost-button:hover,
.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.danger-button:hover {
  background: rgba(181, 58, 48, 0.14);
}

.content {
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(16px);
}

.accent-panel {
  background: linear-gradient(160deg, rgba(211, 92, 55, 0.95), rgba(241, 138, 67, 0.84));
  color: white;
}

.metric-panel {
  background: linear-gradient(160deg, rgba(19, 84, 161, 0.9), rgba(59, 126, 198, 0.82));
  color: white;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--muted);
}

.accent-panel .eyebrow,
.metric-panel .eyebrow {
  color: rgba(255, 255, 255, 0.8);
}

.hero-grid,
.grid-two,
.stats-grid {
  display: grid;
  gap: 20px;
}

.hero-grid,
.grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.stat-card span {
  display: block;
  font-size: 0.92rem;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 12px;
  font-size: 2rem;
}

.auth-panel {
  max-width: 720px;
  margin: 40px auto 0;
}

.portal-panel {
  display: grid;
  gap: 16px;
}

.panel-intro {
  margin-bottom: 24px;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid rgba(93, 112, 142, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  padding: 13px 15px;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

.checkbox-line input {
  width: auto;
}

.checkbox-inline input {
  width: auto;
}

.inline-form,
.inline-activate,
.action-row {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-activate {
  width: 100%;
  margin-top: 18px;
}

.inline-activate input {
  flex: 1;
  min-width: 0;
}

.portal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.portal-actions > * {
  flex: 0 1 auto;
}

.portal-url {
  margin: 0;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(16, 33, 61, 0.05);
  color: var(--muted);
  word-break: break-all;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 14px 18px;
  border-radius: 18px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.flash-success {
  background: rgba(31, 141, 97, 0.12);
  color: var(--ok);
}

.flash-error {
  background: rgba(187, 62, 52, 0.12);
  color: var(--error);
}

.flash-info {
  background: rgba(18, 84, 161, 0.1);
  color: var(--admin-accent);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head-wrap {
  align-items: flex-start;
}

.form-lead {
  margin: 8px 0 0;
  max-width: 42rem;
}

.kv-list {
  display: grid;
  gap: 14px;
}

.kv-list div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
}

.secret-box {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  background: rgba(18, 22, 36, 0.92);
  color: #d9f7ff;
  padding: 18px;
  border-radius: 18px;
}

.secret-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.batch-code-list,
.plan-stack {
  display: grid;
  gap: 12px;
}

.batch-summary-grid {
  display: grid;
  gap: 12px;
}

.plan-item,
.plan-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
}

.plan-item span,
.plan-card p,
.muted {
  color: var(--muted);
}

.plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
}

.batch-card {
  align-items: flex-start;
}

.batch-card-active,
.active-chip {
  background: rgba(18, 84, 161, 0.1);
  box-shadow: inset 0 0 0 1px rgba(18, 84, 161, 0.2);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.pill-accent {
  color: var(--admin-accent);
  background: rgba(18, 84, 161, 0.1);
  box-shadow: inset 0 0 0 1px rgba(18, 84, 161, 0.12);
}

.pill-muted {
  color: var(--muted);
  background: rgba(95, 111, 133, 0.09);
  box-shadow: inset 0 0 0 1px rgba(95, 111, 133, 0.12);
}

.preset-row,
.form-actions,
.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.compact-button {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 0.92rem;
}

.table-wrap {
  overflow: auto;
}

td .ghost-button,
td .danger-button,
.table-actions .ghost-button,
.table-actions .danger-button {
  min-height: 36px;
  padding: 8px 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
}

@media (max-width: 960px) {
  .hero-grid,
  .grid-two,
  .two-col {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-activate {
    flex-direction: column;
  }

  .nav {
    width: 100%;
  }

  .nav a,
  .nav .inline-form,
  .nav .inline-form .ghost-button {
    width: 100%;
  }

  .plan-card,
  .panel-head,
  .preset-row,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .table-actions {
    justify-content: flex-start;
  }

  .secret-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .page-shell {
    padding: 18px 14px 32px;
  }

  .panel {
    padding: 18px;
    border-radius: 20px;
  }

  .topbar {
    margin-bottom: 18px;
  }

  .topbar h1 {
    font-size: 1.6rem;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .admin-topbar .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav a,
  .nav .inline-form,
  .nav .inline-form .ghost-button {
    min-width: 0;
  }

  .auth-panel {
    margin-top: 20px;
  }

  .inline-activate button,
  .portal-actions > * {
    width: 100%;
  }

  .panel-head .action-row,
  .panel-head .action-row > *,
  .table-actions > *,
  .secret-row > * {
    width: 100%;
  }

  .kv-list div {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .mobile-stacked-table {
    min-width: 0;
  }

  .mobile-stacked-table thead {
    display: none;
  }

  .mobile-stacked-table,
  .mobile-stacked-table tbody,
  .mobile-stacked-table tr,
  .mobile-stacked-table td {
    display: block;
    width: 100%;
  }

  .mobile-stacked-table tbody {
    display: grid;
    gap: 12px;
  }

  .mobile-stacked-table tr {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 10px 14px;
  }

  .mobile-stacked-table td {
    border-bottom: 1px dashed var(--line);
    padding: 10px 0;
    white-space: normal;
  }

  .mobile-stacked-table td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .mobile-stacked-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
  }

  .mobile-stacked-table .empty {
    text-align: left;
    padding: 6px 0;
  }

  .mobile-stacked-table .empty::before {
    display: none;
  }

  .mobile-stacked-table td .table-actions,
  .mobile-stacked-table td .action-row {
    width: 100%;
  }

  .mobile-stacked-table td code {
    white-space: normal;
    word-break: break-all;
  }
}

@media (max-width: 520px) {
  .nav {
    grid-template-columns: 1fr;
  }

  .admin-topbar .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .eyebrow {
    letter-spacing: 0.14em;
  }

  .topbar h1,
  .panel h2 {
    line-height: 1.2;
  }

  input,
  textarea,
  select {
    padding: 12px 14px;
  }
}
