/* ==========================================================================
   Connecfy — shared components
   Used by the website, the dashboard and the staff console.
   Conventions: block, block__element, block--modifier. No utility sprawl.
   ========================================================================== */

/* ---- Icons (inline SVG from the {% icon %} tag) -------------------------- */
.icon {
  display: inline-block;
  vertical-align: -0.2em;
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm { width: 0.9375rem; height: 0.9375rem; }
.icon--lg { width: 1.5rem; height: 1.5rem; }

/* ---- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 2.5rem;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-2);
  font-family: inherit;
  font-size: var(--fs-300);
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

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

.btn--accent { background: var(--signal-400); color: var(--slate-950); }
.btn--accent:hover { background: #5AD2DC; }

.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--slate-50); border-color: var(--slate-400); }

.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--slate-100); color: var(--text); }

.btn--danger { background: var(--red-600); color: var(--white); }
.btn--danger:hover { background: var(--red-700); }
.btn--danger-quiet { background: transparent; color: var(--red-600); }
.btn--danger-quiet:hover { background: var(--red-50); }

.btn--sm { min-height: 2rem; padding: 0 var(--sp-3); font-size: var(--fs-200); }
.btn--lg { min-height: 3rem; padding: 0 var(--sp-6); font-size: var(--fs-400); }
.btn--block { display: flex; width: 100%; }

.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn.is-loading { pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: "";
  width: 0.95em; height: 0.95em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 1rem; height: 1rem; flex: none; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent-text); font: inherit; font-weight: 600;
  text-decoration: underline; text-underline-offset: 0.2em; cursor: pointer;
}

/* ---- Forms ---------------------------------------------------------------- */
.field { display: grid; gap: 0.375rem; margin-bottom: var(--sp-5); }
.field:last-child { margin-bottom: 0; }
.label {
  font-size: var(--fs-200);
  font-weight: 700;
  color: var(--text);
}
.label__opt { font-weight: 500; color: var(--text-muted); }
.hint { font-size: var(--fs-200); color: var(--text-muted); }
.field-error {
  display: flex; gap: 0.375rem; align-items: flex-start;
  font-size: var(--fs-200); font-weight: 600; color: var(--red-700);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  font-size: var(--fs-400);
  line-height: 1.4;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--slate-500); opacity: 0.8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--slate-400); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--signal-600);
  box-shadow: var(--shadow-focus);
  outline: none;
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--red-600);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--slate-100); color: var(--text-muted); cursor: not-allowed;
}
.textarea { min-height: 7.5rem; resize: vertical; }
.select {
  appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235F6F7C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  background-size: 1.125rem;
}
.input--mono { font-family: var(--font-mono); font-size: var(--fs-300); }
.input--sm, .select--sm { min-height: 2rem; padding-block: 0.25rem; font-size: var(--fs-300); }

.check {
  display: inline-flex; align-items: flex-start; gap: var(--sp-3);
  font-size: var(--fs-400); cursor: pointer;
}
.check input { width: 1.125rem; height: 1.125rem; margin-top: 0.15rem; accent-color: var(--signal-700); flex: none; }

/* Toggle switch (a checkbox underneath, so it works without JS) */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; font-weight: 600; }
.switch input {
  appearance: none;
  width: 2.5rem; height: 1.5rem; flex: none;
  background: var(--slate-300);
  border-radius: var(--r-pill);
  position: relative;
  transition: background-color var(--dur-1) var(--ease);
  cursor: pointer;
}
.switch input::after {
  content: "";
  position: absolute; top: 0.1875rem; left: 0.1875rem;
  width: 1.125rem; height: 1.125rem;
  background: var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(10, 21, 32, 0.3);
  transition: transform var(--dur-1) var(--ease);
}
.switch input:checked { background: var(--signal-700); }
.switch input:checked::after { transform: translateX(1rem); }
.switch input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.input-group { position: relative; }
.input-group .input { padding-right: 3rem; }
.input-group__btn {
  position: absolute; right: 0.25rem; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 2rem; height: 2rem;
  background: none; border: 0; border-radius: var(--r-1);
  color: var(--text-muted); cursor: pointer;
}
.input-group__btn:hover { color: var(--text); background: var(--slate-100); }

