:root {
  color-scheme: dark;
  --bg: #050607;
  --surface: #111315;
  --surface-2: #17191c;
  --surface-3: #1e2227;
  --border: #2a2d33;
  --border-strong: #3a3f48;
  --text: #f4f7fb;
  --muted: #a8b0bd;
  --muted-2: #78808d;
  --primary: #0b5fc7;
  --primary-2: #1c7dff;
  --primary-soft: rgba(28, 125, 255, .14);
  --purple: #8236d9;
  --green: #2fd072;
  --amber: #f5b541;
  --red: #ff5a66;
  --shadow: 0 20px 50px rgba(0,0,0,.28);
  --radius: 18px;
  --radius-sm: 11px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --surface-3: #e8edf4;
  --border: #d7dde7;
  --border-strong: #bbc5d3;
  --text: #10141a;
  --muted: #576272;
  --muted-2: #7b8594;
  --primary-soft: rgba(11, 95, 199, .10);
  --shadow: 0 18px 42px rgba(22, 35, 56, .13);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(circle at 15% 0%, rgba(11,95,199,.18), transparent 33%), var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 74px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(20px);
  background: color-mix(in srgb, var(--bg) 87%, transparent);
}

.org-switch, .account-btn, .theme-toggle, .nav-btn, .primary, .secondary, .ghost, .template-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: .18s ease;
}
.org-switch:hover, .account-btn:hover, .theme-toggle:hover, .secondary:hover, .ghost:hover, .template-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }

.org-switch {
  height: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  min-width: 230px;
}
.org-switch small, .account-btn small, .account-menu small, .page-head p, .breadcrumb { display: block; color: var(--muted); }
.org-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: white;
  background: linear-gradient(150deg, #07366c, #0b5fc7 55%, #8aa7c7);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.org-mark.large { width: 48px; height: 48px; border-radius: 14px; }
.chevron { color: var(--muted); margin-left: auto; }

.topnav { display: flex; gap: 8px; flex: 1; }
.nav-btn { padding: 10px 14px; color: var(--muted); background: transparent; }
.nav-btn.active { color: var(--text); background: var(--primary-soft); border-color: rgba(28,125,255,.35); }

.account { display: flex; align-items: center; gap: 10px; position: relative; }
.theme-toggle { width: 42px; height: 42px; }
.account-btn { height: 52px; display: flex; align-items: center; gap: 10px; padding: 6px 10px; max-width: 360px; }
.account-btn img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.account-btn strong, .account-menu strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; display: block; }
.account-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 62px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.account-menu.open { display: block; }
.account-menu-head { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.account-menu button { width: 100%; background: transparent; border: 0; color: var(--text); padding: 14px 16px; text-align: left; }
.account-menu button:hover { background: var(--surface-2); }
.account-menu .danger { color: var(--red); }

.app-shell { max-width: 1210px; margin: 0 auto; padding: 32px 28px 88px; }
.view { display: none; animation: appear .18s ease; }
.view.active { display: block; }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head.narrow { max-width: 780px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 28px; line-height: 1.15; margin-bottom: 5px; }
h2 { font-size: 19px; margin-bottom: 14px; }
h3 { font-size: 15px; color: var(--muted); }
p { line-height: 1.65; }

.primary {
  padding: 11px 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: rgba(255,255,255,.10);
  color: white;
  font-weight: 700;
}
.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.secondary, .ghost { padding: 10px 14px; }
.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.back-btn { margin-bottom: 16px; }
.full { width: 100%; justify-content: center; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.search-field { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 14px; height: 46px; }
.search-field input { flex: 1; background: transparent; border: 0; outline: 0; color: var(--text); }
select, input, textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
}
select:focus, input:focus, textarea:focus { border-color: rgba(28,125,255,.65); box-shadow: 0 0 0 3px rgba(28,125,255,.12); }
textarea { resize: vertical; min-height: 120px; }

.ticket-grid { display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); gap: 16px; }
.card, .ticket-card, .rating-card {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px rgba(255,255,255,.01);
}
.ticket-card {
  padding: 20px;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}
