/* Magnus CMS — vanilla CSS, no framework.
   Brand tokens mirror frontend/constants/Colors.ts. */

:root {
  --red: #d72a24;
  --red-dark: #a8201b;
  --red-light: #ff5a4f;
  --red-glow: rgba(215, 42, 36, 0.2);

  --white: #ffffff;
  --paper: #fafafa;
  --surface: #ffffff;
  --border: #ececec;
  --muted: #7a7a7a;
  --text: #1a1a1a;

  --success: #1f8a3b;
  --warning: #e8a317;
  --danger: #d72a24;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --sidebar-w: 220px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
    sans-serif;
  background: var(--paper);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0 0 0.4em;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- App shell: sidebar + topbar ---------- */

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #14100f;
  color: #f2f2f2;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-mark {
  display: block;
  height: 32px;
  width: auto;
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--white);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
}

.sidebar-nav a {
  color: #d8d3d2;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
  color: var(--white);
}

.sidebar-nav a.active {
  background: var(--red);
  color: var(--white);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
}

.topbar-account {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-admin-name {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

.topbar-logout-form {
  margin: 0;
}

.content {
  padding: 28px;
  flex: 1;
}

.page-header {
  margin-bottom: 24px;
}

.page-subtitle {
  color: var(--muted);
  margin: 0;
}

/* ---------- Dashboard stat cards ---------- */

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

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.stat-card:hover {
  text-decoration: none;
  border-color: var(--red);
  transform: translateY(-2px);
}

.stat-card-count {
  font-size: 32px;
  font-weight: 800;
  color: var(--red);
}

.stat-card-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--red);
  border-color: var(--red);
  color: var(--white);
}

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--red);
  color: var(--red);
}

.btn-danger {
  background: var(--white);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: var(--white);
}

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

.btn-block {
  width: 100%;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

th {
  background: var(--paper);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.03em;
  color: var(--muted);
}

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

tbody tr:hover {
  background: var(--paper);
}

.table-actions {
  display: flex;
  gap: 8px;
}

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

form.form {
  max-width: 640px;
}

label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin: 16px 0 6px;
}

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

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='file'],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-glow);
}

.form-actions {
  margin-top: 24px;
  display: flex;
  gap: 10px;
}

.form-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

/* ---------- Flash banners ---------- */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}

.flash-success {
  background: rgba(31, 138, 59, 0.1);
  color: var(--success);
  border: 1px solid rgba(31, 138, 59, 0.25);
}

.flash-error {
  background: var(--red-glow);
  color: var(--red-dark);
  border: 1px solid rgba(215, 42, 36, 0.3);
}

/* ---------- Auth pages (login / error) ---------- */

