:root {
  --color-bg: #f6f7fb;
  --color-surface: #ffffff;
  --color-border: #e6e8f0;
  --color-border-strong: #d8dbe7;
  --color-text: #1a1c29;
  --color-muted: #6b7089;
  --color-muted-2: #9296ab;

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-bg: #eef0fd;
  --color-primary-ring: rgba(79, 70, 229, 0.18);

  --color-success: #0f7a4f;
  --color-success-bg: #e4f7ee;
  --color-warning: #92660a;
  --color-warning-bg: #fdf3d8;
  --color-danger: #b3261e;
  --color-danger-bg: #fbe9e8;
  --color-gray-bg: #eef0f5;
  --color-gray-text: #5b5f74;

  --sidebar-bg: #14121f;
  --sidebar-bg-active: #211d36;
  --sidebar-text: #b7b6c9;
  --sidebar-text-active: #ffffff;
  --sidebar-border: #262238;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(20, 18, 31, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 18, 31, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 18, 31, 0.12);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

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

code {
  font-family: var(--font-mono);
  background: var(--color-gray-bg);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.88em;
  color: var(--color-text);
}

h1, h2, h3 {
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* ---------- App shell ---------- */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
}

.sidebar-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-brand-text-group {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.sidebar-brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.sidebar-brand-subtext {
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13.5px;
}

.nav-link svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-link:hover {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
  text-decoration: none;
}

.nav-link.active {
  background: var(--color-primary);
  color: #fff;
}

.nav-link.active svg {
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
}

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 14px;
  margin-top: 14px;
}

.admin-email {
  color: var(--sidebar-text);
  font-size: 12px;
  padding: 0 8px 8px;
  word-break: break-all;
}

.logout-form {
  display: flex;
}

.logout-form .btn-link {
  color: var(--sidebar-text);
  padding: 8px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border-radius: var(--radius-sm);
}

.logout-form .btn-link:hover {
  background: var(--sidebar-bg-active);
  color: #fff;
  text-decoration: none;
}

.main {
  flex: 1;
  min-width: 0;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 36px 40px 72px;
}

/* ---------- Page header ---------- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

h1 {
  font-size: 23px;
  margin: 0 0 22px;
  color: var(--color-text);
}

.page-header h1 {
  margin: 0;
}

h2 {
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--color-text);
}

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

.hint {
  color: var(--color-muted-2);
  font-size: 12px;
  margin: 6px 0 0;
}

/* ---------- Flash messages ---------- */

.flash {
  padding: 11px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 22px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
}

.flash-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: #c9ecdb;
}

.flash-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: #f4cfcc;
}

/* ---------- Cards ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card-warning {
  border-color: #f0dfa0;
  background: var(--color-warning-bg);
}

/* ---------- Stat grid ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-primary);
  opacity: 0.55;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-label {
  color: var(--color-muted);
  font-size: 12.5px;
  margin-top: 6px;
  font-weight: 500;
}

.key-list {
  margin: 10px 0 0;
  padding-left: 20px;
}

.key-list li {
  margin-bottom: 4px;
}

/* ---------- Tables ---------- */

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table th,
.table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.table th {
  background: #fafafd;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted-2);
}

.table tbody tr {
  transition: background-color 0.1s ease;
}

.table tbody tr:hover {
  background: #fafaff;
}

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

.table .actions {
  white-space: nowrap;
  display: flex;
  gap: 14px;
  align-items: center;
}

.empty {
  text-align: center;
  color: var(--color-muted-2);
  padding: 40px 24px;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  text-transform: capitalize;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}

