/* ============================================================
   AMflow — UI components
   Built on the tokens in main.css. Theme-aware: everything
   uses --color-* tokens, never hardcoded brand colours.
   ============================================================ */

/* ---------- Card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.card-title { font-size: 1.05rem; margin-bottom: 4px; }

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

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.page-header p { margin: 2px 0 0; color: var(--color-text-muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, box-shadow 0.12s, border-color 0.12s;
}

.btn-primary {
  background: var(--gradient-brand);
  color: #fff;
  box-shadow: var(--shadow-brand);
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover { border-color: var(--color-primary); color: var(--color-primary); }

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

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }

.btn-sm { padding: 5px 11px; font-size: 0.82rem; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-primary { background: var(--color-primary-tint); color: var(--color-primary-hover); }
.badge-success { background: color-mix(in srgb, var(--color-success) 16%, #fff); color: #0a7a37; }
.badge-warning { background: color-mix(in srgb, var(--color-warning) 20%, #fff); color: #9a6500; }
.badge-danger  { background: color-mix(in srgb, var(--color-danger) 16%, #fff); color: #b3282d; }
.badge-neutral { background: var(--color-bg); color: var(--color-text-muted); border: 1px solid var(--color-border); }

/* Important marker (the VDV "*" — printed daily for the CEO) */
.badge-important { background: var(--color-warning); color: #fff; }

/* ---------- Forms ---------- */
.field { margin-bottom: var(--space); }

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 5px;
}

.input, .select, .textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}

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

.textarea { min-height: 90px; resize: vertical; }

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

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }

.table th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  padding: 7px 10px;
  border-bottom: 1px solid var(--color-border);
}

.table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--color-border);
}

.table tbody tr:hover { background: var(--color-bg); }

