/* ==========================================================================
   FONTS
   ========================================================================== */

@font-face {
  font-family: 'Maple Mono';
  src: url('/fonts/MapleMono-Regular.ttf.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Maple Mono';
  src: url('/fonts/MapleMono-Bold.ttf.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   BASE
   ========================================================================== */

:root {
  /* Colors */
  --color-text: #1a1a1a;
  --color-text-muted: #888;
  --color-bg: #f5f5f5;
  --color-bg-alt: #f0f0f0;
  --color-surface: #fff;
  --color-border: #d4d4d4;
  --color-border-light: #e0e0e0;
  --color-border-input: #ccc;
  --color-accent: #0057cc;
  --color-accent-hover: #0046a8;
  --color-accent-text: #fff;
  --color-primary: #1a1a1a;
  --color-primary-hover: #333;
  --color-link: #0057cc;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-warning: #f59e0b;
  --color-success: #10b981;
  --color-success-bg: #d1fae5;
  --color-success-text: #065f46;
  --color-warning-bg: #fef3c7;
  --color-warning-text: #92400e;
  --color-error-bg: #f8d7da;
  --color-error-text: #721c24;
  --color-success-badge-bg: #d4edda;
  --color-success-badge-text: #155724;
  --color-shadow: rgba(0, 0, 0, 0.06);
  --color-shadow-heavy: rgba(0, 0, 0, 0.12);
  --color-overlay: rgba(0, 0, 0, 0.5);

  /* Spacing scale (multiples of 0.25rem) */
  --space-xs: 0.25rem;   /* 4px */
  --space-sm: 0.5rem;    /* 8px */
  --space-md: 0.75rem;   /* 12px */
  --space-lg: 1rem;      /* 16px */
  --space-xl: 1.5rem;    /* 24px */
  --space-2xl: 2rem;     /* 32px */

  /* Typography */
  --font-family: "Maple Mono", monospace;
  --font-size-2xs: 0.625rem;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.75rem;
  --font-size-code: 0.8125rem;
  --font-size-base: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;

  /* Border radius */
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;

  /* Focus ring */
  --focus-ring: 2px solid var(--color-text);
  --focus-ring-offset: 2px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-text: #e8e8e8;
    --color-text-muted: #888;
    --color-bg: #1a1a1a;
    --color-bg-alt: #222;
    --color-surface: #1a1a1a;
    --color-border: #333;
    --color-border-light: #333;
    --color-border-input: #333;
    --color-accent: #4d8fff;
    --color-accent-hover: #6aa3ff;
    --color-accent-text: #fff;
    --color-primary: #e8e8e8;
    --color-primary-hover: #ccc;
    --color-link: #4d8fff;
    --color-danger: #f87171;
    --color-danger-hover: #ef4444;
    --color-warning: #fbbf24;
    --color-success: #34d399;
    --color-success-bg: #064e3b;
    --color-success-text: #a7f3d0;
    --color-warning-bg: #78350f;
    --color-warning-text: #fde68a;
    --color-error-bg: #7f1d1d;
    --color-error-text: #fecaca;
    --color-success-badge-bg: #064e3b;
    --color-success-badge-text: #a7f3d0;
    --color-shadow: rgba(0, 0, 0, 0.3);
    --color-shadow-heavy: rgba(0, 0, 0, 0.5);
    --color-overlay: rgba(0, 0, 0, 0.7);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Force font inheritance on form elements (browsers override by default) */
button, input, select, textarea {
  font-family: inherit;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
}

main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

h1 { font-size: var(--font-size-xl); margin-bottom: var(--space-xl); }
h2 { font-size: var(--font-size-xl); margin-bottom: var(--space-xl); }
h3 { font-size: var(--font-size-md); margin-bottom: var(--space-lg); }

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

/* ==========================================================================
   LAYOUT
   ========================================================================== */

/* App layout — top bar + body (sidebar + content) */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Top bar — app switcher */
.top-bar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  background: darken(var(--color-surface), 2%);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.06);
  padding: 0;
  flex-shrink: 0;
  z-index: 200;
}

.top-bar__right {
  display: flex;
  align-items: stretch;
}

.top-bar__left {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.top-bar__link {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--font-size-base);
  font-family: inherit;
  padding: var(--space-md) var(--space-lg);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
  display: flex;
  align-items: center;
}

.top-bar__link:hover {
  color: var(--color-text);
}

.top-bar__favicon {
  width: 1rem;
  height: 1rem;
  margin-right: 0.375rem;
  vertical-align: -0.125rem;
}

.top-bar__add-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1.25rem;
  padding: 0 var(--space-sm);
  display: flex;
  align-items: center;
  line-height: 1;
}

.top-bar__add-btn:hover {
  color: var(--color-text);
}

.top-bar__link.dragging {
  opacity: 0.4;
}

.top-bar__link.drag-over {
  border-left: 2px solid var(--color-text);
}

.top-bar__link.active {
  color: var(--color-accent);
  font-weight: 700;
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.top-bar__divider {
  width: 1px;
  background: var(--color-border);
  flex-shrink: 0;
  align-self: stretch;
}

.top-bar__newsletters {
  display: flex;
  align-items: stretch;
  gap: 0;
}


.top-bar__icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-lg);
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  color: var(--color-text-muted);
}