.badge-active {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-suspended {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-revoked {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.badge-expired,
.badge-inactive {
  background: var(--color-gray-bg);
  color: var(--color-gray-text);
}

/* ---------- Forms ---------- */

.form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.form label {
  font-weight: 600;
  margin: 16px 0 7px;
  font-size: 13px;
  color: var(--color-text);
}

.form label:first-child {
  margin-top: 0;
}

.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form input[type="date"],
.form select,
.form textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.form textarea {
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
}

.form select[multiple] {
  font-family: inherit;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  margin-top: 16px;
}

.checkbox-label input {
  width: auto;
  accent-color: var(--color-primary);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

.filter-form {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.filter-form input[type="text"] {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.filter-form input[type="text"]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.filter-form select {
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--color-surface);
}

.button-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.extend-form {
  align-items: flex-end;
}

.extend-form label {
  margin: 0;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, transform 0.05s ease;
}

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

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.btn-secondary:hover {
  background: var(--color-gray-bg);
  text-decoration: none;
}

.btn-success {
  background: var(--color-success);
  color: #fff;
}

.btn-success:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.btn-warning {
  background: var(--color-warning);
  color: #fff;
}

.btn-warning:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-danger-link {
  color: var(--color-danger);
}

/* ---------- Detail grid ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: 170px 1fr;
  row-gap: 12px;
  margin: 0;
}

.detail-grid dt {
  color: var(--color-muted);
  font-weight: 600;
  font-size: 13px;
}

.detail-grid dd {
  margin: 0;
}

/* ---------- Login page ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.18), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(79, 70, 229, 0.14), transparent 45%),
    var(--sidebar-bg);
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 36px 36px 32px;
  width: 360px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  margin: 0 auto 18px;
  box-shadow: var(--shadow-sm);
  object-fit: contain;
}

.login-card h1 {
  font-size: 18px;
  text-align: center;
  margin: 0 0 6px;
}

.login-subtitle {
  text-align: center;
  color: var(--color-muted);
  font-size: 13px;
  margin: 0 0 22px;
}

.login-card .form {
  border: none;
  box-shadow: none;
  padding: 0;
  max-width: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    overflow-x: auto;
  }

  .sidebar-brand {
    padding: 0 14px 0 0;
  }

  .sidebar-nav {
    flex-direction: row;
  }

  .sidebar-footer {
    border-top: none;
    border-left: 1px solid var(--sidebar-border);
    margin: 0 0 0 10px;
    padding: 0 0 0 14px;
  }

  .admin-email {
    display: none;
  }

  .container {
    padding: 24px 20px 48px;
  }
}

/* ---------- Feature picker (plans & addons) ---------- */

.feature-picker {
  margin-top: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px 16px;
  background: var(--color-bg);
}

.feature-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
  margin: 12px 0 8px;
}

.feature-picker-head:first-child {
  margin-top: 0;
}

.feature-picker-tools {
  display: flex;
  gap: 12px;
  font-weight: 500;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.feature-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  margin: 0 !important;
  font-weight: 500 !important;
}

.feature-option input {
  width: auto;
  margin-top: 3px;
  accent-color: var(--color-primary);
}

.feature-option-core {
  background: var(--color-primary-bg);
  cursor: default;
}

.feature-option-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.feature-option-label {
  font-size: 13px;
  color: var(--color-text);
}

.feature-option-desc {
  font-size: 12px;
  color: var(--color-muted);
  font-weight: 400;
}

.limit-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.limit-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  align-items: center;
  gap: 12px;
}

.limit-label {
  font-size: 13px;
  font-weight: 500;
}

.limit-label small {
  color: var(--color-muted);
  font-weight: 400;
  margin-left: 4px;
}

.limit-unlimited {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500 !important;
  margin: 0 !important;
  white-space: nowrap;
}

.limit-unlimited input {
  width: auto;
  accent-color: var(--color-primary);
}

.form.form-wide {
  max-width: 760px;
}

.feature-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.feature-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--color-success-bg);
  color: var(--color-success);
}

.feature-chip-off {
  background: var(--color-gray-bg);
  color: var(--color-muted);
  text-decoration: line-through;
}

/* ---------- Email templates ---------- */

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.template-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.template-card-band {
  height: 8px;
}

.template-card-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.template-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
}

.template-card-subject {
  font-size: 13px;
  color: var(--color-text);
  background: var(--color-gray-bg);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.template-card-trigger {
  font-size: 12px;
  color: var(--color-muted);
  flex: 1;
}

.template-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.editor-split {
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr);
  gap: 20px;
  align-items: start;
}

.editor-split .form {
  max-width: none;
}

.preview-pane {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: sticky;
  top: 20px;
}

.preview-pane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
}