/* ---------- Alerts / flash ---------- */
.alert {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.alert-success { background: color-mix(in srgb, var(--color-success) 10%, #fff); border-color: color-mix(in srgb, var(--color-success) 35%, #fff); }
.alert-warning { background: color-mix(in srgb, var(--color-warning) 12%, #fff); border-color: color-mix(in srgb, var(--color-warning) 38%, #fff); }
.alert-danger  { background: color-mix(in srgb, var(--color-danger) 9%, #fff); border-color: color-mix(in srgb, var(--color-danger) 32%, #fff); }
.alert-info    { background: var(--color-primary-soft); border-color: var(--color-primary-tint); }

/* ---------- Style guide helpers ---------- */
.swatch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.swatch {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 0.78rem;
}

.swatch-color { height: 56px; }
.swatch-label { padding: 7px 9px; }
.swatch-label code { color: var(--color-text-muted); }

/* ---------- Flash messages ---------- */
.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: var(--space);
}

/* ---------- Form layout ---------- */
.form-actions { display: flex; gap: 10px; align-items: center; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.88rem;
}

.checkbox-row input { width: 16px; height: 16px; }

/* ---------- Clickable card ---------- */
.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.card-link:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow);
}

/* ---------- Auth / login page ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-brand);
  padding: var(--space);
}

.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

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

.auth-logo { width: 44px; height: 44px; object-fit: contain; }

.auth-name {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
}

.auth-submit { width: 100%; justify-content: center; }

/* ---------- Communications list — filter pane + table ---------- */
.comm-page {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: var(--space);
  align-items: start;
}

.filter-pane {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  position: sticky;
  top: var(--space);
}

.filter-pane h4 {
  margin: 0 0 14px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.filter-pane .field { margin-bottom: 12px; }

.filter-pane .field label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.filter-pane .select {
  font-size: 0.88rem;
  padding: 6px 8px;
}

/* Aantal actieve filters naast de "Filters"-titel. */
.filter-count { text-transform: none; letter-spacing: 0; }

/* Reset onderaan het filterpaneel — vol breed zodat hij opvalt. */
.filter-reset { margin-top: 12px; width: 100%; text-align: center; }

.comm-results { min-width: 0; }

/* Dense, uniform rows for the (potentially very long) communicatielijst:
   fixed columns + truncation so one long subject can't blow up the table. */
.comm-results .table { table-layout: fixed; }
.comm-results .table th,
.comm-results .table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.comm-results .table th:nth-child(1), .comm-results .table td:nth-child(1) { width: 46px; }   /* richting/★ */
.comm-results .table th:nth-child(2), .comm-results .table td:nth-child(2) { width: 140px; }  /* datum */
.comm-results .table th:nth-child(3), .comm-results .table td:nth-child(3) { width: 86px; }   /* type */
.comm-results .table th:nth-child(4), .comm-results .table td:nth-child(4) { width: 120px; }  /* categorie */
.comm-results .table th:nth-child(5), .comm-results .table td:nth-child(5) { width: 170px; }  /* klant */
.comm-results .table th:nth-child(7), .comm-results .table td:nth-child(7) { width: 128px; }  /* door */
/* col 6 = Onderwerp takes the remaining width and ellipsises */

/* ---------- Communication form — link rows + autocomplete + adres-panel ---------- */
.comm-form .form-actions {
  position: sticky;
  bottom: 0;
  background: var(--color-bg);
  padding: 12px 0;
  border-top: 1px solid var(--color-border);
  margin-top: 0;
}

.link-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--color-bg) 50%, #fff);
}

.link-row-fields {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr 1.2fr;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.link-row-fields .field { margin-bottom: 0; }

.link-row-fields label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin-bottom: 3px;
  display: block;
}

.link-row .input,
.link-row .addr-button { padding: 7px 10px; font-size: 0.9rem; }

.link-row .addr-button { width: 100%; justify-content: flex-start; }

.link-row .addr-selected:empty { display: none; }

.link-row .remove-link { margin-top: 18px; flex-shrink: 0; }

/* Autocomplete dropdown */
.autocomplete { position: relative; }

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  z-index: 100;
}

.autocomplete-list li {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.92rem;
}

.autocomplete-list li:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

/* Address picker */
.addr-panel {
  margin-top: 8px;
  padding: 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.addr-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  line-height: 1.45;
  transition: border-color 0.12s, background 0.12s;
}

.addr-card:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.addr-card-general {
  background: color-mix(in srgb, var(--color-primary-soft) 60%, #fff);
}

@media (max-width: 980px) {
  .comm-page { grid-template-columns: 1fr; }
  .filter-pane { position: static; }
  .link-row-fields { grid-template-columns: 1fr; }
}

/* ---------- Dashboard ---------- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space);
}

.kpi {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-decoration: none;
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.kpi:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow);
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.kpi-label {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.kpi-sub {
  margin-top: 4px;
  color: var(--color-danger);
  font-size: 0.8rem;
  font-weight: 600;
}

.kpi-warn { border-color: color-mix(in srgb, var(--color-warning) 40%, var(--color-border)); }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: var(--space);
}

/* ---------- Rich text editor (Quill) ---------- */
.ql-toolbar.ql-snow,
.ql-container.ql-snow {
  border-color: var(--color-border);
}

.ql-toolbar.ql-snow {
  border-top-left-radius: var(--radius-sm);
  border-top-right-radius: var(--radius-sm);
}

.ql-container.ql-snow {
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  font-family: var(--font-body);
}

.ql-editor {
  min-height: 220px;
  font-size: 0.95rem;
}

/* Rendered rich content on the detail page */
.rich-content { line-height: 1.55; }
.rich-content p { margin: 0 0 0.6em; }
.rich-content p:last-child { margin-bottom: 0; }
.rich-content ul,
.rich-content ol { margin: 0 0 0.6em; padding-left: 1.5em; }

/* ---------- CEO-rapport ---------- */
.ceo-report-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  margin-bottom: 6px;
  border-bottom: 2px solid var(--color-border);
}

.ceo-report-logo { width: 48px; height: 48px; object-fit: contain; }

.ceo-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}

.ceo-item:last-child { border-bottom: none; }

.ceo-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.ceo-item-subject { font-weight: 600; margin: 6px 0 2px; }
.ceo-item-body { margin: 4px 0; white-space: pre-wrap; }
.ceo-item-foot { font-size: 0.82rem; margin: 4px 0 0; }

/* ---------- Filter / search bar ---------- */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar .input { flex: 1; min-width: 220px; }

/* ---------- Form row (multi-field side by side) ---------- */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0 var(--space);
}

.form-row .field { margin-bottom: var(--space); }

/* ---------- Field error ---------- */
.field-error {
  font-size: 0.82rem;
  color: var(--color-danger);
  margin: 4px 0 0;
}

/* ---------- Info grid (definition list for record detail) ---------- */
.info-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px var(--space);
  margin: 0;
}

.info-grid dt {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.info-grid dd { margin: 0; }

/* ---------- Change list (audit log) ---------- */
.change-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.88rem;
}

.change-list code {
  background: var(--color-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.84rem;
}

/* ---------- Inline colour swatch ---------- */
.color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  border: 1px solid var(--color-border);
  margin-right: 4px;
}

/* ---------- Communication timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }

.timeline-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}

.timeline-item:last-child { border-bottom: none; }

.timeline-meta {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.timeline-subject {
  font-weight: 600;
  margin: 0 0 4px;
}

.timeline-subject a { color: inherit; text-decoration: none; }
.timeline-subject a:hover { color: var(--color-primary); }

.timeline-body {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.timeline-direction-in  { color: var(--color-success); }
.timeline-direction-out { color: var(--color-primary); }
.timeline-direction-internal { color: var(--color-text-muted); }