.top-bar__icon-btn:hover {
  color: var(--color-text);
}

.top-bar__icon-btn.active {
  color: var(--color-accent);
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--color-accent) 15%, transparent);
}

/* Text-style action buttons in nav bars */
.nav-action {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--font-size-base);
  font-family: inherit;
  padding: var(--space-md) var(--space-lg);
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.nav-action:hover {
  color: var(--color-text);
}

.nav-action[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
}

.nav-action--danger {
  color: var(--color-danger);
}

/* App body — sidebar + content, fills remaining space below top bar */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Sidebar — contextual, shown only in newsletter mode */
/* Sidebar resize handle — shared across all left sidebars */
.sidebar-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 0.25rem;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
  background: var(--color-border);
}

.sidebar {
  position: relative;
  width: 14rem;
  flex-shrink: 0;
  background: var(--color-surface);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  box-shadow: 3px 0 0 rgba(0, 0, 0, 0.06);
  z-index: 100;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-lg) 0;
  gap: var(--space-xs);
}

.sidebar__link {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--font-size-base);
  padding: var(--space-sm) var(--space-md);
  transition: color 0.15s;
}

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

.sidebar__link.active {
  color: var(--color-accent);
  font-weight: 700;
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  box-shadow: 3px 0 0 color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.sidebar__divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-sm) var(--space-md);
}


/* Links tab panels */
.links-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}


/* Links layout — sidebar filters + main list */
.links-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Filters sidebar */
.links-filters {
  position: relative;
  width: 14rem;
  flex-shrink: 0;
  padding: 1rem;
  border-right: 1px solid var(--color-border);
  box-shadow: 3px 0 0 rgba(0, 0, 0, 0.06);
  background: var(--color-surface);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.links-filters__search input {
  width: 100%;
  margin-bottom: 0;
}

.search-hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

.search-hint code {
  font-family: inherit;
  opacity: 0.7;
}

.links-filters__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin: 0;
  padding: 0;
  border: none;
}

.links-filters__group select,
.links-filters__group input {
  width: 100%;
  margin-bottom: 0;
  min-width: 0;
}

.links-date-input {
  width: 100%;
  margin-bottom: 0;
}

/* Badge-style filter groups (usage, newsletter, category) */
.filter-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  border: none;
  padding: 0;
  margin: 0;
}

.filter-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-xs);
  border: 1px solid var(--color-border);
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
  background: transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  line-height: 1;
}

.filter-badge:hover {
  color: var(--color-text);
}

/* Hide native checkbox — visual state shown via .filter-badge__check span */
.filter-badge input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.filter-badge__check {
  width: 0.875rem;
  height: 0.875rem;
  border: 1px solid var(--color-border-input);
  background: var(--color-surface);
  flex-shrink: 0;
  display: inline-block;
  padding: 0.55em;
}

.filter-badge input[type="checkbox"]:checked + .filter-badge__check {
  border-color: var(--color-accent);
  background: var(--color-accent) url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 8.5l3.5 3.5 8.5-8'/%3E%3C/svg%3E") center / 0.75rem no-repeat;
}

.filter-badge:has(input:checked) {
  color: var(--color-accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  border-color: var(--color-accent);
}

/* On narrow viewports, filters go above the list */
@container (max-width: 50rem) {
  .links-layout {
    flex-direction: column;
  }

  .links-filters {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    overflow-y: visible;
  }

  .links-filters__search {
    flex: 1;
    min-width: 10rem;
  }

  .links-filters__group {
    flex-direction: row;
    gap: var(--space-xs);
  }

  .links-filters__group select,
  .links-filters__group input {
    width: auto;
  }
}


/* Links main content area */
.links-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: var(--space-xl);
}

/* Toolbar: counter + sort + check/view icons */
.links-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 0 var(--space-sm) 0;
  flex-shrink: 0;
}


.links-toolbar,
.links-toolbar .links-counter,
.links-toolbar .nav-action,
.links-toolbar .btn {
  font-size: var(--font-size-base);
}

.links-toolbar select {
  width: auto;
  margin-bottom: 0;
}

.links-toolbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-left: auto;
}

.links-toolbar__actions .btn svg {
  display: block;
}

/* Global settings tabs */
.global-settings-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Only the sending tab scrolls (settings form can be long) */
#global-tab-sending {
  overflow: auto;
}

#global-tab-sending .settings-content {
  padding-bottom: var(--space-xl);
}


/* Templates layout — left sidebar + editor */
.templates-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.templates-sidebar {
  position: relative;
  width: 12rem;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  box-shadow: 3px 0 0 rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.templates-sidebar__nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-md) 0;
}

.templates-sidebar__link {
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-base);
}

.templates-sidebar__link:hover {
  color: var(--color-text);
  background: var(--color-bg-alt);
}

.templates-sidebar__link.active {
  color: var(--color-accent);
  font-weight: 600;
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--color-accent) 15%, transparent);
}


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

.templates-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.375rem 0.75rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}


.templates-toolbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.templates-toolbar__left select {
  width: auto;
  margin-bottom: 0;
}

