/* =============================================
   TDM Excellence Drivers – Global Styles
   Colors: #D3422A (red), #0D274C (navy), #A1A8B4 (steel)
   ============================================= */

:root {
  --red: #D3422A;
  --red-light: #e85b42;
  --red-dark: #a83220;
  --navy: #0D274C;
  --navy-light: #1a3f70;
  --navy-dark: #071828;
  --steel: #A1A8B4;
  --steel-light: #c5cad3;
  --steel-dark: #7e8693;
  --white: #ffffff;
  --bg: #f0f3f8;
  --bg2: #e6eaf2;
  --card: #ffffff;
  --border: #dde3ed;
  --text: #1a2540;
  --gray: #6b7a99;
  --success: #1db554;
  --warning: #f5a623;
  --danger: #D3422A;
  --info: #2196f3;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(13,39,76,0.10);
  --shadow-hover: 0 6px 24px rgba(13,39,76,0.16);
  --transition: 0.22s ease;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ========== TOPBAR ========== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.hamburger {
  background: none; border: none; color: var(--white);
  font-size: 18px; cursor: pointer; padding: 6px;
  border-radius: 6px; transition: background var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.hamburger:hover { background: rgba(255,255,255,0.15); }

.logo-wrap { display: flex; align-items: center; gap: 10px; }

.logo-icon {
  width: 36px; height: 36px;
  background: var(--red);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.logo-title {
  display: block;
  font-size: 15px; font-weight: 700; line-height: 1.2;
  letter-spacing: -0.3px;
}
.logo-sub {
  display: block;
  font-size: 10px; color: var(--steel-light);
  letter-spacing: 0.5px; text-transform: uppercase;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.badge-week {
  background: rgba(255,255,255,0.12);
  color: var(--steel-light);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px; font-weight: 500;
  display: none;
}
@media (min-width: 640px) { .badge-week { display: flex; align-items: center; gap: 6px; } }

.user-avatar {
  width: 36px; height: 36px;
  background: var(--red);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; cursor: pointer;
  border: 2px solid rgba(255,255,255,0.2);
}

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed;
  top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--navy-dark);
  overflow-y: auto;
  z-index: 900;
  transform: translateX(-100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}

.sidebar.open { transform: translateX(0); }

@media (min-width: 1024px) {
  .sidebar { transform: translateX(0); }
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.sidebar-nav ul { list-style: none; }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px;
  color: var(--steel);
  text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: var(--white);
}

.nav-link.active {
  background: rgba(211,66,42,0.18);
  color: var(--white);
  border-left-color: var(--red);
}

.nav-link i { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer {
  padding: 16px 20px;
  color: var(--steel-dark);
  font-size: 11px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ========== OVERLAY ========== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 800;
}
.overlay.active { display: block; }

/* ========== MAIN CONTENT ========== */
.main-content {
  margin-top: var(--topbar-h);
  padding: 24px 16px;
  min-height: calc(100vh - var(--topbar-h));
  transition: margin-left var(--transition);
}

@media (min-width: 1024px) {
  .main-content { margin-left: var(--sidebar-w); padding: 28px 28px; }
}

/* ========== PAGES ========== */
.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
}

.page-header h1 {
  font-size: 22px; font-weight: 700;
  color: var(--navy);
  display: flex; align-items: center; gap: 10px;
}
.page-header h1 i { color: var(--red); }

.page-sub {
  color: var(--gray); font-size: 13px; margin-top: 4px;
}

/* ========== KPI GRID ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1280px) { .kpi-grid { grid-template-columns: repeat(5, 1fr); } }

.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--navy);
  transition: box-shadow var(--transition), transform var(--transition);
  position: relative; overflow: hidden;
}
.kpi-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.kpi-card.red { border-left-color: var(--red); }
.kpi-card.green { border-left-color: var(--success); }
.kpi-card.orange { border-left-color: var(--warning); }
.kpi-card.blue { border-left-color: var(--info); }

.kpi-label { font-size: 11px; font-weight: 600; color: var(--gray); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 30px; font-weight: 800; color: var(--navy); line-height: 1.1; margin: 6px 0 4px; }
.kpi-card.red .kpi-value { color: var(--red); }
.kpi-card.green .kpi-value { color: var(--success); }
.kpi-card.orange .kpi-value { color: var(--warning); }
.kpi-card.blue .kpi-value { color: var(--info); }
.kpi-trend { font-size: 12px; color: var(--gray); }
.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--red); }
.kpi-icon {
  position: absolute; top: 12px; right: 14px;
  font-size: 28px; opacity: 0.08;
  color: var(--navy);
}

/* ========== CHARTS ========== */
.charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
@media (min-width: 768px) { .charts-row { grid-template-columns: 1fr 1fr; } }

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-card h3 {
  font-size: 14px; font-weight: 600; color: var(--navy);
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px;
}
.chart-card h3 i { color: var(--red); }

/* ========== SECTION CARD ========== */
.section-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.section-card h3 {
  font-size: 14px; font-weight: 600; color: var(--navy);
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.section-card h3 i { color: var(--red); }

/* ========== ATTENTION LIST ========== */
.attention-list { display: flex; flex-direction: column; gap: 8px; }

.attention-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
}
.attention-item.critical { background: rgba(211,66,42,0.08); border-left: 3px solid var(--red); }
.attention-item.warning { background: rgba(245,166,35,0.08); border-left: 3px solid var(--warning); }
.attention-item.info { background: rgba(33,150,243,0.08); border-left: 3px solid var(--info); }

.attention-item i { margin-top: 2px; }
.attention-item.critical i { color: var(--red); }
.attention-item.warning i { color: var(--warning); }
.attention-item.info i { color: var(--info); }

/* ========== PRIORITY DRIVERS ========== */
.priority-drivers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.driver-priority-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border);
}

.driver-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: var(--white);
  flex-shrink: 0;
  background: var(--navy);
}

