:root {
  --primary: #0088FF;
  --primary-hover: #0077E6;
  --primary-soft: #E6F3FF;
  --dark: #1E293B;
  --dark-2: #334155;
  --text: #1E293B;
  --text-muted: #64748B;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --success: #10B981;
  --success-soft: #D1FAE5;
  --warning: #F59E0B;
  --warning-soft: #FEF3C7;
  --danger: #EF4444;
  --danger-soft: #FEE2E2;
  --purple: #8B5CF6;
  --purple-soft: #EDE9FE;
  --orange: #F97316;
  --orange-soft: #FFEDD5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; }
.text-right { text-align: right; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.space-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }

/* ---------- LOGIN ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #DBEAFE 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 100%, #E0F2FE 0%, transparent 55%), var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 20px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .12); padding: 36px 32px; text-align: center;
}
.login-logo { width: 160px; height: 160px; object-fit: contain; margin: 0 auto 8px; display: block; }
.login-card h1 { font-size: 24px; color: var(--dark); }
.login-card form { margin-top: 24px; text-align: left; }
.login-hint { font-size: 12px; color: var(--text-muted); text-align: center; margin: 14px 0 0; }

/* ---------- APP SHELL ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--dark); color: #CBD5E1; display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 40; transition: transform .25s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); color: #fff; }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand small { color: #94A3B8; font-size: 12px; }
.logo-box { width: 52px; height: 52px; border-radius: 12px; background: #fff; display: grid; place-items: center; overflow: hidden; flex-shrink: 0; }
.logo-box img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; font-weight: 500;
  color: #CBD5E1; transition: background .15s, color .15s;
}
.sidebar-nav a svg { width: 20px; height: 20px; fill: currentColor; opacity: .85; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(0,136,255,.35); }
.nav-count { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700; background: rgba(255,255,255,.15); padding: 2px 8px; border-radius: 999px; }
.nav-count:empty { display: none; }
.sidebar-footer { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 6px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 6px; color: #fff; }
.user-chip strong { display: block; font-size: 13px; }
.user-chip small { color: #94A3B8; font-size: 11px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.sidebar .btn-ghost { color: #CBD5E1; justify-content: flex-start; }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 35; }

.content { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; background: rgba(248,250,252,.85); backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 20px; color: var(--dark); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.clock { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.icon-btn { display: none; border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; fill: var(--dark); }
.view { padding: 24px 28px 48px; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; transition: all .15s;
  background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(0,136,255,.25); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: #F1F5F9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-block { width: 100%; }

/* ---------- CARDS / KPI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-header h3 { font-size: 15px; }
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; cursor: pointer; }
.kpi::after { content: ''; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px; border-radius: 50%; background: var(--kpi-color, var(--primary)); opacity: .08; }
.kpi .kpi-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 32px; font-weight: 800; color: var(--kpi-color, var(--dark)); line-height: 1; }
.kpi .kpi-sub { font-size: 12px; color: var(--text-muted); }

/* ---------- TABLE ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 12px 14px; border-bottom: 1px solid var(--border); background: #F8FAFC; white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; transition: background .12s; }
.table tbody tr.clickable:hover { background: #F1F5F9; }
.table .actions { white-space: nowrap; text-align: right; }
.empty { padding: 40px; text-align: center; color: var(--text-muted); }
.empty strong { display: block; color: var(--dark); margin-bottom: 4px; }

/* ---------- BADGES ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.2; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-aguardando { background: var(--warning-soft); color: #B45309; }
.st-atendimento { background: #DBEAFE; color: #1D4ED8; }
.st-pendente { background: var(--purple-soft); color: #6D28D9; }
.st-encerrado { background: var(--success-soft); color: #047857; }
.pr-baixa { background: #F1F5F9; color: #475569; }
.pr-media { background: #DBEAFE; color: #1D4ED8; }
.pr-alta { background: var(--orange-soft); color: #C2410C; }
.pr-critica { background: var(--danger-soft); color: #B91C1C; }
.eq-ativo { background: var(--success-soft); color: #047857; }
.eq-manutencao { background: var(--warning-soft); color: #B45309; }
.eq-descartado { background: #F1F5F9; color: #64748B; }
.inactive { background: #F1F5F9; color: #64748B; }
.active-badge { background: var(--success-soft); color: #047857; }

/* SLA */
.sla { display: inline-flex; flex-direction: column; gap: 5px; min-width: 130px; }
.sla-row { display: flex; align-items: center; gap: 6px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px; }
.sla-bar { height: 5px; border-radius: 999px; background: #E2E8F0; overflow: hidden; }
.sla-bar i { display: block; height: 100%; border-radius: 999px; background: var(--sla-color); transition: width .3s; }
.sla-ok { --sla-color: var(--success); color: #047857; }
.sla-warning { --sla-color: var(--warning); color: #B45309; }
.sla-critical { --sla-color: var(--orange); color: #C2410C; }
.sla-breached { --sla-color: var(--danger); color: #B91C1C; }
.sla-paused { --sla-color: var(--purple); color: #6D28D9; }
.sla-closed_in { --sla-color: var(--success); color: #047857; }
.sla-closed_out { --sla-color: var(--danger); color: #B91C1C; }
.sla-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 6px; background: currentColor; }
.sla-tag span { color: #fff; }
.sla-panel { padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.sla-panel .big { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.sla-panel .meta { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.sla-panel .meta b { color: var(--dark); display: block; font-size: 13px; }
.sla-ring { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--sla-color) calc(var(--pct) * 1%), #E2E8F0 0); position: relative; }
.sla-ring::before { content: ''; position: absolute; inset: 9px; background: #fff; border-radius: 50%; }
.sla-ring span { position: relative; font-weight: 800; font-size: 15px; }

/* ---------- FORMS ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--dark-2); }
.field > span .req { color: var(--danger); }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; width: 100%; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,136,255,.15); }
textarea { min-height: 96px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.hint { font-size: 12px; color: var(--text-muted); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; padding: 8px 10px; }
.filters .search { min-width: 240px; flex: 1; }

/* ---------- MODAL ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.modal { background: #fff; width: 100%; max-width: 640px; border-radius: 16px; box-shadow: 0 30px 80px rgba(15,23,42,.3); max-height: calc(100vh - 32px); display: flex; flex-direction: column; animation: pop .18s; }
.modal.lg { max-width: 900px; }
.modal.sm { max-width: 440px; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 17px; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.close-x { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-muted); }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- TOAST ---------- */
.toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--dark); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; animation: pop .2s; border-left: 4px solid var(--primary); max-width: 360px; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }

/* ---------- TICKET DETAIL ---------- */
.detail-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.detail-head h2 { font-size: 22px; color: var(--dark); }
.detail-head .proto { font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: .05em; }
.detail-grid { display: grid; grid-template-columns: 1fr 360px; gap: 18px; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.info-list dt { color: var(--text-muted); font-weight: 500; }
.info-list dd { margin: 0; font-weight: 500; }
.description { white-space: pre-wrap; line-height: 1.6; color: var(--dark-2); }

.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 13px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding-left: 40px; padding-bottom: 20px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .tl-dot { position: absolute; left: 5px; top: 2px; width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; background: var(--primary); box-shadow: 0 0 0 2px var(--border); }
.timeline .tl-dot.status { background: var(--purple); }
.timeline .tl-dot.comment { background: var(--text-muted); }
.timeline .tl-dot.closed { background: var(--success); }
.timeline .tl-dot.created { background: var(--primary); }
.timeline .tl-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; color: var(--text-muted); }
.timeline .tl-head b { color: var(--dark); font-size: 13px; }
.timeline .tl-body { margin-top: 4px; font-size: 13px; line-height: 1.55; color: var(--dark-2); white-space: pre-wrap; }
.timeline .tl-quote { margin-top: 6px; padding: 8px 12px; background: #F8FAFC; border-left: 3px solid var(--purple); border-radius: 6px; font-size: 13px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }

.link { color: var(--primary); font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }
.urgent-item { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); cursor: pointer; }
.urgent-item:hover { background: #F8FAFC; }
.urgent-item:last-child { border-bottom: 0; }
.urgent-item .ttl { font-weight: 600; }
.urgent-item .sub { font-size: 12px; color: var(--text-muted); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; }
  .content { margin-left: 0; }
  .icon-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .topbar h2 { font-size: 17px; }
  .view { padding: 16px; }
  .btn-new-label { display: none; }
  #btn-new-ticket span { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .filters .search { min-width: 100%; }
  .hide-sm { display: none; }
  .sla-panel { grid-template-columns: 1fr; }
}
@media print {
  body * { visibility: hidden; }
}