.templates-toolbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Usage badges on link cards */
.link-card__usage-badges {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

/* Usage badges (shared base) */
.link-card__usage-badge {
  font-size: 0.75rem;
  padding: 0.1875rem 0.5rem;
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

a.link-card__usage-badge {
  text-decoration: none;
  cursor: pointer;

  &:hover {
    background: var(--color-border);
    color: var(--color-text);
  }
}

.link-card__usage-badge--unused {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-color: var(--color-warning);
}

/* Link picker dialog */
.link-picker {
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.link-picker__header {
  flex-shrink: 0;
  padding: 1.5rem 1.5rem var(--space-md);
}

.link-picker__controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.link-picker__search {
  flex: 1;
  min-width: 10rem;
}

.link-picker__search input {
  margin-bottom: 0;
  width: 100%;
}

.link-picker__controls select {
  width: auto;
  margin-bottom: 0;
  min-width: 10rem;
}

.link-picker__list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  border: 1px solid var(--color-border);
}

.link-picker__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
}

.link-picker__item:last-child {
  border-bottom: none;
}

.link-picker__item:hover {
  background: var(--color-bg-alt);
}

.link-picker__item.is-included {
  background: var(--color-success-bg);
}

.link-picker__item-info {
  flex: 1;
  min-width: 0;
}

.link-picker__item-title {
  font-weight: 500;
  font-size: var(--font-size-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-picker__item-url {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-picker__item-category {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  padding: 0.125rem var(--space-sm);
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.link-picker__item-status {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-success);
  flex-shrink: 0;
}

.link-picker__empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-2xl);
}

/* Content Area */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}


.subnav {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  padding: 0;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.06);
  background: var(--color-surface);
  flex-shrink: 0;
}


/* Inline label + subject in subnav */
.subnav-label {
  display: inline;
  margin: 0;
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
  white-space: nowrap;
  margin-right: var(--space-xs);
}

#subnav-issues .issue-status {
  margin-right: var(--space-md);
}


.subnav__issue-number {
  margin-left: auto;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  padding: var(--space-md) var(--space-lg);
}

/* Issue subject — top of links list */
#issue-subject-area {
  margin-bottom: var(--space-lg);
}

#issue-subject-area h1 {
  margin-bottom: 0;
}

.issue-subject__input {
  width: 100%;
  margin-bottom: 0;
  font-size: var(--font-size-xl);
  font-weight: 600;
  border: none;
  padding: 0;
  background: transparent;
}

.issue-subject__input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.4;
}

.issue-subject__input:focus {
  outline: none;
  border: none;
}

/* Status dots for send test / dry run */
.status-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-border);
  vertical-align: middle;
}

.status-dot.done {
  background: var(--color-success);
}

/* Issue bottom action bar */
.issue-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}


.issue-action-bar__left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.issue-action-bar__left select {
  width: auto;
  margin-bottom: 0;
}

.issue-action-bar__right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Full-height squared back button in subnav */
.subnav-back {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  padding: 0 1rem;
  margin: 0;
  background: none;
  border: none;
  border-right: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-text-muted);
}

.subnav-back:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.subnav-back + * {
  margin-left: var(--space-sm);
}

.subnav-back svg {
  display: block;
}


.subnav-center {
  display: flex;
  gap: 0.5rem;
  flex: 1;
}

/* Fix form elements in nav bars */
.subnav select,
.subnav input,
.nav-tertiary select,
.nav-tertiary input {
  width: auto;
  margin-bottom: 0;
}

.subnav-link {
  padding: var(--space-md) var(--space-lg);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--font-size-base);
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
}

.subnav-link:hover {
  color: var(--color-text);
}

.subnav-link.active {
  color: var(--color-accent);
  font-weight: 600;
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--color-accent) 15%, transparent);
}

/* Tertiary Nav */
.nav-tertiary {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.5rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}


.tertiary-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}


.tertiary-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-status {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.save-status.saving {
  color: var(--color-warning);
}

.save-status.saved {
  color: var(--color-success);
}

/* Main - these styles apply to non-editor pages */
.page {
  max-width: none;
  padding: var(--space-xl);
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}


/* Pages that manage their own padding */
#page-links,
#page-all-links,
#page-issues,
#page-global-settings,
#page-settings {
  padding: 0;
}

/* Full-height editor mode for templates */
body.editor-mode main {
  max-width: none;
  padding: 0;
  flex: 1;
  overflow: hidden;
}

body.editor-mode .content-area {
  min-height: 0;
}

body.editor-mode .page {
  padding: 0;
}

body.editor-mode .settings-content {
  max-width: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.editor-mode .settings-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
}

body.editor-mode .settings-panel.hidden {
  display: none;
}

body.editor-mode .settings-panel h2,
body.editor-mode .settings-panel .subtitle,
body.editor-mode .settings-panel .template-vars,
body.editor-mode .settings-panel .template-header,
body.editor-mode .settings-panel .editor-actions {
  display: none;
}

body.editor-mode .page-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.editor-mode .page-editor > label,
body.editor-mode .page-editor > select {
  display: none;
}

body.editor-mode .CodeMirror {
  flex: 1;
  height: auto;
  min-height: 0;
  border-radius: 0;
  border: none;
}

/* Template Split Layout */
body.editor-mode .template-split {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
}

body.editor-mode .template-editor-pane {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  min-width: 18.75rem;
  min-height: 0;
}

body.editor-mode .template-editor-pane .CodeMirror {
  flex: 1;
  height: 100%;
}

/* Template variables — floating popover */
.template-vars-wrap {
  position: relative;
}