.preview-pane-head .muted {
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-pane iframe {
  width: 100%;
  height: 720px;
  border: 0;
  background: #eef0f6;
}

@media (max-width: 1100px) {
  .editor-split {
    grid-template-columns: 1fr;
  }
  .preview-pane {
    position: static;
  }
}

/* ---------- Product catalogue editor ---------- */

.catalog-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.catalog-table {
  margin: 0;
  min-width: 640px;
}

.catalog-table th {
  font-size: 11px;
  padding: 8px 8px;
}

.catalog-table td {
  padding: 4px 6px;
  vertical-align: middle;
}

.catalog-table td:first-child,
.catalog-table td:nth-last-child(2) {
  text-align: center;
  width: 44px;
}

.form .catalog-table input[type="text"] {
  padding: 6px 8px;
  font-size: 13px;
}

.form .catalog-table input.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.form .catalog-table input[type="checkbox"] {
  width: auto;
  accent-color: var(--color-primary);
}

.catalog-table td:nth-child(2) { width: 170px; }
.catalog-table td:nth-child(3) { width: 160px; }

.manifest-card {
  max-width: 760px;
  margin-bottom: 18px;
}

.manifest-form {
  max-width: none;
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.manifest-card textarea {
  font-family: var(--font-mono);
  font-size: 12.5px;
  width: 100%;
}

/* ---------- License requests ---------- */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--color-border);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--color-muted-2);
  font-weight: 600;
  font-size: 13.5px;
}

.tab:hover {
  color: var(--color-text);
  text-decoration: none;
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-count {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--color-gray-bg);
  color: var(--color-gray-text);
  font-size: 11.5px;
  text-align: center;
}

.tab.active .tab-count {
  background: var(--color-primary);
  color: #fff;
}

.request-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.request-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}

.request-main {
  min-width: 0;
}

.request-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.request-product {
  font-weight: 650;
  font-size: 14.5px;
}

.request-when {
  margin-left: auto;
  color: var(--color-muted-2);
  font-size: 12.5px;
  white-space: nowrap;
}

.request-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 28px;
  line-height: 1.5;
}

.request-label {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted-2);
  margin-bottom: 4px;
}

.request-strong {
  font-weight: 600;
}

.request-grid .muted {
  font-size: 13px;
}

.request-message {
  margin-top: 14px;
  padding: 10px 12px;
  border-left: 3px solid var(--color-border);
  background: #fafafd;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.request-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-left: 20px;
  border-left: 1px solid var(--color-border);
}

.request-side .badge {
  align-self: flex-start;
}

.request-side .btn-link {
  align-self: flex-start;
}

.request-payment {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.request-link {
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.request-key {
  font-size: 12.5px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stack-form select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--color-surface);
}

code.key {
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge-kind-new {
  background: #e6f0ff;
  color: #1d4ed8;
}

.badge-kind-upgrade {
  background: #efe6ff;
  color: #6d28d9;
}

.badge-kind-addon {
  background: #e3f7ec;
  color: #15803d;
}

@media (max-width: 860px) {
  .request-card {
    grid-template-columns: 1fr;
  }

  .request-side {
    padding-left: 0;
    padding-top: 14px;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
}

/* ---------- Licence holder forms & usage ---------- */

.form-section-title {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted-2);
  margin: 22px 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-border);
}

.form-section-title:first-of-type {
  margin-top: 4px;
}

.usage-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.usage-stats .stat {
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fafafd;
}

.usage-stats .stat-value {
  font-size: 18px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

/* A date is a sentence, not a number: at the tile's headline size "5 Nov 2026, 10:23 am"
   wraps and leaves "am" stranded on its own line. */
.usage-stats .stat-value.is-date {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.usage-stats .stat-label {
  margin-top: 2px;
  font-size: 12px;
  color: var(--color-muted-2);
}

/* ---------- WhatsApp & logs ---------- */

.wa-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
  gap: 20px;
  align-items: start;
}

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

.wa-provider-options {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.wa-provider {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "radio title" "radio desc";
  column-gap: 12px;
  row-gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 400;
}

.wa-provider input {
  grid-area: radio;
  margin-top: 4px;
}

.wa-provider-title {
  grid-area: title;
  font-weight: 650;
}

.wa-provider .muted {
  grid-area: desc;
  font-size: 13px;
}

.wa-provider.selected {
  border-color: var(--color-primary);
  background: #f6f5ff;
}

.wa-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form textarea.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.wa-sample {
  margin-top: 10px;
  padding: 10px 12px;
  background: #fafafd;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  overflow-x: auto;
}

.wa-sample pre {
  margin: 8px 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.wa-scan {
  text-align: center;
}

.wa-qr {
  width: 220px;
  height: 220px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  background: #fff;
}

.wa-template-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.wa-template {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--color-surface);
}

.wa-template-off {
  opacity: 0.6;
}

.wa-template-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.wa-bubble {
  margin: 0;
  padding: 10px 12px;
  background: #e7fbd8;
  border-radius: 10px 2px 10px 10px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid #cdeeb6;
}

.wa-preview-bg {
  padding: 18px;
  background: #ece5dd;
  min-height: 200px;
}

.log-filters {
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.log-error {
  max-width: 340px;
  overflow-wrap: anywhere;
  font-size: 12.5px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

/* ---------- Customers, invoices, renewals, newsletter ---------- */

.table td .badge,
.table td .text-danger,
.table td .text-warning {
  white-space: nowrap;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}

.two-col .card {
  margin-bottom: 0;
  min-width: 0;
}

.two-col .table {
  margin-bottom: 0;
}

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

.stat-grid-3 {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  margin-bottom: 20px;
}

@media (max-width: 800px) {
  .stat-grid-3 {
    grid-template-columns: 1fr;
  }
}

.filter-form-wrap {
  flex-wrap: wrap;
}

.filter-form-wrap input[type="text"] {
  min-width: 220px;
}

.filter-form input[type="date"] {
  padding: 8px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--color-surface);
}

.filter-form .checkbox-label {
  margin: 0;
  align-self: center;
  font-size: 13px;
}

.table-compact th,
.table-compact td {
  padding: 8px 10px;
  font-size: 13px;
}

.table .num,
.table td.num {
  text-align: right;
  white-space: nowrap;
}

.table tfoot td {
  font-weight: 600;
  background: var(--color-gray-bg);
}

.text-danger {
  color: var(--color-danger);
  font-weight: 600;
}

.text-warning {
  color: var(--color-warning);
  font-weight: 600;
}

.breadcrumb {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--color-muted);
}

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

.badge-draft {
  background: var(--color-gray-bg);
  color: var(--color-gray-text);
}

.badge-sending {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-sent {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-subscribed {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-unsubscribed {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--color-gray-bg);
  overflow: hidden;
  margin: 8px 0;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--color-primary);
  transition: width 0.3s ease;
}

.side-forms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.side-forms .form {
  max-width: none;
  margin: 0;
}

@media (max-width: 900px) {
  .side-forms {
    grid-template-columns: 1fr;
  }
}

/* Printable invoice */

.invoice-sheet {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  max-width: 820px;
}

.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--color-text);
  margin-bottom: 20px;
}

.invoice-head h2 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: 0.04em;
}

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
  font-size: 13.5px;
  line-height: 1.6;
}

