/*
 * Cockpit design system
 *
 * Mobile-first, plain modern CSS served via Propshaft (no build step).
 * All design decisions live in the custom properties below — components
 * reference tokens, never raw values.
 */

:root {
  /* Color */
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-border: #e4e7ec;
  --color-text: #101828;
  --color-text-muted: #667085;
  --color-primary: #1d4ed8;
  --color-primary-contrast: #ffffff;
  --color-danger: #b42318;
  --color-success: #067647;

  /* Typography */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  /* Spacing & shape */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --radius: 0.75rem;
  --shadow-card: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.1);

  /* Layout */
  --content-max-width: 72rem;
}

/* --- Reset & base ------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

h1,
h2,
h3 {
  line-height: 1.2;
  margin-block: 0 var(--space-3);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

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

/* --- Accessibility ------------------------------------------------------ */

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--color-surface);
  padding: var(--space-2) var(--space-4);
  z-index: 100;
}

.skip-link:focus {
  left: var(--space-2);
}

/* --- Header ------------------------------------------------------------- */

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.site-header__inner {
  max-width: var(--content-max-width);
  margin-inline: auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.site-header__brand {
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--color-text);
  text-decoration: none;
}

/* --- Main --------------------------------------------------------------- */

.site-main {
  max-width: var(--content-max-width);
  margin-inline: auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}

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

.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-2) var(--space-4);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

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

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

.btn--wide {
  width: 100%;
}

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

.flash {
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-3) var(--space-4);
  margin-block-end: var(--space-4);
  font-size: var(--text-sm);
}

.flash--notice {
  background: #ecfdf3;
  color: var(--color-success);
  border: 1px solid #abefc6;
}

.flash--alert {
  background: #fef3f2;
  color: var(--color-danger);
  border: 1px solid #fecdca;
}

/* --- Header user area ----------------------------------------------------- */

.site-header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.site-header__user {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

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

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-8) var(--space-6);
  max-width: 24rem;
  margin: 10vh auto 0;
  text-align: center;
}

.login-card__note {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-block: 0 var(--space-6);
}

/* --- Utilities ------------------------------------------------------------ */

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

.text-sm {
  font-size: var(--text-sm);
}

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

/* --- Page head ------------------------------------------------------------ */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-block-end: var(--space-6);
}

.page-head h1 {
  margin: 0;
}

.page-head__actions {
  display: flex;
  gap: var(--space-2);
}

.site-header__link {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-sm);
}

/* --- Card list (admin) ------------------------------------------------------ */

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.card-list__item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}

.card-list__item p {
  margin: var(--space-1) 0 0;
}

.card-list__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

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

.form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  max-width: 40rem;
  display: grid;
  gap: var(--space-4);
}

.form__field {
  display: grid;
  gap: var(--space-1);
  border: none;
  margin: 0;
  padding: 0;
}

/* Grid items must be allowed to shrink below their intrinsic width,
   otherwise wide content (e.g. the Trix editor) stretches the column. */
.form > *,
.form__field > * {
  min-width: 0;
}

trix-toolbar,
trix-editor {
  max-width: 100%;
}

/* We don't render captions, so hide the caption UI (filename/size,
   "Add a caption") inside the editor as well. */
trix-editor figcaption {
  display: none;
}

/* --- Language tabs (post form) ---------------------------------------------- */

.locale-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-block-end: var(--space-3);
}

.locale-tabs__tab {
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.locale-tabs__tab.is-active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.locale-tabs__panel {
  display: grid;
  gap: var(--space-4);
}

.locale-tabs__panel[hidden] {
  display: none;
}

.locale-tabs__translate {
  align-items: center;
  flex-wrap: wrap;
}

.locale-switcher select {
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-1) var(--space-2);
  font: inherit;
  font-size: var(--text-sm);
  background: var(--color-surface);
}

.form__field label,
.form__field legend {
  font-weight: 600;
  font-size: var(--text-sm);
}

.form__field input[type="text"],
.form__field input[type="number"] {
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-2) var(--space-3);
  font: inherit;
}

.form__actions {
  display: flex;
  gap: var(--space-2);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: var(--space-1) var(--space-3);
  max-height: 20rem;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-3);
}

.checkbox-grid__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

/* --- Audience fields -------------------------------------------------------- */

.audience-fields__section {
  margin-block-start: var(--space-2);
}

.audience-fields__section summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  padding-block: var(--space-1);
}

.audience-fields__section .checkbox-grid {
  margin-block-start: var(--space-2);
}

.audience-fields__count {
  color: var(--color-text-muted);
  font-weight: 400;
}

.audience-fields__summary {
  margin-block-start: var(--space-3);
}

/* --- Dashboard ------------------------------------------------------------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(20rem, 100%), 1fr));
  gap: var(--space-4);
  align-items: start;
}

.widget-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);

  /* All widgets share one height; long content scrolls inside the body. */
  height: 24rem;
  display: flex;
  flex-direction: column;
}

.widget-card__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.widget-card--placeholder {
  display: grid;
  place-items: center;
}

.widget-card__header h2 {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  font-weight: 600;
  margin-block-end: var(--space-3);
}

.widget-welcome__greeting {
  font-size: var(--text-xl);
  font-weight: 700;
  margin-block: 0 var(--space-2);
}

.card-list__item--muted {
  opacity: 0.6;
}

/* --- Post widgets ------------------------------------------------------------ */

.widget-posts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-4);
}

/* Grid items default to min-width auto and would refuse to shrink below
   the intrinsic width of images/code blocks inside them. */
.widget-posts__item {
  min-width: 0;
}

.widget-posts__title {
  font-size: var(--text-base);
  margin-block-end: var(--space-1);
}

.widget-posts__meta {
  margin-block: 0 var(--space-1);
}

.widget-posts__body p {
  margin-block: 0 var(--space-2);
  font-size: var(--text-sm);
}

/* Embedded images never grow wider than their container. */
figure.attachment {
  margin: 0 0 var(--space-2);
}

figure.attachment img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

/* Code blocks scroll horizontally instead of overflowing their card. */
pre {
  overflow-x: auto;
  max-width: 100%;
  padding: var(--space-2);
  border-radius: 6px;
  background: var(--color-bg);
  font-size: var(--text-sm);
}

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

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.badge--published {
  color: var(--color-success);
  border-color: #abefc6;
  background: #ecfdf3;
}

.badge--scheduled {
  color: var(--color-primary);
  border-color: #b2ccff;
  background: #eff4ff;
}

.widget-calendar {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.widget-calendar__item {
  display: flex;
  gap: var(--space-3);
}

.widget-calendar__time {
  flex-shrink: 0;
  min-width: 7.5rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding-block-start: 0.1em;
}

.widget-birthdays {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.widget-birthdays__item {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}

.widget-birthdays__today {
  font-weight: 600;
}

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

.badge--hidden {
  color: var(--color-text-muted);
  border-color: var(--color-border);
  background: var(--color-surface-muted, #f2f4f7);
}

.badge--expired {
  color: var(--color-danger);
  border-color: #fecdca;
  background: #fef3f2;
}

/* --- AI panel -------------------------------------------------------------------- */

.ai-panel {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.ai-panel textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-2) var(--space-3);
  font: inherit;
}

.form__field textarea,
.form__field select,
.form__field input[type="datetime-local"] {
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  background: var(--color-surface);
}

/* --- Admin nav --------------------------------------------------------------- */

.admin-nav {
  display: flex;
  gap: var(--space-4);
  margin-block-end: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  padding-block-end: var(--space-2);
}

.admin-nav__link {
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