.template-vars-toggle {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 5;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.25rem;
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-vars-toggle:hover {
  color: var(--color-text);
  background: var(--color-bg-alt);
}

.template-vars-bar {
  display: none;
  position: absolute;
  top: 2.25rem;
  right: 0.5rem;
  z-index: 10;
  padding: 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 0.25rem 1rem var(--color-shadow);
  font-size: var(--font-size-sm);
  line-height: 1.8;
  max-width: 24rem;
}

.template-vars-bar.is-open {
  display: block;
}

.template-vars-bar strong {
  margin-right: 0.5rem;
}

.template-vars-bar code {
  background: var(--color-bg-alt);
  padding: 0.125rem 0.375rem;
  border-radius: 0;
  margin-left: 0.25rem;
  font-size: var(--font-size-xs);
  white-space: nowrap;
  cursor: pointer;
}

.template-vars-bar code:hover {
  background: var(--color-border);
}

body.editor-mode .template-resize-handle {
  width: 0.25rem;
  cursor: col-resize;
  flex-shrink: 0;
}

body.editor-mode .template-resize-handle:hover,
body.editor-mode .template-resize-handle.dragging {
  background: var(--color-border);
}

body.editor-mode .template-preview-pane {
  flex: 1;
  min-width: 15.625rem;
  background: var(--color-surface);
  overflow: hidden;
}

body.editor-mode .template-preview-pane iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Subpages */

/* Issues page as flex container */
#page-issues {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Issue list landing page */
#subpage-issue-list {
  flex: 1;
  overflow: auto;
  background: var(--color-bg);
}

/* Links subpage - full width/height */
#subpage-links {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--color-bg);
}


/* Compose subpage - full width/height */
#subpage-compose {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--color-bg);
}



.links-scroll-wrapper {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

#subpage-links .links-scroll-wrapper {
  padding: var(--space-xl);
}

.links-content {
  padding: 0;
}

/* Pagination */
.links-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
}

.links-pagination__info {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* Picker inline add form — inside sticky footer */
.link-picker__add-form {
  display: flex;
  gap: var(--space-sm);
  flex: 1;

  & input {
    flex: 1;
    margin-bottom: 0;
    min-width: 12rem;
  }
}

.links-counter {
  color: var(--color-text-muted);
  font-size: var(--font-size-base);
  margin: 0;
}

/* Compose Split Layout */
.compose-split {
  display: flex;
  flex: 1;
  min-height: 0;
}

.compose-split .editor-pane {
  flex: 0 0 70%;
  display: flex;
  flex-direction: column;
  min-width: 18.75rem;
  background: var(--color-surface);
}


.compose-split .editor-pane .md-helpers {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border-light);
  margin: 0;
  flex-shrink: 0;
}

.compose-split .editor-pane textarea {
  flex: 1;
  border: none;
  border-radius: 0;
  resize: none;
  margin: 0;
  min-height: 0;
}

.compose-split .editor-pane .CodeMirror {
  flex: 1;
  height: auto;
  min-height: 0;
  border: none;
  border-radius: 0;
}

.compose-split .resize-handle {
  width: 0.25rem;
  cursor: col-resize;
  flex-shrink: 0;
}

.compose-split .resize-handle:hover,
.compose-split .resize-handle.dragging {
  background: var(--color-border);
}

.compose-split .preview-pane {
  flex: 1;
  min-width: 15.625rem;
  border-radius: 0;
  border: none;
  box-shadow: none;
  overflow: hidden;
}

.compose-split .preview-pane iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Sent issue view — full-width preview, no editor */
.compose-split.sent-view {
  overflow: hidden;
}

.compose-split.sent-view .preview-pane {
  flex: 1;
  overflow: hidden;
}

.compose-split.sent-view .preview-pane iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.settings-content {
  max-width: 50rem;
  padding: var(--space-xl);
}

/* ==========================================================================
   MODULES
   ========================================================================== */

/* Card */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--color-border);
}

/* Button */
.btn {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-base);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { background: var(--color-bg-alt); }

/* Primary CTA — filled accent blue */
.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: var(--color-accent);
}
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn-small { padding: 0.375rem 0.75rem; font-size: var(--font-size-code); }
.btn-icon { aspect-ratio: 1; padding: 0.375rem; display: inline-flex; align-items: center; justify-content: center; }
.select-small { padding: 0.25rem 2rem 0.25rem 0.5rem; font-size: var(--font-size-sm); }
.btn-secondary { border-color: transparent; color: var(--color-text-muted); }
.btn-secondary:hover { color: var(--color-text); background: var(--color-bg-alt); border-color: transparent; }
.btn-danger { border: 1px solid var(--color-danger); color: var(--color-danger); background: transparent; }
.btn-danger:hover { color: var(--color-danger-hover); border-color: var(--color-danger-hover); background: transparent; }

/* Aria-disabled state - keeps button focusable but visually muted */
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Form elements */
input, select, textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  margin-bottom: 0.75rem;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 0.75rem;
  padding-right: 2rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-text);
}

textarea {
  min-height: 7.5rem;
  resize: vertical;
  font-family: monospace;
}

/* CodeMirror Overrides */
.CodeMirror {
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-md);
  font-size: var(--font-size-code);
  height: auto;
  min-height: 9.375rem;
}