.invoice-parties h3 {
  margin: 0 0 6px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
}

.invoice-total {
  display: flex;
  justify-content: flex-end;
  gap: 40px;
  font-size: 18px;
  font-weight: 700;
  padding: 14px 0;
  border-top: 2px solid var(--color-text);
}

.invoice-note {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 24px;
}

@media print {
  .sidebar,
  .page-header,
  .flash,
  .no-print {
    display: none !important;
  }
  .main,
  .container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }
  .invoice-sheet {
    border: 0;
    padding: 0;
    max-width: none;
  }
  body {
    background: #fff;
  }
}

/* ---------- "Write this for me" ---------- */

/* Sits under the field rather than inside it: the inputs here are full width and a button
   floated into the corner of one would cover the end of whatever is being typed. */
.ai-write-row {
  margin: 6px 0 0;
}

.ai-write-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-primary);
  background: var(--color-primary-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
}

.ai-write-btn:hover {
  border-color: var(--color-primary-ring);
}

.ai-write-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.ai-write-spark {
  font-size: 11px;
}

.ai-write-btn.is-busy .ai-write-spark {
  animation: ai-write-pulse 900ms ease-in-out infinite;
}

@keyframes ai-write-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.ai-write-note {
  color: var(--color-muted-2);
  font-size: 12px;
  margin: 5px 0 0;
}

.ai-write-note.bad {
  color: var(--color-danger, #b42318);
}

@media (prefers-reduced-motion: reduce) {
  .ai-write-btn.is-busy .ai-write-spark {
    animation: none;
  }
}

/* ---- Newsletter editor -------------------------------------------------- */

/* An emoji button sitting at the end of a single-line field. */
.with-emoji {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.with-emoji input {
  flex: 1;
  min-width: 0;
}

.emoji-btn {
  flex: 0 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 8px);
  padding: 0 12px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.emoji-btn:hover {
  border-color: #7c3aed;
}

.rt {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 8px);
  background: var(--color-surface);
  overflow: hidden;
}

.rt-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--color-border);
  background: #faf9fd;
}

.rt-bar button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-text, #1f2937);
  cursor: pointer;
}

.rt-bar button:hover {
  background: #ede9fe;
  border-color: #ddd6fe;
}