/* ---- Panels --------------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.panel__title { font-size: var(--fs-400); font-weight: 700; letter-spacing: -0.005em; }
.panel__sub { font-size: var(--fs-200); color: var(--text-muted); margin-top: 0.125rem; }
.panel__body { padding: var(--sp-5); }
.panel__foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-3) var(--r-3); }
.panel--flush > .panel__body { padding: 0; }
.panel--muted { background: var(--surface-2); }

/* ---- Metrics: one bordered block, hairlines between cells ------------------ */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
}
.metric { background: var(--surface); padding: var(--sp-4) var(--sp-5); min-width: 0; }
@media (max-width: 40rem) { .metric { padding: var(--sp-3) var(--sp-4); } .metric__value { font-size: var(--fs-800); } }
.metric__label {
  font-size: var(--fs-100); font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
}
.metric__value {
  margin-top: var(--sp-2);
  font-size: var(--fs-900); font-weight: 700; letter-spacing: -0.025em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.metric__note { margin-top: 0.375rem; font-size: var(--fs-200); color: var(--text-muted); }

/* ---- Usage meter ----------------------------------------------------------- */
.meter {
  height: 0.5rem; border-radius: var(--r-pill);
  background: var(--slate-150); overflow: hidden;
}
.meter__fill { height: 100%; background: var(--signal-500); border-radius: inherit; transition: width var(--dur-2) var(--ease); }
.meter[data-level="warn"] .meter__fill { background: var(--amber-500); }
.meter[data-level="full"] .meter__fill { background: var(--red-600); }

/* ---- Tables ---------------------------------------------------------------- */
.table-wrap {
  position: relative;            /* contains .sr-only cells so they cannot widen the page */
  container-type: inline-size;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
}
.panel > .table-wrap { border: 0; border-radius: 0 0 var(--r-3) var(--r-3); }
.panel__head + .table-wrap { border-radius: 0 0 var(--r-3) var(--r-3); }
.table { width: 100%; font-size: var(--fs-300); }
.table caption { text-align: left; padding: var(--sp-3) var(--sp-4); font-weight: 700; }
.table th {
  padding: 0.6875rem var(--sp-4);
  text-align: left; white-space: nowrap;
  font-size: var(--fs-100); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 0.8125rem var(--sp-4);
  border-bottom: 1px solid var(--slate-150);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #F6FAFB; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .id { font-family: var(--font-mono); font-size: var(--fs-200); }
.table .truncate { max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table a { font-weight: 600; }

/* Optional columns (.col-opt) step aside when the table's own column is narrow, whatever the window width. */
@media (min-width: 721px) {
  @container (max-width: 46rem) { .table .col-opt { display: none; } }
}

@media (max-width: 720px) {
  .table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
  .table--stack tr { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
  .table--stack tbody tr:last-child { border-bottom: 0; }
  .table--stack td { display: flex; justify-content: space-between; gap: var(--sp-4); padding: 0.25rem 0; border: 0; text-align: right; }
  .table--stack td::before {
    content: attr(data-label);
    flex: none; text-align: left;
    font-size: var(--fs-100); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted);
  }
  .table--stack .truncate { max-width: 60%; }

  /* .table--rows: a dense list on phones - number and status on one line,
     the message beneath, sender and time last. No per-cell labels. */
  .table--rows, .table--rows tbody, .table--rows tr, .table--rows td { display: block; width: 100%; }
  .table--rows thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--rows tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--sp-3); row-gap: 0.25rem;
    grid-template-areas: "num status" "msg msg" "sender when";
    padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
  }
  .table--rows tbody tr:last-child { border-bottom: 0; }
  .table--rows td { padding: 0; border: 0; width: auto; }
  .table--rows .c-num { grid-area: num; }
  .table--rows .c-status { grid-area: status; justify-self: end; }
  .table--rows .c-msg {
    grid-area: msg; max-width: none; white-space: normal; color: var(--text-2);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .table--rows .c-sender { grid-area: sender; font-size: var(--fs-200); }
  .table--rows .c-when { grid-area: when; font-size: var(--fs-200); justify-self: end; }
}

/* ---- Status ---------------------------------------------------------------- */
.status {
  display: inline-flex; align-items: center; gap: 0.3125rem;
  padding: 0.125rem 0.5rem 0.125rem 0.4375rem;
  border-radius: var(--r-1);
  background: var(--slate-100); color: var(--slate-700);
  font-size: var(--fs-100); font-weight: 700; line-height: 1.6; letter-spacing: 0.005em;
  white-space: nowrap;
}
.status .icon { width: 0.875rem; height: 0.875rem; stroke-width: 2.1; }
.status--queued    { background: var(--slate-100); color: var(--slate-700); }
.status--sending   { background: var(--amber-50);  color: var(--amber-700); }
.status--sent      { background: var(--signal-50); color: var(--signal-800); }
.status--delivered { background: var(--green-50);  color: var(--green-700); }
.status--received  { background: var(--signal-50); color: var(--signal-800); }
.status--failed    { background: var(--red-50);    color: var(--red-700); }
.status--online    { background: var(--green-50);  color: var(--green-700); }
.status--offline   { background: var(--slate-100); color: var(--slate-600); }
.status--active    { background: var(--green-50);  color: var(--green-700); }
.status--revoked   { background: var(--red-50);    color: var(--red-700); }
.status--paid      { background: var(--green-50);  color: var(--green-700); }
.status--pending   { background: var(--amber-50);  color: var(--amber-700); }

/* ---- Alerts ---------------------------------------------------------------- */
.alert {
  display: grid; grid-template-columns: auto 1fr; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--signal-200);
  border-radius: var(--r-2);
  background: var(--signal-50);
  font-size: var(--fs-300);
  color: var(--slate-900);
}
.alert .icon { margin-top: 0.1875rem; color: var(--signal-700); }
.alert__title { font-weight: 700; }
.alert__body > * + * { margin-top: 0.25rem; }
.alert--success { background: var(--green-50); border-color: var(--green-100); }
.alert--success .icon { color: var(--green-700); }
.alert--warning { background: var(--amber-50); border-color: var(--amber-100); }
.alert--warning .icon { color: var(--amber-700); }
.alert--danger  { background: var(--red-50);   border-color: var(--red-100); }
.alert--danger .icon  { color: var(--red-700); }
.alerts { display: grid; gap: var(--sp-3); }

/* ---- Tabs ------------------------------------------------------------------ */
.tabs { display: flex; flex-wrap: wrap; gap: var(--sp-1); border-bottom: 1px solid var(--border); }
.tab {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 0.625rem var(--sp-4); margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  font-size: var(--fs-300); font-weight: 650; color: var(--text-muted);
  text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-current="page"], .tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--signal-500); }

