:root {
  --brand-primary: #2563eb;
  --brand-secondary: #1e293b;
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { color: var(--brand-secondary); line-height: 1.25; }
h1 { font-size: 1.75rem; margin: 0 0 1rem; }
h2 { font-size: 1.25rem; margin: 1.75rem 0 0.75rem; }

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

p.hint { color: var(--color-text-muted); font-size: 0.85rem; margin: 0.25rem 0 0; }

/* Header / nav */
.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 2rem;
  background: var(--brand-secondary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.site-header .brand { font-weight: 700; font-size: 1.1rem; }
.brand-link { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
.site-header nav { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; }
.site-header nav a, .site-header nav .link-button {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: 0.925rem;
  transition: color 0.15s ease;
}
.site-header nav a:hover, .site-header nav .link-button:hover { color: #fff; }
.site-header nav .current-user { color: rgba(255, 255, 255, 0.6); font-size: 0.875rem; }

/* Layout */
.container { max-width: 720px; margin: 2rem auto; padding: 0 1.25rem 3rem; }

/* Buttons */
.link-button { background: none; border: none; padding: 0; cursor: pointer; font: inherit; text-decoration: underline; color: inherit; }
.inline-form { display: inline; }

.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: var(--brand-primary);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.05s ease;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: translateY(1px); }
.btn-danger { background: #b91c1c; }
.btn-outline { background: none; color: var(--brand-primary); border: 1px solid var(--color-border); }
.btn-outline:hover { background: #f3f4f6; opacity: 1; }

.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 1.5rem; }
.form-actions button, .form-actions .btn { margin-top: 0; }

/* Flash messages */
.flashes { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.flash { padding: 0.7rem 1rem; margin-bottom: 0.5rem; border-radius: var(--radius); font-size: 0.925rem; }
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* Forms */
form.stacked { display: flex; flex-direction: column; }
form.stacked label { margin-top: 1rem; font-weight: 600; font-size: 0.9rem; }
form.stacked label:first-child { margin-top: 0; }
form.stacked input[type=text], form.stacked input[type=email], form.stacked input[type=password],
form.stacked input[type=number], form.stacked select, form.stacked textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-top: 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
form.stacked input:focus, form.stacked select:focus, form.stacked textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 20%, transparent);
}
form.stacked button {
  margin-top: 1.5rem;
  align-self: flex-start;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 999px;
  background: var(--brand-primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
form.stacked button:hover { opacity: 0.9; }

/* Tables */
table { width: 100%; border-collapse: collapse; margin: 1rem 0; background: var(--color-surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
table th, table td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--color-border); font-size: 0.925rem; }
table th { color: var(--color-text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; background: #fafafa; }
table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover { background: #fafbfc; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card h2:first-child { margin-top: 0; }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.65rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: #e5e7eb; color: #374151; }
.badge-on { background: #d1fae5; color: #065f46; }
.badge-off { background: #fee2e2; color: #991b1b; }
.badge-error { background: #fef3c7; color: #92400e; }

/* Subscription status dots - coloured circle with the count of that status */
.subscription-summary-btn { display: inline-flex; align-items: center; gap: 0.35rem; background: none; border: none; padding: 0; cursor: pointer; }
.status-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}
.status-dot-active { background: #059669; }
.status-dot-error { background: #dc2626; }
.status-dot-canceled { background: #6b7280; }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; }
.filter-bar label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.9rem; }
.filter-bar input, .filter-bar select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
.filter-bar-actions { display: flex; gap: 0.5rem; }
.filter-bar-actions button { padding: 0.65rem 1.4rem; border: none; border-radius: 999px; background: var(--brand-primary); color: #fff; font-weight: 600; cursor: pointer; }

/* Pagination */
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 1rem 0; }
.pagination a, .pagination span { padding: 0.4rem 0.7rem; border-radius: 8px; font-size: 0.9rem; text-decoration: none; color: var(--color-text); }
.pagination a { border: 1px solid var(--color-border); background: var(--color-surface); }
.pagination a:hover { background: #fafbfc; }
.pagination-current { background: var(--brand-primary); color: #fff; font-weight: 600; }
.pagination-disabled { color: var(--color-text-muted); }
.pagination-ellipsis { color: var(--color-text-muted); }
.pagination-summary { margin-left: auto; color: var(--color-text-muted); font-size: 0.85rem; }

/* Modal */
dialog.modal { padding: 0; border: none; border-radius: var(--radius); box-shadow: var(--shadow-md); max-width: 40rem; width: calc(100vw - 2.5rem); }
dialog.modal::backdrop { background: rgba(15, 23, 42, 0.5); }
.modal-content { padding: 1.5rem; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--color-border); }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--color-text-muted); padding: 0; }
.modal-close:hover { color: var(--color-text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }

.qr-code { display: block; margin: 1rem 0; }

/* Messaging module - mail-client-style shell */
.container-wide { max-width: 1200px; }
.mail-shell { display: flex; gap: 1.5rem; align-items: flex-start; padding: 1.25rem 1.5rem; }
.mail-sidebar { width: 200px; flex-shrink: 0; position: sticky; top: 1.5rem; }
.mail-compose-btn { display: block; width: 100%; text-align: center; margin-bottom: 1rem; border: none; }
.mail-folders { display: flex; flex-direction: column; gap: 0.15rem; }
.mail-folders a { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0.75rem; border-radius: 8px; color: var(--color-text); text-decoration: none; font-size: 0.9rem; }
.mail-folders a:hover { background: #eef2ff; }
.mail-folders a.active { background: var(--brand-primary); color: #fff; }
.mail-folders a.active .mail-count { color: rgba(255, 255, 255, 0.85); }
.mail-count { color: var(--color-text-muted); font-size: 0.8rem; }
.mail-main { flex: 1; min-width: 0; }

.mail-list { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.mail-list-row { display: flex; align-items: center; gap: 1rem; padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--color-border); text-decoration: none; color: inherit; }
.mail-list-row:last-child { border-bottom: none; }
.mail-list-row:hover { background: #fafbfc; }
.mail-list-subject { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-list-meta { color: var(--color-text-muted); font-size: 0.82rem; white-space: nowrap; }

/* Compose - WYSIWYG editor */
.compose-toolbar { display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.4rem; border: 1px solid var(--color-border); border-bottom: none; border-radius: 8px 8px 0 0; background: #fafafa; margin-top: 0.35rem; }
.compose-toolbar button { border: 1px solid transparent; background: none; padding: 0.35rem 0.65rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.compose-toolbar button:hover { background: #e5e7eb; }
.compose-editor { min-height: 260px; padding: 0.85rem 1rem; border: 1px solid var(--color-border); border-radius: 0 0 8px 8px; background: #fff; }
.compose-editor:focus { outline: none; }

/* Compose - recipient picker */
.recipient-picker { border: 1px solid var(--color-border); border-radius: 8px; padding: 0.85rem; background: #fafafa; margin-top: 0.35rem; }
.recipient-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.recipient-chip { display: inline-flex; align-items: center; gap: 0.4rem; background: #e0e7ff; color: #3730a3; padding: 0.25rem 0.6rem; border-radius: 999px; font-size: 0.82rem; }
.recipient-chip button { border: none; background: none; cursor: pointer; color: inherit; font-weight: 700; padding: 0; line-height: 1; }
.recipient-search-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.recipient-search-row input, .recipient-search-row select { padding: 0.45rem 0.6rem; border: 1px solid var(--color-border); border-radius: 6px; font: inherit; }
.recipient-results { max-height: 220px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: 8px; margin-top: 0.5rem; background: #fff; }
.recipient-result-row { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--color-border); font-size: 0.88rem; }
.recipient-result-row:last-child { border-bottom: none; }
.recipient-result-row button { font-size: 0.8rem; padding: 0.25rem 0.65rem; }

/* Compose - attachments */
.attachment-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.5rem 0; }
.attachment-item { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.5rem 0.75rem; border: 1px solid var(--color-border); border-radius: 8px; font-size: 0.88rem; background: #fff; }

/* Audit trail */
.edit-log { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; color: var(--color-text-muted); }
.edit-log li { padding: 0.3rem 0; border-bottom: 1px dashed var(--color-border); }
.edit-log li:last-child { border-bottom: none; }

@media (max-width: 860px) {
  .mail-shell { flex-direction: column; }
  .mail-sidebar { width: 100%; position: static; }
}

@media (max-width: 640px) {
  .site-header { padding: 0.75rem 1.25rem; }
  .container { margin: 1.25rem auto; }
}

/* Admin dashboard shell */
.admin-body { background: var(--color-bg); }
.admin-shell { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--brand-secondary);
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0 1rem;
}
.admin-brand { padding: 0 1.25rem 1rem; margin-bottom: 0.5rem; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.admin-brand a { display: block; color: #fff; font-weight: 700; font-size: 1.05rem; text-decoration: none; }
.admin-brand-tag { display: block; font-size: 0.75rem; color: rgba(255, 255, 255, 0.55); margin-top: 0.15rem; }

.admin-nav { display: flex; flex-direction: column; gap: 0.1rem; padding: 0 0.65rem; flex: 1; overflow-y: auto; }
.admin-nav-heading { margin: 0.9rem 0.6rem 0.2rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(255, 255, 255, 0.4); }
.admin-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 0.9rem;
}
.admin-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.admin-nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.admin-nav a.active { background: var(--brand-primary); color: #fff; }

.admin-sidebar-footer { padding: 0.75rem 1.25rem 0; border-top: 1px solid rgba(255, 255, 255, 0.12); margin-top: 0.5rem; }
.admin-sidebar-footer a { color: rgba(255, 255, 255, 0.6); font-size: 0.85rem; text-decoration: none; }
.admin-sidebar-footer a:hover { color: #fff; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.admin-topbar-title { flex: 1; min-width: 0; }
.admin-topbar-title h1 { margin: 0; font-size: 1.2rem; }
.admin-topbar-actions { display: flex; align-items: center; gap: 1rem; }
.admin-user-menu { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--color-text-muted); }
.admin-user-menu .current-user { font-weight: 600; color: var(--color-text); }
.admin-sidebar-toggle { display: none; background: none; border: none; padding: 0.3rem; cursor: pointer; color: var(--color-text); }
.admin-sidebar-toggle svg { width: 22px; height: 22px; }

.admin-content { flex: 1; padding: 1.5rem; max-width: 1200px; width: 100%; }
.admin-content.container-flush { max-width: none; padding: 0; }

.admin-subnav { display: flex; gap: 0.25rem; margin-bottom: 1.1rem; border-bottom: 1px solid var(--color-border); }
.admin-subnav a { padding: 0.5rem 0.9rem; color: var(--color-text-muted); text-decoration: none; font-size: 0.9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.admin-subnav a:hover { color: var(--color-text); }
.admin-subnav a.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stat-card .stat-value { font-size: 1.9rem; font-weight: 700; color: var(--brand-secondary); }
.stat-card .stat-label { font-size: 0.85rem; color: var(--color-text-muted); }
.stat-card-alert .stat-value { color: #b45309; }

.quick-links-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.quick-link-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.quick-link-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.quick-link-card h3 { margin: 0 0 0.35rem; font-size: 1rem; color: var(--brand-primary); }
.quick-link-card p { margin: 0; font-size: 0.85rem; color: var(--color-text-muted); }

@media (max-width: 900px) {
  .admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }
  .admin-sidebar.open { transform: translateX(0); }
  .admin-sidebar-toggle { display: inline-flex; }
  .admin-content { padding: 1.1rem; }
}

