/* Reminder Dashboard — all styling lives here.
   Theming is one set of custom properties, overridden for dark mode by
   prefers-color-scheme and by an explicit [data-theme] on <html>. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1b1f24;
  --text-muted: #646c76;
  --primary: #2f6df6;
  --primary-hover: #2058d8;
  --primary-soft: #e6eeff;
  --danger: #d3383d;
  --danger-soft: #fdecec;
  --success: #1c8a4c;
  --success-soft: #e4f6ec;
  --warn: #a86a05;
  --warn-soft: #fdf3e0;
  --info: #2f6df6;
  --info-soft: #e6eeff;
  --neutral: #6a727c;
  --neutral-soft: #eceef1;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e242c;
    --border: #2b323b;
    --text: #e8eaed;
    --text-muted: #9aa4b0;
    --primary: #5b8dff;
    --primary-hover: #7aa2ff;
    --primary-soft: #1b2740;
    --danger: #f2656a;
    --danger-soft: #3a1f21;
    --success: #4ec983;
    --success-soft: #16301f;
    --warn: #e0a642;
    --warn-soft: #33270f;
    --info: #5b8dff;
    --info-soft: #1b2740;
    --neutral: #99a2ad;
    --neutral-soft: #252b33;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.32);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --border: #2b323b;
  --text: #e8eaed;
  --text-muted: #9aa4b0;
  --primary: #5b8dff;
  --primary-hover: #7aa2ff;
  --primary-soft: #1b2740;
  --danger: #f2656a;
  --danger-soft: #3a1f21;
  --success: #4ec983;
  --success-soft: #16301f;
  --warn: #e0a642;
  --warn-soft: #33270f;
  --info: #5b8dff;
  --info-soft: #1b2740;
  --neutral: #99a2ad;
  --neutral-soft: #252b33;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

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

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

code {
  font-family: var(--mono);
  font-size: 0.92em;
}

a {
  color: var(--primary);
}

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

.req {
  color: var(--danger);
}

[hidden] {
  display: none !important;
}

/* ───────────────────────────── Boot / setup ───────────────────────────── */

.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 100vh;
  color: var(--text-muted);
}

