/* ============================================================================
   ticket.css — Portale gestione ticket assistenza IT
   Usa i token di styles.css (--brand-red, --action-blue, --surface, ...).
   ========================================================================== */

.tk {
  --tk-ok: #1f9d55;
  --tk-warn: #d68000;
  --tk-info: #1157f9;
  --tk-muted: #7d7d80;
  --tk-radius: 0;
}

/* ---- Intestazione applicazione -------------------------------------------- */
.tk-app {
  padding: 2rem 0 4rem;
  background: var(--surface);
  min-height: 60vh;
}

.tk-appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.tk-appbar h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--heading);
}

.tk-appbar .tk-sub {
  margin: 0.2rem 0 0;
  color: var(--tk-muted);
  font-size: 0.9rem;
}

/* ---- Selettore ruolo (cliente / operatore) -------------------------------- */
.tk-roleswitch {
  display: inline-flex;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 3px;
}

.tk-roleswitch button {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--tk-muted);
  padding: 0.4rem 1rem;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.tk-roleswitch button.is-active {
  background: var(--brand-red);
  color: #fff;
}

.tk-role-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--tk-muted);
  margin-top: 0.35rem;
  text-align: right;
}

/* ---- Box utente autenticato ----------------------------------------------- */
.tk-userbox {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.tk-user {
  display: flex;
  flex-direction: column;
  text-align: right;
  line-height: 1.2;
}
.tk-user strong { color: var(--heading); font-size: 0.9rem; }
.tk-user em { color: var(--tk-muted); font-size: 0.78rem; font-style: normal; }

/* ---- Allegati ------------------------------------------------------------- */
.tk-attach {
  margin: 1.1rem 0 0;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border-radius: 0;
}
.tk-attach-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.tk-attach-head > span { font-size: 0.85rem; font-weight: 700; color: var(--heading); }
.tk-att-add {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--action-blue);
  cursor: pointer;
}
.tk-att-add:hover { text-decoration: underline; }
.tk-att-empty { margin: 0; font-size: 0.85rem; color: var(--tk-muted); }
.tk-att-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.tk-att {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.4rem 0.6rem;
}
.tk-att-dl {
  border: none;
  background: none;
  font: inherit;
  color: var(--heading);
  cursor: pointer;
  text-align: left;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tk-att-dl:hover { color: var(--action-blue); }
.tk-att-dl em { color: var(--tk-muted); font-style: normal; font-size: 0.82rem; }
.tk-att-ico { margin-right: 0.35rem; }
.tk-att-del {
  border: none;
  background: none;
  color: var(--tk-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
  flex-shrink: 0;
}
.tk-att-del:hover { color: var(--brand-red); }

/* ---- Barra strumenti (filtri + azioni) ------------------------------------ */
.tk-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.8rem;
  margin-bottom: 1.2rem;
}

.tk-toolbar .tk-search {
  flex: 1 1 220px;
  min-width: 160px;
}

.tk-toolbar select,
.tk-toolbar input[type="text"],
.tk-field input,
.tk-field select,
.tk-field textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.55rem 0.7rem;
}

.tk-toolbar select { color: var(--heading); }

.tk-toolbar .tk-spacer { flex: 1 1 auto; }

/* Il pulsante "nuovo ticket" resta sempre visibile e non si comprime */
.tk-toolbar .tk-btn-new {
  flex: 0 0 auto;
  order: -1;
  margin-right: 0.2rem;
  box-shadow: 0 2px 8px rgba(17, 87, 249, 0.28);
}

/* ---- Bottoni --------------------------------------------------------------- */
.tk-btn {
  border: none;
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.tk-btn-primary { background: var(--action-blue); color: #fff; }
.tk-btn-primary:hover { background: var(--action-blue-dark); }
.tk-btn-ghost { background: transparent; color: var(--heading); border: 1px solid var(--border); }
.tk-btn-ghost:hover { border-color: var(--brand-gray); }
.tk-btn-danger { background: transparent; color: var(--brand-red); border: 1px solid var(--border); }
.tk-btn-danger:hover { border-color: var(--brand-red); }
.tk-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Lista ticket ---------------------------------------------------------- */
.tk-list { display: grid; gap: 0.7rem; }

.tk-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.4rem 1rem;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-gray);
  border-radius: 0;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  transition: box-shadow 0.2s ease, transform 0.05s ease;
}
.tk-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,0.08); }
.tk-card[data-priority="urgente"] { border-left-color: var(--brand-red); }
.tk-card[data-priority="alta"] { border-left-color: var(--tk-warn); }