.settings-panel .CodeMirror,
.page-editor .CodeMirror {
  min-height: 25rem;
}

.editor-pane .CodeMirror {
  min-height: 25rem;
}

dialog .CodeMirror {
  min-height: 7.5rem;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
  font-size: var(--font-size-base);
}

label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  margin: 1rem 0;
  cursor: pointer;
}

label.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.form-row input { flex: 1; }
.form-row button { flex-shrink: 0; margin-bottom: 0.75rem; }
.form-row-field { flex: 1; }

/* Stat card */
/* Markdown helpers */
.md-helpers {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.md-helpers button {
  padding: 0.25rem 0.5rem;
  font-size: var(--font-size-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.md-helpers button:hover { background: var(--color-border); }

/* Editor */
.editor-actions { display: flex; gap: 0.75rem; }

/* Preview */
.preview-pane {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.preview-pane iframe {
  width: 100%;
  height: 37.5rem;
  border: none;
}

.template-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.template-header select {
  min-width: 12.5rem;
}

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

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}

th {
  background: var(--color-bg-alt);
  font-weight: 500;
  font-size: var(--font-size-code);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

td button { padding: 0.25rem 0.75rem; font-size: var(--font-size-sm); }

/* Dialog (native <dialog> element) */
dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0;
  width: 25rem;
  max-width: 90%;
  max-height: 80dvh;
  box-shadow: 0 0.25rem 1rem var(--color-shadow);
  background: var(--color-surface);
  color: var(--color-text);
  /* Restore auto margin killed by * reset — needed for native centering */
  margin: auto;
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog::backdrop {
  background: var(--color-overlay);
}

/* Sticky header */
dialog h2,
dialog .link-picker__header h2 {
  margin: 0;
}

dialog > h2 {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  padding: 1.5rem 1.5rem 1rem;
  z-index: 1;
  flex-shrink: 0;
}

dialog > p {
  padding: 0 1.5rem;
  margin: 0 0 var(--space-sm) 0;
}

/* Scrollable body — form or modal-content */
dialog > form,
dialog > .modal-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-height: 0;
  padding: 0;
}

/* The scrollable middle area */
dialog > form {
  overflow-y: auto;
  padding: 0 1.5rem;
}

dialog > .modal-content {
  overflow: hidden;
}

/* Link picker: scrollable list */
.link-picker__list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 1.5rem;
}

/* Sticky footer actions — box-shadow gives full-width top separator without negative margins */
.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 1.5rem;
  background: var(--color-surface);
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
  box-shadow: 0 -1px 0 var(--color-border-light);
}

dialog.modal-wide { width: 31.25rem; }
dialog.link-picker-dialog { width: 56rem; }

dialog.link-picker-dialog .modal-actions {
  justify-content: space-between;
}


/* Settings/Templates panels */
.settings-panel h2 { margin: 0 0 1.25rem 0; }

/* Logo upload */
.logo-upload-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.logo-preview {
  width: 7.5rem;
  height: 3.75rem;
  border: 1px dashed var(--color-border-input);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-alt);
  overflow: hidden;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-preview:empty::before {
  content: 'No logo';
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.logo-upload-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Page settings — theme and string overrides */
.settings-fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-lg);

  & legend {
    font-weight: 500;
    font-size: var(--font-size-sm);
    padding: 0 var(--space-xs);
    color: var(--color-text-muted);
  }

  & details {
    border-top: 1px solid var(--color-border);
    padding: var(--space-sm) 0;

    &:first-of-type {
      border-top: none;
      padding-top: 0;
    }

    &:last-of-type {
      padding-bottom: 0;
    }

    & summary {
      cursor: pointer;
      font-size: var(--font-size-sm);
      font-weight: 500;
      user-select: none;
      list-style: none;
      display: flex;
      align-items: center;
      gap: var(--space-xs);

      &::before {
        content: '▶';
        font-size: 0.6em;
        transition: transform 0.15s;
      }
    }

    &[open] summary::before {
      transform: rotate(90deg);
    }
  }

  & .settings-fieldset__body {
    margin-top: var(--space-sm);
  }
}

/* Color theme row — two side-by-side color fields */
.settings-color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.settings-color-field {
  & label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-bottom: var(--space-xs);
  }
}

/* Color swatch + text input side by side */
.color-input-row {
  display: flex;
  gap: var(--space-xs);
  align-items: center;

  & input[type="color"] {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0.125rem;
    border: 1px solid var(--color-border-input);
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    background: none;
  }

  & input[type="text"] {
    flex: 1;
    min-width: 0;
  }
}

/* Provider config */
.provider-select {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.provider-select label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: normal;
  cursor: pointer;
  white-space: nowrap;
}
.provider-select input[type="radio"] {
    margin-bottom: 0;
}

.provider-config {
  background: var(--color-bg-alt);
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}

.subtitle {
  color: var(--color-text-muted);
  margin-bottom: 1.25rem;
}

/* Categories list */
.categories-list {
  list-style: none;
  margin: 0 0 1rem 0;
  padding: 0;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  cursor: grab;
}

.category-item:active { cursor: grabbing; }

.category-item.dragging {
  opacity: 0.5;
  background: var(--color-border);
}

.category-item .drag-handle {
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
}

.category-item .category-name {
  flex: 1;
  font-weight: 500;
}

