:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #f3f4f6;
    --secondary-hover: #e5e7eb;
    --background: #f9fafb;
    --surface: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background);
    background-image: 
        radial-gradient(at 0% 0%, hsla(253,16%,7%,0.03) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,39%,30%,0.03) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,49%,30%,0.03) 0, transparent 50%);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.app-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-main);
    background: linear-gradient(to right, #111827, #4f46e5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

.save-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-radius: 9999px;
    font-size: 0.85rem;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: opacity 0.3s ease;
}

.save-status.hidden {
    opacity: 0;
    pointer-events: none;
}

.status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Formulário e Seções */
.form-container form {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.form-section {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.form-section:hover {
    box-shadow: var(--shadow-lg);
}

.form-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
}

.section-header-flex h2 {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Grid System */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1.25rem;
}

@media (max-width: 640px) {
    .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
}

/* Inputs e Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--surface);
    color: var(--text-main);
    transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

input[readonly] {
    background-color: var(--secondary);
    color: var(--text-muted);
    cursor: not-allowed;
}

input::placeholder {
    color: #9ca3af;
}

.helper-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Botões */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 6px rgba(79, 70, 229, 0.4);
}

.btn-primary:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

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

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-large {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-danger {
    background-color: #fee2e2;
    color: var(--error);
    padding: 0.5rem;
}
.btn-danger:hover {
    background-color: #fca5a5;
    color: #991b1b;
}

.btn:disabled,
.btn:disabled:hover {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--secondary);
    color: var(--text-muted);
    border-color: var(--border);
}

/* Utilitários */
.hidden {
    display: none !important;
}

.slide-down {
    animation: slideDown 0.3s ease-out forwards;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.mt-10 { margin-top: 0.625rem; }
.mt-20 { margin-top: 1.25rem; }
.mb-15 { margin-bottom: 1rem; }
.block { display: block; }

/* Panels and Alerts */
.panel {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.info-alert {
    background-color: #eff6ff;
    border-left: 4px solid var(--info);
    padding: 1rem;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: #1e3a8a;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.warning-panel {
    background-color: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 4px solid var(--warning);
}

.warning-panel p {
    color: #92400e;
    font-size: 0.95rem;
}

/* Erros */
.error-msg {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    min-height: 1.2rem;
}

.input-error {
    border-color: var(--error) !important;
    background-color: #fef2f2 !important;
}

/* Lista da Equipe */
.repeater-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.repeater-item {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: grid;
    grid-template-columns: 2fr 2fr 1.5fr 1.5fr auto;
    gap: 1rem;
    align-items: end;
    animation: fadeIn 0.3s ease;
}

@media (max-width: 768px) {
    .repeater-item {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Contadores */
.licence-counter, .agent-counter {
    font-size: 0.9rem;
    font-weight: 500;
}

.text-muted {
    color: var(--text-muted);
}

.progress-bar-container {
    width: 150px;
    height: 8px;
    background-color: var(--secondary);
    border-radius: 4px;
    margin-bottom: 0.25rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary);
    transition: width 0.3s ease, background-color 0.3s ease;
}

.progress-bar.limit-reached {
    background-color: var(--error);
}

.agent-counter {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Agentes: Busca e Chips */
.agent-search-container {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.search-box input {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%236b7280" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>');
    background-repeat: no-repeat;
    background-position: 1rem center;
    padding-left: 2.75rem;
    border-radius: 9999px;
}

.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.chip {
    padding: 0.35rem 0.85rem;
    background-color: var(--secondary);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.chip:hover {
    background-color: var(--secondary-hover);
}

.chip.active {
    background-color: #e0e7ff;
    color: var(--primary-hover);
    border-color: var(--primary);
}

/* Resultados da Busca de Agentes */
.search-results {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.agent-result-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.agent-result-item:last-child {
    border-bottom: none;
}

.agent-result-item:hover {
    background-color: var(--secondary);
}

.agent-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.agent-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.agent-category-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background-color: #f3f4f6;
    color: #4b5563;
    border-radius: 4px;
    font-size: 0.7rem;
    margin-top: 0.25rem;
}

.btn-add-agent {
    background-color: var(--secondary);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.agent-result-item:hover .btn-add-agent {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Agentes Selecionados (Cards) */
.selected-agents h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    background-color: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
}

#selected-agents-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.agent-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    animation: slideDown 0.3s ease;
}

.agent-card-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.agent-card-header:hover {
    background-color: var(--secondary);
}

.agent-card-title {
    font-weight: 600;
    font-size: 1rem;
    word-break: break-word;
}

.agent-card-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.agent-card-body {
    padding: 0 1rem 1rem 1rem;
    border-top: 1px solid var(--border);
    display: none;
}

.agent-card-body.open {
    display: block;
    animation: fadeIn 0.3s ease;
}

.agent-card-body h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-main);
}

/* Modais */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background-color: var(--surface);
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 1001;
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

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

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

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

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Comparativo Quente/Frio */
.comparison-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
    background: var(--background);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.example-good { color: #065f46; font-size: 0.85rem; }
.example-bad { color: #991b1b; font-size: 0.85rem; }

/* Painel de Erros Final */
.error-panel {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--surface);
    border-left: 4px solid var(--error);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    width: 350px;
    max-width: calc(100vw - 2rem);
    max-height: 60vh;
    overflow-y: auto;
    z-index: 900;
    animation: slideLeft 0.3s ease;
}

@media (max-width: 640px) {
    .error-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-width: 100vw;
        max-height: 50vh;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
    }
}

/* Reserva espaço no fim da página para o painel fixo não cobrir o botão
   "Abrir Chamado" — no celular ele ficava por cima e o toque não passava. */
body.tem-pendencias .form-actions {
    padding-bottom: 55vh;
}

.error-panel-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
}

/* Pendências que NÃO bloqueiam o envio */
.error-panel--warn {
    border-left-color: var(--warning);
}

.error-panel--warn h4 {
    color: #b45309;
}

.error-panel--warn li a::before {
    color: var(--warning);
}

.error-panel-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

@keyframes slideLeft {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

.error-panel h4 {
    color: var(--error);
    margin-bottom: 0.5rem;
}

.error-panel ul {
    list-style: none;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.error-panel li a {
    color: var(--text-main);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-panel li a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.error-panel li a::before {
    content: "•";
    color: var(--error);
}
