* { margin: 0; padding: 0; box-sizing: border-box; }
:root { --primary: #2563eb; --danger: #dc2626; --success: #16a34a; --warn: #eab308; --bg: #f9fafb; --card: #fff; --text: #1f2937; --muted: #6b7280; --border: #e5e7eb; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Skip link (acessibilidade) */
.skip-link { position: absolute; top: -40px; left: 0; background: var(--primary); color: #fff; padding: 8px 16px; z-index: 1000; border-radius: 0 0 6px 0; }
.skip-link:focus { top: 0; }

nav { background: #1f2937; color: #fff; padding: 12px 0; }
nav .container { display: flex; align-items: center; justify-content: space-between; }
nav .brand { font-size: 1.25rem; font-weight: 700; color: #fff; }
nav .links { display: flex; gap: 16px; }
nav .links a { color: #d1d5db; font-size: 0.875rem; }
nav .links a:hover { color: #fff; }
nav .user-info { font-size: 0.8rem; color: #9ca3af; }
nav .hamburger { display: none; flex-direction: column; gap: 5px; cursor: pointer; padding: 4px; background: none; border: none; }
nav .hamburger span { display: block; width: 22px; height: 2px; background: #d1d5db; border-radius: 2px; }
.page { padding: 24px 0; }
.page h1 { font-size: 1.5rem; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat { text-align: center; }
.stat .value { font-size: 2rem; font-weight: 700; }
.stat .label { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.stat.success .value { color: var(--success); }
.stat.danger .value { color: var(--danger); }
.stat.warn .value { color: var(--warn); }

/* Tabelas com wrapper responsivo */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; }
.table-wrap table { min-width: 560px; }

/* Botões alinhados ao fim de um filtro flex (substitui label fantasma) */
.filters .btn-bottom, .filter-bar .btn-bottom { align-self: flex-end; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f3f4f6; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; color: var(--muted); }
tr:hover td { background: #f9fafb; }

/* Truncamento de IDs longos com tooltip nativo */
.truncate { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.badge-online { background: #dcfce7; color: #166534; }
.badge-offline { background: #fee2e2; color: #991b1b; }
.badge-busy { background: #fef3c7; color: #92400e; }
.badge-unassigned { background: #e5e7eb; color: #374151; }
.btn { display: inline-block; padding: 8px 16px; border: none; border-radius: 6px; font-size: 0.875rem; cursor: pointer; font-weight: 500; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn[disabled], .btn.is-loading { opacity: 0.6; cursor: not-allowed; pointer-events: none; }
.btn.is-loading::after { content: ''; display: inline-block; width: 12px; height: 12px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -2px; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input, select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.875rem; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 0.875rem; }
.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.hidden { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
th { white-space: nowrap; }

/* Token mascarado (locations) */
.token-box { display: inline-flex; align-items: center; gap: 6px; }
.token-box code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }
.token-box .copy-btn, .token-box .reveal-btn { cursor: pointer; color: var(--primary); font-size: 0.75rem; user-select: none; }
.token-box .reveal-btn[aria-pressed="true"] { color: var(--muted); }

.skeleton-row { height: 44px; background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; margin-bottom: 4px; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Estado vazio padronizado */
.empty-state { text-align: center; padding: 48px 16px; }
.empty-state .icon { font-size: 3rem; color: var(--muted); margin-bottom: 12px; line-height: 1; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.875rem; color: var(--muted); }

/* R02: entre 900-1024px, encolhe os links sem virar hambúrguer */
@media (max-width: 1024px) and (min-width: 901px) {
    nav .links { gap: 10px; }
    nav .links a { font-size: 0.8rem; }
    nav .user-info { font-size: 0.7rem; }
}

@media (max-width: 900px) {
    nav .hamburger { display: flex; }
    nav .links { display: none; flex-direction: column; position: absolute; top: 48px; left: 0; right: 0; background: #1f2937; padding: 12px 16px; gap: 4px; z-index: 200; border-top: 1px solid #374151; }
    nav .links.open { display: flex; }
    nav .links a { padding: 8px 4px; font-size: 0.9rem; border-bottom: 1px solid #374151; }
    nav .links a:last-child { border-bottom: none; }
    nav .user-info { display: none; }
    nav .user-info.open { display: block; }
    nav .container { position: relative; }
    body { overflow-x: hidden; }
    .tenant-bar .container { flex-wrap: wrap; gap: 6px; }
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 480px) {
    .container { padding: 0 12px; }
    .page { padding: 16px 0; }
    .page h1 { font-size: 1.25rem; }
    .card { padding: 14px; }
    .summary-grid { grid-template-columns: 1fr !important; }
    .filters { flex-direction: column !important; }
    .filters > * { width: 100% !important; }
    th, td { padding: 8px 8px; font-size: 0.8rem; }
    .truncate { max-width: 110px; }
    .token-box code { max-width: 130px; }
    nav .brand { font-size: 1.1rem; }
    .btn { padding: 8px 12px; font-size: 0.8rem; }
    .modal-content { padding: 16px !important; max-width: 95vw !important; }
}

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