/* ========================================================================
   components.css — reusable UI primitives
   ======================================================================== */

/* ----------------------------------------------------------- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: var(--fs-sm);
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: transform var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--primary);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow-md);
}
.btn--primary:hover {
  background: var(--primary-600);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.btn--ghost {
  background: var(--hover);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:hover {
  background: var(--raised);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

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

/* ------------------------------------------------------------- Cards --- */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  transition: transform var(--dur) var(--ease),
    border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.card--hover:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ------------------------------------------------------------ Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge--primary { color: var(--badge-primary); background: var(--primary-soft); border-color: rgba(167,139,250,.3); }
.badge--success { color: var(--badge-success); background: var(--success-soft); border-color: rgba(92,203,127,.3); }
.badge--warning { color: var(--badge-warning); background: var(--warning-soft); border-color: rgba(245,158,11,.32); }
.badge--danger  { color: var(--badge-danger);  background: var(--danger-soft);  border-color: rgba(255,89,94,.34); }

.dot-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  position: relative;
}
.dot-pulse::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: dot-pulse 2.4s var(--ease) infinite;
}
@keyframes dot-pulse {
  0%   { transform: scale(0.6); opacity: 0.5; }
  70%  { transform: scale(1.8); opacity: 0; }
  100% { opacity: 0; }
}

.tag {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--hover);
  border: 1px solid var(--border);
}

/* --------------------------------------------------------- Accordion --- */
.accordion {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.incident {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.incident.is-open {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.incident__head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  text-align: left;
  padding: var(--sp-3);
}
.incident__id {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--danger);
  margin-top: 4px;
}
.incident__title {
  font-size: var(--fs-h3);
  font-weight: 600;
}
.incident__chevron {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.incident.is-open .incident__chevron {
  transform: rotate(180deg);
  color: var(--text);
}

/* Height transition via max-height + grid-rows fallback */
.incident__panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-slow) var(--ease);
}
.incident.is-open .incident__panel {
  grid-template-rows: 1fr;
}
.incident__panel-inner {
  overflow: hidden;
}
.incident__body {
  padding: 0 var(--sp-3) var(--sp-3);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-2) var(--sp-4);
}
.incident__step {
  border-left: 2px solid var(--border-strong);
  padding-left: var(--sp-2);
}
.incident__step h4 {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.incident__step p { color: var(--text-muted); font-size: var(--fs-sm); }
.incident__step--impact { border-left-color: var(--success); }
.incident__step--impact p { color: var(--text); }
.incident__tags {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

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

/* ----------------------------------------------------------- Drawer --- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.drawer-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 201;
  width: min(440px, 92vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: none; }
.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.drawer__close {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.drawer__close:hover { background: var(--hover); color: var(--text); }
.drawer__body {
  padding: var(--sp-3);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.drawer__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.drawer__tools { display: flex; flex-wrap: wrap; gap: 8px; }
.drawer__muted { color: var(--text-muted); }

/* ------------------------------------------------------- KB / search --- */
.kb-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-4);
}
.search {
  position: relative;
  flex: 1 1 280px;
}
.search input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.search input::placeholder { color: var(--text-dim); }
.search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
}
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 13px;
  font-size: var(--fs-sm);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
  transition: all var(--dur-fast) var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.is-active {
  color: var(--on-accent);
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

.kb-card h3 { font-size: 1.05rem; margin-bottom: 10px; }
.kb-card .field { margin-top: 10px; }
.kb-card .field span {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 3px;
}
.kb-card .field p { color: var(--text-muted); font-size: var(--fs-sm); }
.kb-card .field--outcome p { color: var(--text); }
.kb-empty {
  text-align: center;
  color: var(--text-muted);
  padding: var(--sp-8);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.kb-empty[hidden] { display: none; }

/* ---------------------------------------------------- Escalation TL --- */
.timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding-left: var(--sp-4);
}
.timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: linear-gradient(180deg, var(--border-strong), transparent);
}
.esc {
  position: relative;
}
.esc__node {
  position: absolute;
  left: calc(-1 * var(--sp-4) + 2px);
  top: 22px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 4px var(--bg);
}
.esc__node--warning { border-color: var(--warning); }
.esc__node--danger  { border-color: var(--danger); }
.esc__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-2) var(--sp-4);
  margin-top: var(--sp-2);
}
.esc__cell span {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.esc__cell p { color: var(--text-muted); font-size: var(--fs-sm); }
.esc__cell--cause p { color: var(--text); }
.esc__details {
  margin-top: var(--sp-2);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-2);
}
.esc__toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--primary);
}
.esc__toggle svg { transition: transform var(--dur) var(--ease); }
.esc.is-open .esc__toggle svg { transform: rotate(180deg); }
.esc__tech {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-slow) var(--ease);
}
.esc.is-open .esc__tech { grid-template-rows: 1fr; }
.esc__tech > div { overflow: hidden; }
.esc__tech p {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  padding-top: var(--sp-2);
}

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

/* --------------------------------------------------------- Contact --- */
/* Ticket card is edge-to-edge: the two columns, their divider, and the footer
   bar all reach the card edges, so the card itself carries no padding. */
.ticket-shell { padding: 0; overflow: hidden; }
.ticket__cols {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
}
/* Vertical divider between the columns (adapts the mockup's 1px column). */
.ticket__side { border-left: 1px solid var(--border); }
.ticket__main,
.ticket__side { padding: var(--sp-3) var(--sp-3) var(--sp-4); }
/* Section headings above each column (Contact Information / Message). */
.ticket__section {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin: 0 0 var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ticket__section svg { color: var(--primary); }

/* Footer action bar — spans the full card width under the columns. */
.ticket__bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.ticket__note {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.ticket__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.form-field { margin-bottom: var(--sp-3); }
.form-field:last-child { margin-bottom: 0; }
@media (max-width: 640px) {
  .ticket__cols { grid-template-columns: 1fr; }
  .ticket__side { border-left: 0; border-top: 1px solid var(--border); }
  .ticket__actions { width: 100%; margin-left: 0; justify-content: flex-end; }
}
.form-field label,
.form-field__label {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: 8px;
}
.form-field .req { color: var(--danger); }
.form-field input,
.form-field textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.form-field textarea { resize: vertical; min-height: 120px; }
.form-field input:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
/* Live character counter under the Comments textarea. */
.form-field__foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}
.char-count {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.char-count[data-near="true"] { color: var(--warning); }
.priority {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.priority input { position: absolute; opacity: 0; pointer-events: none; }
.priority label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 10px 6px;
  font-size: var(--fs-sm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  margin: 0;
  transition: all var(--dur-fast) var(--ease);
}
.priority__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.priority__dot[data-prio="low"] { background: var(--success); }
.priority__dot[data-prio="normal"] { background: var(--primary); }
.priority__dot[data-prio="high"] { background: #F5A623; }
.priority__dot[data-prio="urgent"] { background: var(--danger); }
.priority input:checked + label {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}
.priority input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 2px; }

.ticket-success {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-3);
}
.ticket-success.is-shown { display: flex; }
.ticket-success__icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid rgba(92,203,127,.3);
}
.ticket-success__sla {
  margin-top: var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.ticket-success__sla strong { color: var(--text); }
