:root {
  --bg: #f3f5fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --sidebar: #0b1220;
  --radius: 16px;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

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

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #cbd5e1;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #22d3ee);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.brand span {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  color: #cbd5e1;
  text-decoration: none;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: #1e293b;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 11.5px;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
}

.status-pill.ok::before {
  background: #22c55e;
}

.status-pill.warn::before {
  background: #f59e0b;
}

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

.sidebar .muted {
  color: #64748b;
}

.main {
  padding: 28px 32px 48px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

h1 {
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.topbar p {
  margin: 0;
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #4338ca;
}

.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.btn-ghost:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.btn-danger {
  background: #fff;
  border-color: #fecaca;
  color: #b91c1c;
}

.btn-danger:hover {
  background: #fef2f2;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
  cursor: pointer;
}

.forward-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.forward-panel.active {
  border-left-color: var(--green);
  background: #f0fdf4;
}

.forward-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.forward-desc {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 3px;
}

.forward-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.forward-controls input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13.5px;
  width: 210px;
  background: #fff;
}

.forward-controls input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: #a5b4fc;
}

.mode-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f1f5f9;
}

.mode-btn {
  border: none;
  background: transparent;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}

.mode-btn:hover {
  color: var(--ink);
}

.mode-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.forward-panel.active .mode-btn.active {
  background: var(--green);
  color: #fff;
}

.forward-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
  border-top: 1px dashed var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

.forward-hint-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.forward-hint-text strong {
  font-size: 12px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.forward-hint-text code {
  font-family: "Cascadia Code", Consolas, monospace;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12px;
}

.forward-hint-alt {
  font-size: 11.5px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 6px;
  letter-spacing: -0.03em;
}

.stat.accent .stat-value {
  color: var(--accent);
}

.stat.warn .stat-value {
  color: var(--amber);
}

.stat.danger .stat-value {
  color: var(--red);
}

.stat.good .stat-value {
  color: var(--green);
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filters input,
.filters select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ink);
}

.filters input {
  flex: 1 1 260px;
}

.filters input:focus,
.filters select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: #a5b4fc;
}

.table-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 13px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: none;
}

.ticket-id {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--accent);
  white-space: nowrap;
}

.cell-main {
  font-weight: 600;
}

.cell-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.issue-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #334155;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.alta {
  background: var(--red);
  color: #fff;
}

.badge.media,
.badge.bassa {
  background: var(--green);
  color: #fff;
}

.badge.nuovo {
  background: var(--accent-soft);
  color: #4338ca;
}

.badge.in_lavorazione {
  background: #e0f2fe;
  color: #0369a1;
}

.badge.chiuso {
  background: #f1f5f9;
  color: #475569;
}

.status-select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12.5px;
  font-family: inherit;
  background: #fff;
  cursor: pointer;
}

.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
}

.empty h3 {
  margin: 0 0 6px;
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, 100%);
  height: 100vh;
  background: #fff;
  z-index: 50;
  box-shadow: -20px 0 60px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.22s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(30px);
    opacity: 0.4;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.drawer-head {
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.drawer-head h2 {
  margin: 0 0 4px;
  font-size: 19px;
}

.drawer-head p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.drawer-body {
  padding: 22px;
  overflow: auto;
  flex: 1;
}

.drawer-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  background: #f8fafc;
}

.icon-btn {
  border: none;
  background: #f1f5f9;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 18px;
  color: var(--muted);
  flex: 0 0 auto;
}

.icon-btn:hover {
  background: #e2e8f0;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.detail {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 14px;
  min-width: 0;
}

.detail .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 700;
}

.detail .value {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.detail.full {
  grid-column: 1 / -1;
}

.issue-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.section-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 22px 0 10px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 5px;
}

.field select,
.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
}

.notes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.note {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.note .meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

textarea {
  width: 100%;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  resize: vertical;
}

textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: #a5b4fc;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  z-index: 60;
  box-shadow: var(--shadow);
  max-width: 90vw;
}

.toast.error {
  background: #b91c1c;
}

/* ---------------------------------------------------------------------------
   Simulatore
--------------------------------------------------------------------------- */

.sim-layout {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.sim-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.sim-header h1 {
  font-size: 24px;
}

.phone-shell {
  background: #0b1220;
  border-radius: 26px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}

.phone-screen {
  background: #f8fafc;
  border-radius: 16px;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.phone-top {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.phone-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

.phone-top strong {
  font-size: 14px;
}

.phone-top span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.chat {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: 440px;
}

.msg {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  animation: pop 0.18s ease;
  white-space: pre-wrap;
}

@keyframes pop {
  from {
    transform: translateY(4px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.system {
  align-self: center;
  background: #fef3c7;
  color: #92400e;
  font-size: 12.5px;
  max-width: 100%;
}

.msg.success {
  align-self: stretch;
  max-width: 100%;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.msg.success a {
  color: #047857;
  font-weight: 700;
}

.chat-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 12px;
}

.option-btn {
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.option-btn:hover {
  background: #e0e7ff;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 14px 20px 18px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.chat-input input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 14px;
  font-family: inherit;
}

.chat-input input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: #a5b4fc;
}

.chat-input button {
  border: none;
  background: var(--accent);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  flex: 0 0 auto;
}

.chat-input button:disabled,
.option-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sim-hint {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

@media (max-width: 1100px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
  }

  .sidebar nav {
    flex-direction: row;
    overflow: auto;
  }

  .sidebar-footer {
    display: none;
  }

  .main {
    padding: 20px 16px 40px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    flex-direction: column;
  }

  table {
    min-width: 720px;
  }

  .table-card {
    overflow-x: auto;
  }
}

@media (max-width: 560px) {
  .detail-grid,
  .form-row {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}
