/* ===== TOKENS ===== */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --accent-bg: #e0f2fe;
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --purple: #8b5cf6;
  --purple-bg: #ede9fe;
  --sidebar-w: 220px;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}
[data-theme="dark"] {
  --bg: #0d0f14;
  --surface: #161923;
  --surface2: #1e2433;
  --border: #2a3045;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-bg: #0c2a3a;
  --success-bg: #052e1c;
  --warning-bg: #2d1e00;
  --danger-bg: #2d0a0a;
  --purple-bg: #1e1530;
  --shadow: 0 1px 4px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; transition: background .2s, color .2s; }
h1,h2,h3,h4,h5 { font-family: 'Syne', sans-serif; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }

/* ===== LOGIN ===== */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0c1a2e 0%, #0f2846 50%, #0c1a2e 100%);
}
.login-card {
  background: var(--surface); border-radius: 16px; padding: 40px;
  width: 380px; box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; gap: 20px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.login-brand h1 { font-size: 26px; color: var(--text); line-height: 1; }
.login-brand p { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.brand-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #0369a1);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 24px; flex-shrink: 0;
}
.login-error { color: var(--danger); font-size: 13px; padding: 10px 12px; background: var(--danger-bg); border-radius: 8px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100; transition: transform .25s;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 20px 16px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-icon-sm {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #0369a1);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; flex-shrink: 0;
}
.brand-name { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 16px; color: var(--text); }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; border: none; background: transparent; color: var(--text-muted);
  font-size: 14px; font-weight: 500; width: 100%; text-align: left; transition: all .15s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.nav-item i { font-size: 18px; flex-shrink: 0; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 14px 12px;
  border-top: 1px solid var(--border);
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-bg);
  display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 16px; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 11px; color: var(--text-muted); }

/* ===== MAIN ===== */
.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar h2 { font-size: 18px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.main-content { padding: 24px; flex: 1; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: 8px; border: none; font-size: 13px; font-weight: 600; transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .85; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon {
  width: 34px; height: 34px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-muted); display: flex; align-items: center; justify-content: center;
  font-size: 18px; transition: all .15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ===== FORMS ===== */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions-col { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
input[type="text"], input[type="date"], input[type="email"], input[type="password"],
select, textarea {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.required { color: var(--danger); }

/* ===== CARDS ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--border); }

/* ===== DASH FILTERS ===== */
.dash-filters {
  margin-bottom: 20px;
  padding: 14px 20px;
}
.dash-filters-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}
.dash-filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.dash-filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.dash-filter-group input,
.dash-filter-group select {
  min-width: 160px;
}

/* ===== STATS GRID ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); border-top: 3px solid var(--accent);
}
.stat-card.blue { border-top-color: var(--accent); }
.stat-card.green { border-top-color: var(--success); }
.stat-card.amber { border-top-color: var(--warning); }
.stat-card.purple { border-top-color: var(--purple); }
.stat-card.red { border-top-color: var(--danger); }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 28px; font-family: 'Syne', sans-serif; font-weight: 700; margin-top: 6px; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== DASHBOARD CHARTS ===== */
.dashboard-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.chart-card h4 { font-size: 14px; margin-bottom: 16px; color: var(--text); }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { font-size: 12px; color: var(--text-muted); width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--bg); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width .5s; }
.bar-count { font-size: 12px; font-weight: 600; color: var(--text); min-width: 24px; text-align: right; }

/* ===== TABLE ===== */
.filters-row { display: flex; flex-wrap: wrap; gap: 10px; padding: 0; }
.search-input { flex: 1; min-width: 180px; }
.filter-select { min-width: 150px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table th { font-size: 12px; font-weight: 700; color: var(--text-muted); background: var(--surface2); text-transform: uppercase; letter-spacing: .5px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface2); }
.th-sort { cursor: pointer; user-select: none; }
.th-sort:hover { color: var(--text); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px;
  border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-aberto { background: var(--accent-bg); color: var(--accent); }
.badge-andamento { background: var(--warning-bg); color: var(--warning); }
.badge-concluido { background: var(--success-bg); color: var(--success); }
.badge-cancelado { background: var(--border); color: var(--text-muted); }

/* ===== TAREFAS (dentro do modal) ===== */
.tarefas-section { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.tarefas-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tarefas-header h4, .setores-header h4, .responsaveis-header h4 { font-size: 14px; color: var(--text); }
.tarefa-item {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px;
}
.tarefa-item-header { display: flex; justify-content: space-between; align-items: center; }
.tarefa-item-label { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.tarefa-item-footer { display: flex; justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.tarefa-confirmada {
  background: var(--success-bg); border: 1px solid var(--success);
  border-radius: 8px; padding: 12px 14px; margin-bottom: 10px;
}
.tarefa-confirmada-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tarefa-confirmada-info { display: flex; align-items: center; gap: 8px; }
.tarefa-confirmada-info i { font-size: 16px; }
.tarefa-confirmada-body { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; font-size: 12px; color: var(--text-muted); }
.tarefa-confirmada-body i { font-size: 13px; margin-right: 3px; }
.tarefa-confirmada-atividade { width: 100%; font-size: 13px; color: var(--text); margin: 4px 0 0; }
.tarefa-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tarefa-field-full { grid-column: 1 / -1; }

/* ===== EMPRESAS ===== */
.empresas-header { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.empresas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.empresa-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); border-top: 3px solid var(--accent); overflow: hidden;
}
.empresa-card-header { padding: 16px 20px 12px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--border); }
.empresa-card-title { font-size: 15px; font-weight: 700; }
.empresa-card-cnpj { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.empresa-card-body { padding: 14px 20px; }
.empresa-card-actions { display: flex; gap: 6px; }
.setor-item {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px;
}
.setor-item-header { display: flex; justify-content: space-between; align-items: center; }
.setor-nome { font-size: 13px; font-weight: 700; }
.setor-resp-count { font-size: 11px; color: var(--text-muted); }
.setor-responsaveis { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.resp-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); padding: 3px 0; }
.resp-item i { font-size: 14px; color: var(--accent); }
.setor-actions { display: flex; gap: 4px; }

/* ===== SETORES / RESPONSÁVEIS (dentro do modal) ===== */
.setores-section, .responsaveis-section { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.setores-header, .responsaveis-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.setor-form-item, .resp-form-item {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px;
}
.setor-form-item input, .resp-form-item input { flex: 1; }
.resp-form-item { flex-wrap: wrap; }
.resp-form-item .form-group { flex: 1; min-width: 140px; }

/* ===== MODAL VER REGISTRO ===== */
.ver-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.ver-field { display: flex; flex-direction: column; gap: 4px; }
.ver-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.ver-value { font-size: 14px; color: var(--text); }
.ver-obs { grid-column: 1 / -1; }
.tarefas-view { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.tarefa-view-item {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 8px;
}
.tarefa-view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tarefa-view-setor { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; }
.tarefa-view-resp { font-size: 12px; color: var(--text-muted); }
.tarefa-view-atividade { font-size: 13px; color: var(--text); margin-top: 6px; }
.tarefa-prazo {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; margin-top: 6px;
  padding: 3px 8px; border-radius: 20px;
}
.prazo-ok      { background: var(--success-bg); color: var(--success); }
.prazo-proximo { background: var(--warning-bg); color: var(--warning); }
.prazo-hoje    { background: var(--warning-bg); color: var(--warning); }
.prazo-vencido { background: var(--danger-bg);  color: var(--danger); }
.tarefa-status-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.tarefa-status-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.tarefa-status-row select { font-size: 12px; padding: 4px 8px; border-radius: 6px; }

/* ===== RELATÓRIO ===== */
.relatorio-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.relatorio-filters { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.relatorio-filters h3 { font-size: 15px; margin-bottom: 4px; }
.relatorio-preview { padding: 24px; min-height: 400px; }
.rel-section { margin-bottom: 24px; }
.rel-section h4 { font-size: 14px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.rel-stats { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 12px; }
.rel-stat { text-align: center; }
.rel-stat-val { font-size: 22px; font-weight: 700; font-family: 'Syne', sans-serif; color: var(--accent); }
.rel-stat-label { font-size: 11px; color: var(--text-muted); }
.muted-text { color: var(--text-muted); font-size: 13px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
}
.modal-lg { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-header h3 { font-size: 16px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }

/* ===== PAGINATION ===== */
.pagination { display: flex; align-items: center; gap: 4px; padding: 12px 16px; justify-content: center; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all .15s;
}
.page-btn:hover { background: var(--bg); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 18px; box-shadow: var(--shadow-md); font-size: 13px; font-weight: 500;
  max-width: 320px; display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

/* ===== MOBILE ===== */
.mobile-menu-btn { display: none; }
.mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99; }
@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-overlay.open { display: block; }
  .main-wrap { margin-left: 0; }
  .dashboard-charts { grid-template-columns: 1fr; }
  .relatorio-layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .ver-grid { grid-template-columns: 1fr; }
  .tarefa-fields { grid-template-columns: 1fr; }
}

/* ===== MISC ===== */
.empty-row td { text-align: center; color: var(--text-muted); padding: 40px; font-size: 13px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--accent-bg); color: var(--accent); }
.divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }

.page { display: none; }
.page.active { display: block; }

@keyframes slideIn { from { opacity: 0; transform: translateY(-16px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