/* ---- Segmented control ----------------------------------------------------- */
.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--slate-100); border-radius: var(--r-2);
}
.segmented button, .segmented a {
  min-width: 2.25rem; padding: 0.25rem 0.625rem;
  border: 0; border-radius: 4px; background: transparent;
  font-size: var(--fs-100); font-weight: 700; letter-spacing: 0.04em;
  color: var(--text-muted); text-decoration: none; cursor: pointer;
}
.segmented [aria-pressed="true"], .segmented [aria-current="true"] {
  background: var(--surface); color: var(--text);
  box-shadow: 0 1px 2px rgba(10, 21, 32, 0.14);
}

/* ---- Key / value list ------------------------------------------------------ */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.75rem var(--sp-6); margin: 0; }
.kv dt { font-size: var(--fs-200); color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.kv--stack { grid-template-columns: 1fr; gap: 0.125rem; }
.kv--stack dd { margin-bottom: var(--sp-3); }

/* ---- Empty state ----------------------------------------------------------- */
.empty { text-align: center; padding: var(--sp-12) var(--sp-6); }
.empty__art { margin: 0 auto var(--sp-5); width: 9.5rem; color: var(--slate-300); }
.empty__title { font-size: var(--fs-600); font-weight: 700; }
.empty__text { max-width: 32rem; margin: var(--sp-2) auto 0; color: var(--text-muted); }
.empty__actions { margin-top: var(--sp-5); display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap; }

/* ---- Pagination ------------------------------------------------------------ */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-200); color: var(--text-muted);
}
.pagination__links { display: flex; gap: var(--sp-2); }

/* ---- Code ------------------------------------------------------------------ */
.code { background: var(--slate-900); color: #D4E1EB; border-radius: var(--r-3); overflow: hidden; border: 1px solid #1B3045; }
.code__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 0.375rem 0.5rem 0.375rem var(--sp-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-mono); font-size: var(--fs-100); color: #8FA3B3;
}
.code pre { margin: 0; padding: var(--sp-4) var(--sp-5); overflow-x: auto; font-size: var(--fs-200); line-height: 1.75; tab-size: 2; }
.code code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.code--wrap pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.tk-k { color: #79D3DD; }          /* keys, flags */
.tk-s { color: #A6D99B; }          /* strings */
.tk-n { color: #F0C27B; }          /* numbers, status values */
.tk-c { color: #7C92A3; font-style: italic; } /* comments */
.tk-m { color: #FFFFFF; font-weight: 600; }   /* methods, commands */
.code .btn--ghost { color: #A9BBC9; }
.code .btn--ghost:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.copyline {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0.375rem 0.375rem 0.375rem var(--sp-3);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-2);
}
.copyline code { flex: 1; min-width: 0; background: none; border: 0; padding: 0; font-size: var(--fs-300); overflow-wrap: anywhere; }

/* ---- Dialog ---------------------------------------------------------------- */
.dialog {
  width: min(34rem, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: rgba(10, 21, 32, 0.55); }
.dialog__head { padding: var(--sp-5) var(--sp-6) var(--sp-3); }
.dialog__title { font-size: var(--fs-700); }
.dialog__body { padding: 0 var(--sp-6) var(--sp-5); }
.dialog__foot {
  display: flex; justify-content: flex-end; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  background: var(--surface-2); border-top: 1px solid var(--border);
}

/* ---- Toasts (client-side events only; server messages render as alerts) ---- */
.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: var(--z-toast); display: grid; gap: var(--sp-3); }
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  min-width: 15rem; max-width: 22rem;
  padding: var(--sp-3) var(--sp-4);
  background: var(--slate-900); color: var(--white);
  border-radius: var(--r-2); box-shadow: var(--shadow-pop);
  font-size: var(--fs-300); font-weight: 600;
  animation: toast-in var(--dur-2) var(--ease);
}
.toast .icon { color: var(--signal-400); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity var(--dur-1), transform var(--dur-1); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- Route line: the Connecfy signature (a message in transit) ------------- */
.route { display: flex; align-items: center; width: 100%; color: var(--slate-300); }
.route__node { width: 0.625rem; height: 0.625rem; border-radius: 50%; border: 2px solid currentColor; background: var(--surface); flex: none; }
.route__node--live { border-color: var(--signal-500); background: var(--signal-500); }
.route__line { flex: 1; height: 0; border-top: 2px dashed currentColor; }
.route__line--solid { border-top-style: solid; }
