:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

header {
  margin-bottom: 24px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.stat-value.alta { color: var(--danger); }
.stat-value.media { color: var(--warning); }
.stat-value.baixa { color: var(--success); }

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

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

input[type="text"], select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}

input[type="text"] { min-width: 250px; }
select { cursor: pointer; }

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #dc2626; }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #059669; }

.table-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  background: #f1f5f9;
  padding: 12px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}

td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:hover { background: #f8fafc; }

td.id { font-family: 'Courier New', monospace; font-weight: 600; color: var(--primary); font-size: 13px; }
td.assunto { max-width: 300px; }

.priority-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.priority-alta { background: #fee2e2; color: var(--danger); }
.priority-media { background: #fef3c7; color: var(--warning); }
.priority-baixa { background: #d1fae5; color: var(--success); }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.status-aguarda { background: #dbeafe; color: var(--info); }
.status-responder { background: #fef3c7; color: #b45309; }
.status-verificar { background: #e9d5ff; color: #7e22ce; }
.status-resolvida { background: #d1fae5; color: #065f46; }
.status-arquivada { background: #f1f5f9; color: var(--text-muted); }

.dias-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--text-muted);
}

.dias-badge.alta { background: #fee2e2; color: var(--danger); }

.actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

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

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active { display: flex; }

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-large { max-width: 800px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.close-btn:hover { color: var(--text); }

.modal-body { padding: 24px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

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

.form-row > .form-group { min-width: 0; }

/* Ações */
.pendencia-info {
  overflow-wrap: anywhere;
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.pendencia-info h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.pendencia-info .meta {
  font-size: 13px;
  color: var(--text-muted);
}

.acoes-list {
  margin-bottom: 20px;
}

.acao-item {
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 12px;
  border-left: 3px solid var(--primary);
  background: var(--bg);
  margin-bottom: 8px;
  border-radius: var(--radius);
}

.acao-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.acao-tipo {
  font-weight: 600;
  font-size: 13px;
  color: var(--primary);
}

.acao-data {
  font-size: 12px;
  color: var(--text-muted);
}

.acao-descricao {
  font-size: 14px;
  margin-bottom: 4px;
}

.acao-email {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  overflow-wrap: anywhere;
}

.acao-manual {
  border-left-color: #64748b;
  background: #f8fafc;
}

.acao-form {
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

.no-actions {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-style: italic;
}

@media (max-width: 768px) {
  .container { padding: 12px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 8px; }
  .modal-content { max-height: 96vh; }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; }
}

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: var(--bg); }
.sort-ind { color: var(--primary); font-size: 11px; }

.link-origem { color: var(--primary); text-decoration: none; font-weight: 500; }
.link-origem:hover { text-decoration: underline; }