.driver-info { min-width: 0; }
.driver-info .name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.driver-info .route { font-size: 12px; color: var(--gray); }
.score-badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.score-badge.high { background: rgba(29,181,84,0.12); color: var(--success); }
.score-badge.mid { background: rgba(245,166,35,0.12); color: var(--warning); }
.score-badge.low { background: rgba(211,66,42,0.12); color: var(--red); }

/* ========== WEEK GRID ========== */
.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.week-day-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.week-day-header {
  background: var(--navy);
  color: var(--white);
  padding: 10px 14px;
  font-size: 13px; font-weight: 600;
}
.week-day-header.today { background: var(--red); }

.week-day-body { padding: 10px 14px; }

.routine-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--bg2);
}
.routine-item:last-child { border-bottom: none; }
.routine-item .ri-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ri-dot.done { background: var(--success); }
.ri-dot.pending { background: var(--warning); }
.ri-dot.alert { background: var(--red); }

/* ========== TOOLBAR ========== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.search-input {
  flex: 1; min-width: 180px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px; font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color var(--transition);
}
.search-input:focus { outline: none; border-color: var(--navy); }

.filter-select {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px; font-family: inherit;
  color: var(--text);
  background: var(--white);
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--navy); }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; border: none;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-light); }
.btn-secondary { background: var(--bg2); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: var(--red-light); }
.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { background: #17994a; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 9px; }

/* ========== TABLE ========== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%; border-collapse: collapse;
  background: var(--card);
  font-size: 13px;
}

.data-table thead th {
  background: var(--navy);
  color: var(--white);
  padding: 11px 14px;
  text-align: left;
  font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.4px;
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.data-table tbody tr:hover { background: var(--bg); }
.data-table tbody tr:last-child { border-bottom: none; }

.data-table td {
  padding: 10px 14px;
  vertical-align: middle;
}

/* Status badges */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.status-badge.ativo, .status-badge.ativa, .status-badge.resolvida { background: rgba(29,181,84,0.12); color: var(--success); }
.status-badge.inativo, .status-badge.suspensa { background: rgba(161,168,180,0.2); color: var(--steel-dark); }
.status-badge.afastado, .status-badge.aberta { background: rgba(211,66,42,0.12); color: var(--red); }
.status-badge.em-treino, .status-badge.em-analise { background: rgba(245,166,35,0.12); color: var(--warning); }

/* Editable table */
.editable-table td[contenteditable="true"] {
  cursor: text;
  background: rgba(13,39,76,0.03);
  outline: 2px solid transparent;
  border-radius: 4px;
  transition: outline var(--transition);
}
.editable-table td[contenteditable="true"]:focus {
  outline-color: var(--navy);
  background: rgba(13,39,76,0.06);
}