.tk-card-code {
  grid-row: 1 / span 2;
  font-weight: 700;
  color: var(--heading);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
.tk-card-main { min-width: 0; }
.tk-card-subject {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--heading);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tk-card-meta {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--tk-muted);
}
.tk-card-badges {
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

/* ---- Badge stato / priorità ----------------------------------------------- */
.tk-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.22rem 0.6rem;
  border-radius: 0;
  white-space: nowrap;
}
.tk-badge::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 0;
  background: currentColor;
}
.tk-badge-status[data-v="aperto"] { background: #eaf1ff; color: #1157f9; }
.tk-badge-status[data-v="in-lavorazione"] { background: #fff2e0; color: #b96b00; }
.tk-badge-status[data-v="in-attesa"] { background: #f0ecff; color: #6b4bd6; }
.tk-badge-status[data-v="risolto"] { background: #e6f6ec; color: #1f9d55; }
.tk-badge-status[data-v="chiuso"] { background: #eceded; color: #6b6b6e; }

.tk-badge-prio { border: 1px solid transparent; }
.tk-badge-prio[data-v="bassa"] { background: #eceded; color: #6b6b6e; }
.tk-badge-prio[data-v="media"] { background: #eaf1ff; color: #1157f9; }
.tk-badge-prio[data-v="alta"] { background: #fff2e0; color: #b96b00; }
.tk-badge-prio[data-v="urgente"] { background: #fde7e9; color: var(--brand-red); }

/* ---- Stato vuoto / caricamento -------------------------------------------- */
.tk-empty, .tk-loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--tk-muted);
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 0;
}
.tk-empty h3 { color: var(--heading); margin: 0 0 0.4rem; }

.tk-spinner {
  width: 30px; height: 30px;
  margin: 0 auto 0.8rem;
  border: 3px solid var(--border);
  border-top-color: var(--brand-red);
  border-radius: 50%;
  animation: tk-spin 0.8s linear infinite;
}
@keyframes tk-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .tk-spinner { animation: none; } }

/* ---- Riepilogo conteggi (operatore) --------------------------------------- */
.tk-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-bottom: 1.2rem;
}
.tk-stat {
  flex: 1 1 120px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.8rem 1rem;
}
.tk-stat b { display: block; font-size: 1.5rem; color: var(--heading); line-height: 1.1; }
.tk-stat span { font-size: 0.8rem; color: var(--tk-muted); }

/* ---- Dettaglio ------------------------------------------------------------- */
.tk-detail { display: grid; grid-template-columns: 1fr 300px; gap: 1.4rem; align-items: start; }

.tk-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  font: inherit;
  color: var(--action-blue);
  cursor: pointer;
  padding: 0;
  margin-bottom: 1rem;
}

.tk-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 1.3rem;
}
.tk-detail-head h2 { margin: 0 0 0.3rem; font-size: 1.25rem; color: var(--heading); }
.tk-detail-head .tk-code { color: var(--tk-muted); font-size: 0.85rem; font-weight: 700; }
.tk-detail-badges { display: flex; gap: 0.5rem; margin: 0.8rem 0 0; flex-wrap: wrap; }

/* Thread messaggi */
.tk-thread { margin-top: 1.3rem; display: grid; gap: 0.9rem; }
.tk-msg { display: grid; gap: 0.3rem; }
.tk-msg-head { font-size: 0.78rem; color: var(--tk-muted); }
.tk-msg-head b { color: var(--heading); }
.tk-msg-body {
  padding: 0.7rem 0.9rem;
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}
.tk-msg[data-role="agent"] .tk-msg-body { background: #eaf1ff; }
.tk-msg[data-role="client"] .tk-msg-body { background: #f4f5f6; }
.tk-msg[data-role="system"] .tk-msg-body {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--tk-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* Box risposta */
.tk-reply { margin-top: 1.2rem; }
.tk-reply textarea { width: 100%; min-height: 90px; resize: vertical; }
.tk-reply-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.6rem; }

/* Sidebar proprietà */
.tk-side .tk-panel + .tk-panel { margin-top: 1rem; }
.tk-side h4 { margin: 0 0 0.8rem; font-size: 0.95rem; color: var(--heading); }
.tk-prop { margin-bottom: 0.9rem; }
.tk-prop label { display: block; font-size: 0.78rem; font-weight: 700; color: var(--tk-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.3rem; }
.tk-prop select, .tk-prop .tk-prop-val { width: 100%; }
.tk-prop .tk-prop-val { color: var(--heading); font-weight: 600; }
.tk-side select { width: 100%; font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 0; background: #fff; color: var(--heading); }
.tk-sla { font-size: 0.82rem; color: var(--tk-muted); line-height: 1.4; }

/* ---- Form nuovo ticket ----------------------------------------------------- */
.tk-form { max-width: 680px; }
.tk-field { margin-bottom: 1.1rem; }
.tk-field label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--heading); margin-bottom: 0.35rem; }
.tk-field label .tk-req { color: var(--brand-red); }
.tk-field input, .tk-field select, .tk-field textarea { width: 100%; }
.tk-field textarea { min-height: 120px; resize: vertical; }
.tk-field input:focus, .tk-field select:focus, .tk-field textarea:focus,
.tk-toolbar input:focus, .tk-toolbar select:focus, .tk-side select:focus, .tk-reply textarea:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(191,30,46,0.12);
}
.tk-field-hint { font-size: 0.8rem; color: var(--tk-muted); margin: 0.3rem 0 0; }
.tk-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.tk-form-actions { display: flex; justify-content: flex-end; gap: 0.7rem; margin-top: 0.5rem; }

/* Avviso/feedback inline */
.tk-note {
  margin: 1rem 0 0;
  padding: 0.8rem 1rem;
  border-radius: 0;
  border-left: 3px solid var(--tk-ok);
  background: #e6f6ec;
  color: #1c6b3e;
  font-size: 0.9rem;
}
.tk-note[hidden] { display: none; }

/* ---- Responsive ------------------------------------------------------------ */
@media (max-width: 820px) {
  .tk-detail { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .tk-form-row { grid-template-columns: 1fr; }
  .tk-card { grid-template-columns: 1fr auto; }
  .tk-card-code { grid-row: auto; grid-column: 1 / -1; }
  .tk-card-badges { grid-row: auto; flex-direction: row; }
}

/* ============================ Gestione clienti (operatore) ============================ */

/* Navigazione Ticket / Clienti nella testata */
.tk-nav { display: flex; gap: 0.4rem; align-items: center; }
.tk-navbtn {
  font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 0.45rem 0.9rem; border-radius: 0;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--tk-muted); cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.tk-navbtn:hover { color: var(--heading); border-color: var(--brand-gray); }
.tk-navbtn.is-active { background: var(--action-blue); border-color: var(--action-blue); color: #fff; }

/* Card cliente nell'elenco */
.tk-client-card {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0; padding: 0.9rem 1.1rem; margin-bottom: 0.6rem;
}
.tk-client-card .tk-card-main { flex: 1 1 240px; }
.tk-client-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Riga password: input + bottone genera */
.tk-passrow { display: flex; gap: 0.5rem; align-items: stretch; }
.tk-passrow input { flex: 1 1 auto; }

/* Banner credenziali dopo creazione / reset */
.tk-credbox {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: #eefaf1; border: 1px solid var(--tk-ok);
  border-radius: 0; padding: 0.9rem 1.1rem; margin-bottom: 1rem;
}
.tk-credbox-body { font-size: 0.9rem; color: var(--heading); }
.tk-cred { margin-top: 0.35rem; display: flex; align-items: center; gap: 0.5rem; }
.tk-cred span { display: inline-block; min-width: 74px; color: var(--tk-muted); font-size: 0.82rem; }
.tk-cred code {
  font-family: Menlo, Consolas, monospace; font-size: 0.95rem;
  background: #fff; border: 1px solid var(--border); border-radius: 0;
  padding: 0.15rem 0.5rem; color: var(--heading); user-select: all;
}