.category-item .category-id {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  background: var(--color-border-light);
  padding: 0.125rem 0.5rem;
  border-radius: 0;
}

.category-item .category-actions {
  display: flex;
  gap: 0.5rem;
}

.category-item .category-actions button {
  padding: 0.25rem 0.625rem;
  font-size: var(--font-size-sm);
}

/* Page header with action */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-header h1 {
  margin: 0;
}

/* Issue list page */
.issue-list-content {
  padding: var(--space-xl);
}

.issue-cards {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.issue-card {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-light);
}

.issue-card:last-child {
  border-bottom: none;
}

.issue-card:hover {
  filter: brightness(0.97);
}

/* Issue card number column with badge */
.issue-card-number-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  min-width: 3.5rem;
}

.issue-card-number {
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
  font-weight: 500;
}

.issue-card-badge {
  font-size: var(--font-size-xs);
  padding: 0.0625rem 0.375rem;
}

.issue-card-badge--draft {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

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

.issue-card-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.issue-card-title:empty::before {
  content: 'Untitled';
  color: var(--color-text-muted);
  font-style: italic;
}

.issue-card-meta {
  display: flex;
  gap: 1rem;
  font-size: var(--font-size-code);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.issue-card-meta span {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.issue-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}

.issue-card-actions .btn {
  min-width: auto;
  text-align: center;
}

.issue-card-actions .btn-icon {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-md);
  line-height: 1;
}

.issue-status {
  font-size: var(--font-size-code);
  padding: 0.25rem 0.625rem;
  border-radius: 0;
  background: var(--color-border);
}

.issue-status.draft {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.issue-status.sent {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

/* Link cards grid */
.link-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 2rem;
  padding-bottom: 1rem;
}

.link-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1rem;
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Extra left padding for cards with drag handles */
.link-card[draggable="true"] {
  padding-left: 2rem;
}

.link-card.dragging {
  opacity: 0.8;
  transform: scale(1.02) rotate(1deg);
  box-shadow: 0 0.5rem 1.5rem var(--color-shadow-heavy);
  z-index: 100;
}

.link-card.drag-over {
  border: 2px dashed var(--color-text);
  background: var(--color-surface);
}

/* Drag handle: left side of card, aligned with title */
.link-card .drag-handle {
  position: absolute;
  top: 1rem;
  left: 0.5rem;
  color: var(--color-border-input);
  font-size: 1rem;
  cursor: grab;
  padding: 0.25rem;
}

.link-card .drag-handle:active {
  cursor: grabbing;
}

.link-card-content {
  flex: 1;
  min-width: 0;
}

.link-card h4 {
  margin: 0 0 0.25rem 0;
  font-weight: 400;
}

.link-card h4 a {
  color: var(--color-text);
  text-decoration: none;
}

.link-card h4 a:hover { text-decoration: underline; }

.link-card .meta {
  color: var(--color-text-muted);
  font-size: var(--font-size-code);
}

.link-card .editable-meta:empty::before {
  content: 'Add meta (e.g. video, 5 min)';
  color: var(--color-text-muted);
  opacity: 0.5;
}

/* Inline editable fields */
.link-card .editable {
  cursor: text;
  padding: 0.125rem 0.25rem;
  margin: -0.125rem -0.25rem;
  border-radius: 0;
  border: 1px solid transparent;
}

.link-card .editable:hover {
  background: var(--color-surface);
}

.link-card .editable:focus {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
  background: var(--color-surface);
  border-color: var(--color-text);
}

.link-card .editable-title {
  display: block;
}

/* Stats page */
.stats-content {
  padding: var(--space-xl);
  max-width: 56rem;
}

.stats-summary {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
  font-size: var(--font-size-md);
}

.stats-summary__total {
  font-weight: 600;
}

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

.stats-links {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.stats-link {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.stats-link__rank {
  width: 2rem;
  text-align: center;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

.stats-link__info {
  flex: 1;
  min-width: 0;
}

.stats-link__title {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: 0.25rem;
}

.stats-link__title a {
  color: var(--color-text);
  text-decoration: underline;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-link__category {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: var(--color-bg-alt);
  padding: 0.0625rem 0.375rem;
  flex-shrink: 0;
}

.stats-link__bar-wrap {
  height: 0.375rem;
  background: var(--color-border-light);
  border-radius: 0;
  overflow: hidden;
}

.stats-link__bar {
  height: 100%;
  background: var(--color-text);
  border-radius: 0;
  min-width: 1px;
}

.stats-link__clicks {
  font-weight: 600;
  font-size: var(--font-size-md);
  min-width: 3rem;
  text-align: right;
  flex-shrink: 0;
}

/* Click count badge on link cards */
.link-card__clicks {
  color: var(--color-text-muted);
  background: var(--color-bg-alt);
  padding: 0.1875rem 0.5rem;
  border: 1px solid var(--color-border);
}

.link-card .url-row {
  font-size: var(--font-size-sm);
  margin-top: 0.125rem;
}

.link-card .editable-url {
  color: var(--color-text-muted);
  font-family: monospace;
  word-break: break-all;
}

.link-card .editable-description {
  display: block;
  margin-top: 0.5rem;
  font-size: var(--font-size-base);
  color: var(--color-primary-hover);
  min-height: 1.5em;
}

.link-card .editable-description:empty::before {
  content: 'Add description...';
  color: var(--color-text-muted);
}

.link-card .editable-reading-time {
  min-width: 2.5rem;
}

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


.link-card .actions,
.link-card-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 0.75rem;
  margin-top: auto;
  font-size: 0.75rem;
}

/* Uniform sizing for all interactive elements in action bar */
.link-card-actions .btn,
.link-card-actions select,
.link-card-actions .link-card__usage-badge,
.link-card-actions .link-card__clicks,
.link-card-actions .link-card__date,
.link-card-actions .url-status {
  font-size: 0.75rem;
  padding: 0.1875rem 0.5rem;
  line-height: 1.4;
  margin-bottom: 0;
  box-sizing: border-box;
}

.link-card-actions select {
  width: auto;
  min-width: 6.25rem;
  height: auto;
}

.link-card-actions .move-to-issue-select {
  min-width: 7.5rem;
}

/* URL status indicator */
.url-status {
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 0.125rem 0.375rem;
  border-radius: 0;
  min-width: 2.5rem;
  text-align: center;
}

.url-status:empty {
  display: none;
}

.url-status.checking {
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
}

.url-status.status-ok {
  background: var(--color-success-badge-bg);
  color: var(--color-success-badge-text);
}

.url-status.status-error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

/* Compact view toggle */
.links-view-toggle {
  display: flex;
  gap: 0;
}

.links-view-toggle .btn {
  border-radius: 0;
}

.links-view-toggle .btn:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.links-view-toggle .btn:last-child {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.links-view-toggle .btn.active {
  background: var(--color-text);
  color: var(--color-bg);
}

.links-view-toggle .btn:not(.active) {
  background: var(--color-surface);
  color: var(--color-primary-hover);
}

/* Collapse button — hidden by default, shown in compact expanded cards */
.link-card__collapse {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0.25rem;
  line-height: 1;
  flex-shrink: 0;
}

.link-card__collapse:hover {
  color: var(--color-text);
}

/* Compact-end: usage badges + category — only visible in compact mode */
.link-card__compact-end {
  display: none;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
  font-size: 0.75rem;
}

.link-card__compact-end select,
.link-card__compact-end .btn,
.link-card__compact-end .link-card__usage-badge {
  font-size: 0.75rem;
  padding: 0.1875rem 0.5rem;
}

.link-card__compact-end select {
  width: auto;
  margin-bottom: 0;
}

/* Compact/minimized link cards */
.link-cards.compact .link-card {
  padding: 0.375rem 0.625rem;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.link-cards.compact .link-card-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.link-cards.compact .link-card h4 {
  margin: 0;
  font-size: var(--font-size-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-cards.compact .link-card .url-row,
.link-cards.compact .link-card .editable-description,
.link-cards.compact .link-card-actions {
  display: none;
}

/* Chevron visible in compact mode — far right, rotated down when collapsed */
.link-cards.compact .link-card .link-card__collapse {
  display: flex;
  order: 99;
  margin-left: auto;
  flex-shrink: 0;
  transform: rotate(180deg);
}

/* Show meta inline after title in compact mode */
.link-cards.compact .link-card .meta {
  display: flex;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.link-cards.compact .link-card__compact-end {
  display: flex;
}

/* Expanded card in compact mode */
.link-cards.compact .link-card.is-expanded {
  padding: 0.625rem;
  flex-direction: column;
  align-items: stretch;
  cursor: default;
  position: relative;
}

.link-cards.compact .link-card.is-expanded .link-card-content {
  display: block;
}

.link-cards.compact .link-card.is-expanded .link-card__collapse {
  position: absolute;
  top: 0.75rem;
  right: 0.625rem;
  margin-left: 0;
  transform: rotate(0deg);
}

.link-cards.compact .link-card.is-expanded h4 {
  margin: 0 0 0.25rem 0;
}

.link-cards.compact .link-card.is-expanded .url-row,
.link-cards.compact .link-card.is-expanded .meta,
.link-cards.compact .link-card.is-expanded .editable-description,
.link-cards.compact .link-card.is-expanded .link-card-actions {
  display: flex;
}

.link-cards.compact .link-card.is-expanded .editable-description {
  display: block;
}

.link-cards.compact .link-card.is-expanded .link-card__compact-end {
  display: none;
}

.link-cards.compact .link-card.is-expanded h4 {
  white-space: normal;
  overflow: visible;
}

/* Title alignment: match collapsed padding so title stays in same spot */
.link-cards.compact .link-card.is-expanded .link-card-content {
  padding-right: 2rem;
}

/* Compact collapsed: drag handle inline in flex row */
.link-cards.compact .link-card .drag-handle {
  position: static;
  order: -1;
  padding: 0;
  font-size: var(--font-size-base);
}

/* Compact expanded: drag handle back to absolute left, with room for it */
.link-cards.compact .link-card.is-expanded:has(.drag-handle) {
  padding-left: 2rem;
}

.link-cards.compact .link-card.is-expanded .drag-handle {
  position: absolute;
  top: 0.625rem;
  left: 0.5rem;
  padding: 0.25rem;
}

/* Category sections on links page */
.category-section {
  margin-bottom: 2rem;
  padding-top: 0.5rem;
}

.category-section h3 {
  font-size: var(--font-size-base);
  text-transform: uppercase;
  color: var(--color-text-muted);
  letter-spacing: 0.03125rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-light);
}

/* Compact mode: tighter spacing between headings and cards */
.link-cards.compact + .category-section,
.link-cards.compact ~ .category-section {
  margin-top: 1rem;
}

.link-cards.compact .category-section {
  margin-bottom: 1rem;
}

.link-cards.compact .category-section h3 {
  margin-bottom: 0.375rem;
  padding-bottom: 0.25rem;
}

.link-cards.compact {
  gap: 0.375rem;
}

/* ==========================================================================
   STATE
   ========================================================================== */

/* Screen reader only - visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden:not(dialog) { display: none !important; }
[hidden] { display: none; }
.active { } /* defined per module */

.empty-state {
  color: var(--color-text-muted);
  padding: var(--space-xl) 0;
}
.issue-cards .empty-state {
    padding: var(--space-xl);
}

.empty-state p {
  margin-bottom: var(--space-md);
}

#test-result {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
}

#test-result.success { background: var(--color-success-badge-bg); color: var(--color-success-badge-text); }
#test-result.error { background: var(--color-error-bg); color: var(--color-error-text); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .app-body {
    flex-direction: column;
  }

  .sidebar__nav {
    flex-direction: row;
    flex: 1;
    overflow-x: auto;
    padding: var(--space-sm) 0;
    gap: var(--space-xs);
  }

  .sidebar__link {
    white-space: nowrap;
  }

  .provider-select { flex-direction: column; gap: 0.5rem; }
}

/* Login screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--color-surface);
}

.login-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0;
  padding: 2rem;
  width: 100%;
  max-width: 24rem;
}

.login-form h1 {
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: var(--font-size-base);
  font-weight: 500;
}

.login-form input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--color-border-input);
  border-radius: 0;
  font-size: 1rem;
  margin-bottom: 1rem;
  box-sizing: border-box;
}

.login-form .btn {
  width: 100%;
}

.login-error {
  color: var(--color-danger);
  font-size: var(--font-size-base);
  margin: -0.5rem 0 1rem;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 4rem;
  right: 1.5rem;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0;
  padding: 0.75rem 1rem;
  box-shadow: 0 0.25rem 0.75rem var(--color-shadow);
  font-size: var(--font-size-base);
  max-width: 24rem;
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}

.toast--error {
  border-color: var(--color-danger);
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.toast--success {
  border-color: var(--color-success);
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.toast--warning {
  border-color: var(--color-warning);
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.toast--out {
  animation: toast-out 0.15s ease-in forwards;
}

.subscribe-url {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  text-decoration: underline;
  cursor: pointer;
}

.subscribe-url:hover {
  color: var(--color-text);
}

/* Subscriber status badges */
.sub-status {
  font-size: var(--font-size-xs);
  padding: 0.125rem 0.5rem;
  border-radius: 0;
}

.sub-status--confirmed {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.sub-status--pending {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.sub-status--bounced {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.sub-status--complained {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.sub-status--unsubscribed {
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
}

.sub-row--inactive {
  opacity: 0.6;
}

/* ==========================================================================
   NEWSLETTER ALL LINKS PAGE
   ========================================================================== */


/* ==========================================================================
   DUPLICATE LINK WARNING BADGE
   ========================================================================== */

.link-card__duplicate-badge {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: var(--color-bg-alt);
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  white-space: nowrap;
}

/* ==========================================================================
   MOVE BUTTONS — keyboard accessible link reordering
   ========================================================================== */


/* ==========================================================================
   SUBSCRIBER FILTERS
   ========================================================================== */

.subscriber-filters {
  display: flex;
  gap: var(--space-sm);
  padding: 0 var(--space-xl);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

.subscriber-filter__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-family: inherit;
  cursor: pointer;
}

.subscriber-filter__btn:hover {
  color: var(--color-text);
  background: var(--color-bg-alt);
}

.subscriber-filter__btn--active {
  color: var(--color-accent);
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
  font-weight: 700;
}

.subscriber-filter__btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

.subscriber-filter__count {
  font-size: var(--font-size-2xs);
  color: var(--color-text-muted);
}

.subscriber-filter__btn--active .subscriber-filter__count {
  color: var(--color-accent);
}

/* Bounce detail row */
.sub-row--bounce-detail td {
  padding-top: 0;
  font-size: var(--font-size-xs);
}

.sub-bounce-reason {
  color: var(--color-text-muted);
  font-style: italic;
}

/* ==========================================================================
   SCHEDULE UI
   ========================================================================== */

.schedule-area {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.schedule-area__input {
  font-family: inherit;
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border-input);
  background: var(--color-surface);
  color: var(--color-text);
}

.schedule-area__input:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

.schedule-area__info {
  font-size: var(--font-size-sm);
  color: var(--color-success-text);
  background: var(--color-success-bg);
  padding: var(--space-xs) var(--space-sm);
  white-space: nowrap;
}

/* ==========================================================================
   BULK ACTION BAR
   ========================================================================== */

.bulk-action-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  margin-top: var(--space-sm);
}

.bulk-action-bar__count {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Checkbox in link cards for bulk selection */
.link-card__select-checkbox {
  align-self: center;
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

/* Selected state for link cards */
.link-card--selected {
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-surface));
  outline: 1px solid var(--color-accent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}