.auth-body {
  background: linear-gradient(160deg, #14100f 0%, #2a1614 45%, var(--red-dark) 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-wrap {
  width: 100%;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  padding: 32px;
}

.error-card {
  text-align: center;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  justify-content: center;
}

.auth-brand-mark {
  display: block;
  height: 34px;
  width: auto;
}

.auth-brand-name {
  font-weight: 700;
  font-size: 16px;
}

.auth-title {
  text-align: center;
  margin-bottom: 18px;
}

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

.auth-form .btn {
  margin-top: 22px;
}

/* ---------- Field errors ---------- */

.field-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

input.has-error,
select.has-error,
textarea.has-error {
  border-color: var(--danger);
}

/* ---------- Badges + swatches ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--paper);
  border: 1px solid var(--border);
  color: var(--text);
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge-muted {
  color: var(--muted);
  font-style: italic;
  font-weight: 400;
  border-style: dashed;
}

.color-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  vertical-align: middle;
  margin-right: 6px;
}

.list-thumb {
  display: block;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--paper);
}

.status-toggle-form {
  display: inline-block;
  margin: 0;
}

.badge-status {
  border: none;
  font: inherit;
  cursor: pointer;
}

.badge-status-active {
  background: rgba(31, 138, 59, 0.12);
  color: var(--success);
}

.badge-status-inactive {
  background: var(--paper);
  border: 1px solid var(--border);
  color: var(--muted);
}

.video-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
}

.video-indicator.has-video {
  color: var(--success);
}

.video-indicator.no-video {
  color: var(--muted);
}

/* ---------- Color picker pair ---------- */

.color-pair {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-pair input[type='color'] {
  width: 44px;
  height: 40px;
  padding: 2px;
  flex-shrink: 0;
}

.color-pair input[type='text'] {
  flex: 1;
}

/* ---------- Dynamic rows (specs, guide steps, days/categories) ---------- */

.row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.row-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.row-item > * {
  flex: 1;
}

.row-item .row-remove {
  flex: 0 0 auto;
  margin-top: 0;
}

.row-add {
  margin-bottom: 20px;
}

.section-title {
  font-weight: 700;
  font-size: 15px;
  margin: 28px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.section-title:first-of-type {
  border-top: none;
  padding-top: 0;
}

/* ---------- Video upload block ---------- */

.current-video {
  margin: 8px 0 14px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.current-video video {
  max-width: 100%;
  max-height: 220px;
  display: block;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  background: #000;
}

.current-video img {
  max-width: 100%;
  max-height: 220px;
  display: block;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  background: var(--white);
  object-fit: contain;
}

.current-video-filename {
  font-size: 13px;
  color: var(--muted);
  font-family: monospace;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.checkbox-line input[type='checkbox'] {
  width: auto;
}

.checkbox-line label {
  margin: 0;
  font-weight: 500;
}

/* ---------- Structured days editor (programs) ---------- */

.day-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.day-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.day-block-header h3 {
  margin: 0;
  font-size: 15px;
}

.day-block .row-item {
  background: var(--white);
}

.day-list,
.days-wrap {
  margin-bottom: 10px;
}

/* ---------- Filters ---------- */

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.filter-bar .filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-bar label {
  margin: 0;
}

.filter-bar select {
  min-width: 180px;
}

/* ---------- Sort order controls (banners) ---------- */

.sort-controls {
  display: flex;
  gap: 4px;
}

.sort-controls form {
  margin: 0;
}

/* ---------- Detail / summary pages (users) ---------- */

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

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.detail-card h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 8px;
}

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

/* ---------- Drag-and-drop reordering (products list, gallery editor) ---------- */

.drag-handle-cell {
  width: 28px;
  text-align: center;
}

.drag-handle {
  display: inline-block;
  cursor: grab;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  user-select: none;
}

tbody[data-reorder-url] tr[data-id]:hover .drag-handle,
.gallery-item:hover .drag-handle {
  color: var(--red);
}

tbody[data-reorder-url] tr.is-dragging {
  opacity: 0.4;
}

tbody[data-reorder-url] tr[data-id] {
  transition: background-color 0.1s ease;
}

.reorder-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.reorder-status-pending {
  color: var(--muted);
}

.reorder-status-ok {
  color: var(--success);
}

.reorder-status-error {
  color: var(--danger);
}

/* ---------- Product gallery editor ---------- */

.gallery-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 10px 0;
}

.gallery-item {
  width: 150px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: grab;
}

.gallery-item.is-dragging {
  opacity: 0.4;
}

.gallery-item img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--white);
  border: 1px solid var(--border);
}

.gallery-item-path {
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
  word-break: break-all;
}

.gallery-item .checkbox-line {
  margin-top: 0;
}

/* ---------- Redemption codes ---------- */

.code-mono {
  font-family: monospace;
  font-size: 13px;
  letter-spacing: 0.02em;
}

/* ---------- App Settings ---------- */

.field-with-link {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-with-link input {
  flex: 1;
}

.external-link {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  white-space: nowrap;
}

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

/* ---------- Dashboard warning card ---------- */

.warning-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(232, 163, 23, 0.12);
  border: 1px solid rgba(232, 163, 23, 0.35);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
  color: var(--text);
  font-size: 14px;
}

.warning-card-icon {
  color: var(--warning);
  font-weight: 700;
}

.warning-card a {
  color: var(--red);
  font-weight: 600;
}