.rt-sep {
  width: 1px;
  align-self: stretch;
  margin: 2px 4px;
  background: var(--color-border);
}

.rt-area {
  min-height: 260px;
  max-height: 520px;
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.7;
  outline: none;
}

/* contenteditable has no placeholder of its own. */
.rt-area.is-empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted, #9ca3af);
  pointer-events: none;
}

.rt-area p { margin: 0 0 12px; }
.rt-area h3 { margin: 16px 0 8px; font-size: 17px; }
.rt-area ul,
.rt-area ol { margin: 0 0 12px; padding-left: 22px; }
.rt-area a { color: #4c1d95; }

/* The emoji picker: one popover, moved to whichever button opened it. */
/* display:grid below would otherwise beat the [hidden] attribute's own display:none, and
   the picker would go on swallowing clicks while invisible. */
.emoji-pop[hidden] {
  display: none;
}

.emoji-pop {
  position: absolute;
  z-index: 60;
  width: 288px;
  max-height: 232px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-md, 0 10px 30px rgba(0, 0, 0, 0.14));
}

.emoji-pop button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 4px 0;
  font-size: 19px;
  line-height: 1.25;
  cursor: pointer;
}

.emoji-pop button:hover {
  background: #ede9fe;
}

/* ---- Usage & trends ----------------------------------------------------- */

.page-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--color-muted-2);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

.filters select {
  width: auto;
  min-width: 170px;
  margin: 0;
}

/*
 * The chart is one series, so it takes one hue — the console's own accent — rather than
 * a palette. Nothing here needs telling apart from anything else; it needs reading.
 */
.chart {
  display: block;
  width: 100%;
  height: auto;
}

/* Grid and axis text stay recessive: they are scaffolding, not the subject. */
.chart-grid {
  stroke: var(--color-border);
  stroke-width: 1;
}

.chart-tick {
  fill: var(--color-muted-2);
  font-size: 11px;
}

.chart-area {
  fill: var(--color-primary);
  fill-opacity: 0.1;
}

.chart-line {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-dot {
  fill: var(--color-primary);
  stroke: var(--color-surface);
  stroke-width: 2;
}

/* One row's shape, no axis and no labels — the figures beside it carry the values. */
.spark {
  display: block;
  width: 90px;
  height: 24px;
  overflow: visible;
}

.spark path {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 1.5;
  stroke-opacity: 0.75;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* Direction is in the arrow and the sign as well as the colour. */
.delta {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.delta.up {
  color: #047857;
}

.delta.down {
  color: #b45309;
}

/* A licence key is one token; broken across three lines it stops looking like a key. */
.key-inline {
  white-space: nowrap;
  font-size: 11px;
}

.stat-value.is-warn {
  color: #b45309;
}

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.pager-where {
  font-size: 13px;
  color: var(--color-muted-2);
}

.btn.sm {
  padding: 5px 12px;
  font-size: 13px;
}

.btn.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.filters input[type='search'] {
  width: auto;
  min-width: 210px;
  margin: 0;
}

.print-only {
  display: none;
}

/* ---- Printing ----------------------------------------------------------- */

/*
 * A printed page has no sidebar to navigate with and no buttons to press, so everything
 * that only works on screen comes out — and the filters that produced the numbers go in,
 * because a sheet of figures nobody can place is worse than no sheet at all.
 */
@media print {
  .sidebar,
  .no-print,
  .page-header .button-row {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .print-header {
    margin-bottom: 14px;
    font-size: 12px;
    color: #000;
  }

  body,
  .shell,
  .main,
  .container {
    margin: 0;
    padding: 0;
    max-width: none;
    background: #fff;
    display: block;
  }

  .card {
    break-inside: avoid;
    border: 1px solid #ccc;
    box-shadow: none;
    margin-bottom: 12px;
  }

  /* A row split across a page break loses its shop name to the previous sheet. */
  table,
  tr {
    break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  a {
    text-decoration: none;
    color: #000;
  }

  .chart-area {
    fill-opacity: 0.18;
  }
}

/* Two cards side by side where the content is short. */
.two-up {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}

/* A bar in a table cell, read against the busiest row rather than against an axis. */
.bar-cell {
  width: 45%;
  min-width: 90px;
}

.bar {
  display: block;
  height: 8px;
  min-width: 2px;
  border-radius: 4px;
  background: var(--color-primary);
  opacity: 0.55;
}

/* A shop already at its cap is a different conversation from one approaching it. */
.bar.is-over {
  background: #b45309;
  opacity: 0.8;
}
