@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* ============ TOKENS ============ */
:root,
[data-theme="dark"] {
  --bg: #020617;
  --surface: #0F172A;
  --surface-2: #161F35;
  --surface-hover: #1E293B;
  --muted: #1A2338;
  --border: #263349;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --text-faint: #64748B;

  --accent: #22C55E;
  --accent-hover: #16A34A;
  --accent-soft: rgba(34,197,94,.14);
  --on-accent: #04140A;

  --info: #3B82F6;
  --info-soft: rgba(59,130,246,.14);
  --warning: #F59E0B;
  --warning-soft: rgba(245,158,11,.14);
  --purple: #A78BFA;
  --purple-soft: rgba(167,139,250,.14);
  --danger: #EF4444;
  --danger-soft: rgba(239,68,68,.14);

  --ring: #22C55E;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 24px rgba(0,0,0,.45);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.55);

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-hover: #F1F5F9;
  --muted: #F1F5F9;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #52607A;
  --text-faint: #8595AD;

  --accent: #16A34A;
  --accent-hover: #15803D;
  --accent-soft: rgba(22,163,74,.10);
  --on-accent: #FFFFFF;

  --info: #2563EB;
  --info-soft: rgba(37,99,235,.10);
  --warning: #D97706;
  --warning-soft: rgba(217,119,6,.12);
  --purple: #7C3AED;
  --purple-soft: rgba(124,58,237,.10);
  --danger: #DC2626;
  --danger-soft: rgba(220,38,38,.10);

  --ring: #16A34A;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow-md: 0 8px 24px rgba(15,23,42,.08);
  --shadow-lg: 0 24px 48px rgba(15,23,42,.14);

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.is-hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ============ LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 800; font-size: 17px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: transparent; border: none; color: var(--text-muted);
  font-size: 14.5px; font-weight: 600; text-align: left;
  cursor: pointer; transition: background .15s ease, color .15s ease;
  min-height: 44px;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-icon { flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: var(--muted); color: var(--text-muted);
  font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
}
.nav-item.is-active .nav-badge { background: var(--accent); color: var(--on-accent); }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 10px; padding: 9px 12px;
  cursor: pointer; font-size: 13.5px; font-weight: 600; min-height: 44px;
  transition: background .15s ease, color .15s ease;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.icon-sun { display: none; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.avatar {
  width: 34px; height: 34px; border-radius: 999px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--info));
  color: #04140A; font-weight: 800; font-size: 12.5px;
  display: flex; align-items: center; justify-content: center;
}
.avatar-sm { width: 30px; height: 30px; font-size: 11.5px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-size: 13.5px; font-weight: 700; }
.user-role { font-size: 12px; color: var(--text-faint); }

.sidebar-scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 19px; flex-shrink: 0; }
.search-wrap {
  flex: 1; max-width: 420px; margin-left: 12px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px; height: 40px;
  color: var(--text-faint); transition: border-color .15s ease, box-shadow .15s ease;
}
.search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap input {
  border: none; background: transparent; outline: none; color: var(--text);
  font-size: 14px; width: 100%; height: 100%; font-family: inherit;
}
.search-wrap input::placeholder { color: var(--text-faint); }

.content { padding: 24px 28px 64px; flex: 1; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border-radius: 10px; border: 1px solid transparent;
  padding: 0 16px; height: 40px; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background .15s ease, border-color .15s ease, transform .1s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  cursor: pointer; transition: background .15s ease, color .15s ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.link-btn {
  background: none; border: none; color: var(--accent); font-weight: 700;
  font-size: 13.5px; cursor: pointer; padding: 6px 8px; border-radius: 6px;
}
.link-btn:hover { background: var(--accent-soft); }

.only-mobile { display: none; }

/* ============ CARDS / KPI ============ */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow-sm);
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 10px; }
.kpi-icon {
  width: 26px; height: 26px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.kpi-icon-info { background: var(--info-soft); color: var(--info); }
.kpi-icon-danger { background: var(--danger-soft); color: var(--danger); }
.kpi-icon-success { background: var(--accent-soft); color: var(--accent); }
.kpi-icon-neutral { background: var(--muted); color: var(--text-muted); }
.kpi-value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12.5px; margin-top: 6px; }
.kpi-foot.positive { color: var(--accent); font-weight: 600; }