.setup {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.setup-card {
  width: 100%;
  max-width: 440px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setup-title {
  font-size: 22px;
}

/* ────────────────────────────── App layout ────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  font-size: 16px;
  font-weight: 650;
  padding: 4px 10px 16px;
}

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

.nav-item {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
}

.user-name {
  font-weight: 600;
}

.user-key {
  color: var(--text-muted);
  font-size: 11px;
}

.nav-toggle {
  display: none;
}

.content {
  padding: 24px;
  min-width: 0;
}

.page-head {
  display: flex;
  /* Top-aligned so the primary action lines up with the first row of filters
     instead of floating between them when the filters wrap. */
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  /* Claim the free width so the search shares a row with the status filter. */
  flex: 1 1 420px;
}

/* Primary action sits flush with the right edge of the content column and
   matches the search field's height, so the row reads as one band. */
.page-head > .btn {
  margin-left: auto;
  padding-block: 9px;
}

/* ──────────────────────────────── Cards ──────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad {
  padding: 20px;
}

.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-title {
  font-size: 15px;
}

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

.grid-cards {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.stat {
  padding: 16px 18px;
}

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

.stat-value {
  font-size: 26px;
  font-weight: 650;
  margin-top: 4px;
}

.stat-sub {
  color: var(--text-muted);
  font-size: 12px;
}

/* ──────────────────────────────── Forms ──────────────────────────────── */

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

.field-label {
  font-weight: 550;
  font-size: 13px;
}

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

.input,
input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 74px;
  font-family: var(--mono);
  font-size: 13px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.input-error {
  border-color: var(--danger);
}

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

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.checkbox input {
  width: auto;
}

.search {
  flex: 1 1 200px;
  min-width: 180px;
  max-width: 340px;
  width: auto;
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ─────────────────────────────── Buttons ─────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  filter: brightness(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

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

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

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

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

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

.btn-icon {
  padding: 5px 8px;
}

.btn-block {
  width: 100%;
}

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

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.seg {
  padding: 5px 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}

.seg.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ──────────────────────────────── Table ──────────────────────────────── */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

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

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

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  color: var(--text);
}

.cell-title {
  font-weight: 550;
}

.cell-sub {
  color: var(--text-muted);
  font-size: 12px;
}

.cell-url {
  font-family: var(--mono);
  font-size: 12px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.pager-info {
  color: var(--text-muted);
  font-size: 13px;
  margin-right: auto;
}

/* ─────────────────────────────── Badges ──────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-pending {
  background: var(--info-soft);
  color: var(--info);
}

.badge-fired {
  background: var(--success-soft);
  color: var(--success);
}

.badge-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-cancelled {
  background: var(--neutral-soft);
  color: var(--neutral);
}

.badge-skipped {
  background: var(--warn-soft);
  color: var(--warn);
}

/* ─────────────────────────── Callouts / states ───────────────────────── */

.callout {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid transparent;
}

.callout-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
}

.callout-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.callout-info {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 30%, transparent);
}

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

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

/* Skeleton loader */
.skeleton {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-row {
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.spinner-lg {
  width: 30px;
  height: 30px;
  border-width: 3px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  .skeleton-row {
    animation: none;
  }
}

/* ─────────────────────────────── Modal ───────────────────────────────── */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 18, 0.55);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-wide {
  max-width: 780px;
}

.modal-head {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  margin-right: auto;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.modal-foot:empty {
  display: none;
}

/* ─────────────────────────────── Toasts ─────────────────────────────── */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--neutral);
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}

.toast-success {
  border-left-color: var(--success);
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-info {
  border-left-color: var(--info);
}

.toast-message {
  flex: 1;
  word-break: break-word;
}

.toast-close {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ───────────────────────── Details / definition list ─────────────────── */

.dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 16px;
  margin: 0;
}

.dl dt {
  color: var(--text-muted);
  font-size: 13px;
}

.dl dd {
  margin: 0;
  word-break: break-word;
}

.section-title {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 22px 0 10px;
}

pre.code {
  margin: 0;
  padding: 11px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
}

/* Progress bar */
.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 10px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-fill.warn {
  background: var(--warn);
}

.progress-fill.danger {
  background: var(--danger);
}

/* Bar chart (last 7 days) */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 150px;
  padding: 12px 4px 0;
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar {
  width: 100%;
  max-width: 46px;
  min-height: 3px;
  background: var(--primary);
  border-radius: 4px 4px 0 0;
}

.chart-bar.zero {
  background: var(--border);
}

.chart-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.chart-value {
  font-size: 12px;
  font-weight: 600;
}

/* ───────────────────────────── Responsive ───────────────────────────── */

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: none;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .content {
    padding: 16px;
  }

  .user-key {
    display: none;
  }

  /* Stacked layout: each control takes a full row of its own. */
  .search {
    width: 100%;
    min-width: 0;
    max-width: none;
    flex-basis: 100%;
  }

  .filters {
    width: 100%;
    flex-basis: 100%;
  }

  .page-head > .btn {
    width: 100%;
    margin-left: 0;
  }

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

  .dl {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }

  .dl dd {
    margin-bottom: 8px;
  }

  /* The reminders table drops to stacked cards on phones. */
  table.responsive thead {
    display: none;
  }

  table.responsive,
  table.responsive tbody,
  table.responsive tr,
  table.responsive td {
    display: block;
    width: 100%;
  }

  table.responsive tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }

  table.responsive td {
    border: 0;
    padding: 3px 0;
  }

  table.responsive td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--text-muted);
    font-size: 12px;
  }

  .row-actions {
    justify-content: flex-start;
    margin-top: 8px;
  }

  .cell-url {
    max-width: 100%;
  }
}