.ticket-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }
.ticket-card .card-top, .ticket-card .card-bottom { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ticket-card h2 { font-size: 17px; margin: 0; }
.ticket-card p { color: var(--muted); margin: 0; font-size: 14px; }
.ticket-card .card-bottom { margin-top: auto; color: var(--muted); font-size: 13px; justify-content: space-between; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.badge.blue { color: #9dccff; background: rgba(28,125,255,.13); border-color: rgba(28,125,255,.35); }
.badge.green { color: #8df6b7; background: rgba(47,208,114,.13); border-color: rgba(47,208,114,.35); }
.badge.amber { color: #ffe0a3; background: rgba(245,181,65,.13); border-color: rgba(245,181,65,.35); }
.badge.red { color: #ffadb4; background: rgba(255,90,102,.13); border-color: rgba(255,90,102,.35); }
.badge.purple { color: #d7b8ff; background: rgba(130,54,217,.15); border-color: rgba(130,54,217,.40); }

.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 24px; align-items: start; }
.ticket-main { display: flex; flex-direction: column; gap: 18px; }
.ticket-title-row { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.breadcrumb { font-size: 14px; margin-bottom: 8px; }
.rating-card { padding: 38px 28px; text-align: center; }
.rating-card p { color: var(--muted); margin-bottom: 18px; }
.rating-row { display: flex; justify-content: center; gap: 10px; }
.rating-row button { border: 0; width: 42px; height: 42px; border-radius: 50%; font-size: 22px; background: var(--surface-3); transition: .15s ease; }
.rating-row button:hover, .rating-row button.selected { transform: scale(1.12); background: var(--primary-soft); }
.block { padding: 24px; }
.side-card { padding: 22px; margin-bottom: 18px; }
.ticket-side { position: sticky; top: 94px; }
dl { margin: 0; display: grid; gap: 10px; }
dt { color: var(--muted); font-weight: 700; }
dd { margin: 0 0 8px; line-height: 1.45; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

.comments { display: flex; flex-direction: column; gap: 12px; }
.comment {
  padding: 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.comment.internal { background: rgba(245,181,65,.10); border-color: rgba(245,181,65,.24); }
.comment-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.comment-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--purple); color: white; font-weight: 800; }
.comment-head small { color: var(--muted); display: block; }
.comment p { margin: 0; }

.form-card { max-width: 780px; padding: 26px; }
.form-card label, .admin-grid label { display: grid; gap: 8px; margin-bottom: 18px; color: var(--muted); font-weight: 700; }
.form-card small { color: var(--muted-2); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.metric { padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.metric strong { display: block; font-size: 28px; }
.metric span { color: var(--muted); font-size: 13px; }
.agent-layout { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 18px; align-items: start; }
.queue-card { padding: 20px; }
.section-head { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 14px; }
.section-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 13px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
td { font-size: 14px; }
.row-actions { display: flex; gap: 8px; }
.row-actions button { padding: 7px 9px; border-radius: 9px; font-size: 12px; }
.template-btn { width: 100%; text-align: left; padding: 12px; margin-bottom: 8px; color: var(--muted); }

.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); gap: 18px; }
.org-preview { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.org-preview img { width: 220px; max-width: 50%; height: auto; border-radius: 8px; background: #000; }
.org-preview small { display: block; color: var(--muted); }
.mini-table { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; margin-bottom: 16px; }
.mini-table div { display: flex; justify-content: space-between; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--border); }
.mini-table div:last-child { border-bottom: 0; }
.mini-table span { color: var(--muted); }

.account-page { max-width: 760px; display: grid; gap: 18px; }
.profile-row { display: flex; align-items: center; gap: 16px; }
.profile-row img { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; }
.profile-row small { display: block; color: var(--muted); }
.footer { border-top: 1px solid var(--border); color: var(--muted); text-align: center; padding: 18px; position: fixed; bottom: 0; left: 0; right: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); }
.toast { position: fixed; right: 24px; bottom: 82px; max-width: 420px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); display: none; }
.toast.show { display: block; animation: appear .15s ease; }

@media (max-width: 980px) {
  .topbar { height: auto; align-items: stretch; flex-wrap: wrap; padding: 12px; }
  .topnav { order: 3; width: 100%; overflow-x: auto; }
  .account { margin-left: auto; }
  .account-btn span:not(.chevron) { display: none; }
  .ticket-layout, .agent-layout { grid-template-columns: 1fr; }
  .ticket-side { position: static; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .app-shell { padding: 24px 14px 86px; }
  .ticket-grid, .admin-grid, .form-grid { grid-template-columns: 1fr; }
  .toolbar, .page-head { flex-direction: column; align-items: stretch; }
  .metrics { grid-template-columns: 1fr; }
  .org-switch { min-width: 0; flex: 1; }
}

/* Atualização v0.2 - organizações/localidades, cadastro e identidade visual */
.org-picker { position: relative; }
.org-logo-square {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(255,255,255,.10);
}
.org-logo-square.large { width: 54px; height: 54px; border-radius: 15px; }
.org-menu {
  display: none;
  position: absolute;
  top: 62px;
  left: 0;
  width: 360px;
  max-width: calc(100vw - 28px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  z-index: 50;
}
.org-menu.open { display: block; }
.org-menu button {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  text-align: left;
}
.org-menu button:last-child { border-bottom: 0; }
.org-menu button:hover, .org-menu button.active { background: var(--surface-2); }
.org-menu small { color: var(--muted); display: block; }
.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-row select { width: auto; min-width: 175px; }
.section-head.stackable { align-items: flex-start; }
.brand-preview {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
}
.brand-logo {
  display: block;
  max-width: 100%;
  width: 360px;
  height: auto;
  border-radius: 8px;
}
html[data-theme="dark"] .logo-for-light { display: none; }
html[data-theme="light"] .logo-for-dark { display: none; }
html[data-theme="light"] .brand-preview { background: #fff; }
html[data-theme="dark"] .brand-preview { background: #000; }
.muted-text { color: var(--muted); }
.wide-card { grid-column: 1 / -1; }
.org-admin-row { align-items: center; }
.org-admin-row strong small { display: block; color: var(--muted); font-weight: 500; margin-top: 2px; }
.org-admin-row span { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.org-admin-row em {
  font-style: normal;
  color: #9dccff;
  background: rgba(28,125,255,.13);
  border: 1px solid rgba(28,125,255,.35);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}
.form-note {
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  font-size: 14px;
}

@media (max-width: 980px) {
  .org-picker { flex: 1; }
  .org-menu { top: 58px; }
  .filter-row select { width: 100%; }
}

@media (max-width: 720px) {
  .org-menu { position: fixed; left: 12px; right: 12px; width: auto; top: 72px; }
  .toolbar select { width: 100%; }
  .org-admin-row span { justify-content: flex-start; }
}