.dash-grid { display: grid; grid-template-columns: 1.1fr 1.4fr; gap: 16px; align-items: start; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { font-size: 15px; }

.status-bars { display: flex; flex-direction: column; gap: 14px; }
.status-bar-row { display: flex; align-items: center; gap: 10px; }
.status-bar-label { width: 128px; flex-shrink: 0; font-size: 13px; font-weight: 600; color: var(--text-muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
.status-bar-track { flex: 1; height: 8px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.status-bar-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.status-bar-value { width: 26px; text-align: right; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

.mini-list { display: flex; flex-direction: column; gap: 4px; }
.mini-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px;
  cursor: pointer; transition: background .15s ease; min-height: 44px;
}
.mini-row:hover { background: var(--surface-hover); }
.mini-row-main { flex: 1; min-width: 0; }
.mini-row-subject { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row-sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

/* ============ FILTERS / TOGGLE ============ */
.filters-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filters-left { display: flex; gap: 10px; flex-wrap: wrap; }

select, input[type=text], input[type=email], input[type=search], textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 12px; height: 40px; outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
select { cursor: pointer; }
textarea { padding: 10px 12px; height: auto; resize: vertical; line-height: 1.5; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.view-toggle { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.toggle-btn {
  display: flex; align-items: center; gap: 6px; border: none; background: transparent;
  color: var(--text-muted); font-weight: 700; font-size: 13px; padding: 7px 12px; border-radius: 8px;
  cursor: pointer; transition: background .15s ease, color .15s ease; min-height: 36px;
}
.toggle-btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ============ TABLE ============ */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-sm); }
.tickets-table { width: 100%; border-collapse: collapse; }
.tickets-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.tickets-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.tickets-table tbody tr { cursor: pointer; transition: background .15s ease; }
.tickets-table tbody tr:hover { background: var(--surface-hover); }
.tickets-table tbody tr:last-child td { border-bottom: none; }
.cell-subject { font-weight: 700; }
.cell-id { color: var(--text-faint); font-weight: 500; font-size: 12.5px; margin-right: 6px; }
.cell-sub { color: var(--text-faint); font-size: 12.5px; margin-top: 2px; }
.cell-requester { display: flex; align-items: center; gap: 8px; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 64px 20px; color: var(--text-faint); text-align: center; }
.empty-state p { font-weight: 700; color: var(--text-muted); font-size: 15px; }

/* ============ BADGES ============ */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700;
  padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.badge .status-dot { width: 6px; height: 6px; }
.badge-status-aberto { background: var(--info-soft); color: var(--info); }
.badge-status-em-andamento { background: var(--warning-soft); color: var(--warning); }
.badge-status-pendente { background: var(--purple-soft); color: var(--purple); }
.badge-status-resolvido { background: var(--accent-soft); color: var(--accent); }
.badge-status-fechado { background: var(--muted); color: var(--text-faint); }

.badge-priority-baixa { background: var(--muted); color: var(--text-muted); }
.badge-priority-media { background: var(--info-soft); color: var(--info); }
.badge-priority-alta { background: var(--warning-soft); color: var(--warning); }
.badge-priority-urgente { background: var(--danger-soft); color: var(--danger); }

/* ============ KANBAN ============ */
.kanban-wrap { display: grid; grid-template-columns: repeat(5, minmax(204px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kanban-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; min-height: 160px; display: flex; flex-direction: column; gap: 10px; }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 2px; }
.kanban-col-title { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; }
.kanban-count { font-size: 12px; font-weight: 700; color: var(--text-faint); background: var(--muted); padding: 1px 7px; border-radius: 999px; }
.kanban-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 12px;
  cursor: pointer; transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  display: flex; flex-direction: column; gap: 8px;
}
.kanban-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card-subject { font-size: 13.5px; font-weight: 700; line-height: 1.35; }
.kanban-card-foot { display: flex; align-items: center; justify-content: space-between; }
.kanban-card-requester { font-size: 12px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.kanban-empty { padding: 20px 6px; text-align: center; color: var(--text-faint); font-size: 12.5px; }

/* ============ MODAL / DRAWER ============ */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(2,6,23,.6); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .18s ease;
}
[data-theme="light"] .overlay { background: rgba(15,23,42,.4); }
.overlay.drawer-align { justify-content: flex-end; padding: 0; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn .2s cubic-bezier(.2,.8,.3,1);
}
.modal-sm { max-width: 380px; }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 16px; }
.confirm-title { font-size: 17px; margin-bottom: 8px; }
.modal-body .muted { margin-bottom: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.field .req { color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.helper-text { font-size: 12px; color: var(--text-faint); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.drawer {
  background: var(--surface); border-left: 1px solid var(--border);
  width: 100%; max-width: 460px; height: 100dvh;
  display: flex; flex-direction: column;
  animation: slideIn .22s cubic-bezier(.2,.8,.3,1);
  box-shadow: var(--shadow-lg);
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 16px; border-bottom: 1px solid var(--border); }
.ticket-id { font-size: 12px; font-weight: 700; color: var(--text-faint); }
.drawer-head h2 { font-size: 17px; margin-top: 4px; }

.drawer-body { padding: 20px 22px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 24px; }
.drawer-section { display: flex; flex-direction: column; gap: 12px; }
.drawer-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.drawer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.requester-card { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.requester-name { font-size: 13.5px; font-weight: 700; }
.ticket-description { font-size: 14px; color: var(--text-muted); line-height: 1.6; white-space: pre-wrap; }
.ticket-meta { display: flex; flex-direction: column; gap: 2px; }

.comment-list { display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; }
.comment {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.comment.is-internal { background: var(--warning-soft); border-color: transparent; }
.comment-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.comment-author { font-size: 12.5px; font-weight: 700; }
.comment-time { font-size: 11.5px; color: var(--text-faint); }
.comment-text { font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }
.comment-tag { font-size: 10.5px; font-weight: 800; text-transform: uppercase; color: var(--warning); letter-spacing: .03em; }

.comment-form { display: flex; flex-direction: column; gap: 8px; }
.comment-form-actions { display: flex; align-items: center; justify-content: space-between; }
.checkbox-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.drawer-foot { padding: 14px 22px; border-top: 1px solid var(--border); }

/* ============ TOASTS ============ */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: 340px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow-lg); display: flex; align-items: flex-start; gap: 10px;
  font-size: 13.5px; font-weight: 600; animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.toast-icon { flex-shrink: 0; width: 20px; height: 20px; border-radius: 999px; display: flex; align-items: center; justify-content: center; }
.toast-success .toast-icon { background: var(--accent-soft); color: var(--accent); }
.toast-error .toast-icon { background: var(--danger-soft); color: var(--danger); }
.toast-info .toast-icon { background: var(--info-soft); color: var(--info); }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0; width: 264px;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-scrim.is-open {
    display: block; position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 50;
  }
  .only-mobile { display: inline-flex; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .page-title { display: none; }
  .search-wrap { margin-left: 0; }
  .content { padding: 18px 16px 48px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 24px; }
  .field-row { grid-template-columns: 1fr; }
  .drawer-grid { grid-template-columns: 1fr; }
  .kanban-wrap { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .view-toggle { align-self: flex-start; }
  .btn span, .btn { white-space: nowrap; }
  #newTicketBtn span { display: none; }
}

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