/* ========== ROTA TABS ========== */
.rota-tabs, .gestao-tabs {
  display: flex; gap: 4px;
  background: var(--bg2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 0;
  width: fit-content;
}

.tab-btn {
  padding: 8px 18px;
  border: none; background: none;
  border-radius: 7px;
  font-size: 13px; font-weight: 600; font-family: inherit;
  color: var(--gray); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.tab-btn.active { background: var(--card); color: var(--navy); box-shadow: 0 1px 6px rgba(0,0,0,0.1); }

.tab-content, .gtab-content { display: none; }
.tab-content.active, .gtab-content.active { display: block; }

/* ========== TRAINING WEEK ========== */
.training-week {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}

.training-day-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.training-day-header {
  background: var(--navy);
  color: var(--white);
  padding: 10px 14px;
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
}

.training-day-header .driver-count {
  background: var(--red);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 11px; font-weight: 700;
}

.training-day-body { padding: 8px 14px; }

.training-driver-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--bg2);
}
.training-driver-item:last-child { border-bottom: none; }
.training-driver-item i { color: var(--navy); }
.training-tag {
  margin-left: auto;
  font-size: 10px; font-weight: 600;
  background: var(--bg2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--gray);
}

/* ========== EXPORT GRID ========== */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.export-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  gap: 10px;
  transition: box-shadow var(--transition);
}
.export-card:hover { box-shadow: var(--shadow-hover); }

.export-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--white);
}
.export-icon.red { background: var(--red); }
.export-icon.blue { background: var(--navy); }
.export-icon.orange { background: var(--warning); }
.export-icon.green { background: var(--success); }

.export-card h3 { font-size: 15px; font-weight: 700; color: var(--navy); }
.export-card p { font-size: 12px; color: var(--gray); flex: 1; }

.export-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ========== SHEETS INFO ========== */
.sheets-info {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
}
.sheets-id {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px; color: var(--gray);
  flex: 1; min-width: 200px;
  word-break: break-all;
}
.sheets-info-box {
  margin-top: 14px;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px; color: var(--text);
  line-height: 1.8;
}
.sheets-info-box.hidden { display: none; }

/* ========== MODALS ========== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: 14px;
  width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { opacity:0; transform:scale(0.92) translateY(20px); } to { opacity:1; transform:scale(1) translateY(0); } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; color: var(--navy); display:flex;align-items:center;gap:8px; }
.modal-header h3 i { color: var(--red); }

.modal-close {
  background: none; border: none;
  color: var(--gray); font-size: 18px;
  cursor: pointer; padding: 4px;
  border-radius: 4px; transition: color var(--transition);
}
.modal-close:hover { color: var(--red); }

.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 440px) { .form-row { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--navy); }
.form-group input, .form-group select, .form-group textarea {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px; font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--navy);
  background: var(--white);
}
.form-group textarea { resize: vertical; }

.modal-footer {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ========== RESPONSABILIDADES ========== */
.resp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.resp-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
  border-left: 3px solid var(--navy);
  font-size: 13px;
}
.resp-item .resp-role { font-size: 11px; color: var(--gray); font-weight: 600; text-transform: uppercase; }
.resp-item .resp-person { font-weight: 700; color: var(--navy); margin: 2px 0; }
.resp-item .resp-task { color: var(--text); font-size: 12px; }

/* ========== NEGATIVE SCORE ========== */
.negative-score-list { display: flex; flex-direction: column; gap: 8px; }

.neg-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: rgba(211,66,42,0.06);
  border-radius: 8px;
  border-left: 3px solid var(--red);
}
.neg-item .neg-name { font-weight: 600; font-size: 13px; flex: 1; }
.neg-item .neg-score { color: var(--red); font-weight: 700; }
.neg-item .neg-reason { font-size: 12px; color: var(--gray); }

/* ========== TOAST ========== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--navy);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  z-index: 9999;
  opacity: 0; transform: translateY(20px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: var(--shadow-hover);
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--red); }
.toast.warning { background: var(--warning); color: var(--navy); }

/* ========== UTILITIES ========== */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.hidden { display: none !important; }

.info-badge {
  font-size: 12px; color: var(--gray);
  background: rgba(33,150,243,0.08);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(33,150,243,0.2);
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--steel); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--navy); }

/* ========== ACTION ICONS ========== */
.action-btn {
  background: none; border: none;
  color: var(--gray);
  cursor: pointer; padding: 4px 7px;
  border-radius: 5px; font-size: 14px;
  transition: color var(--transition), background var(--transition);
}
.action-btn:hover.edit { color: var(--navy); background: rgba(13,39,76,0.08); }
.action-btn:hover.delete { color: var(--red); background: rgba(211,66,42,0.08); }
