:root {
  --azul: #1e3a5f;
  --azul-claro: #2d5488;
  --verde: #7ac143;
  --verde-escuro: #5a9431;
  --fundo: #f4f6f9;
  --branco: #ffffff;
  --texto: #1a2332;
  --texto2: #5a6a7e;
  --texto3: #93a1b3;
  --borda: #e3e8ef;
  --vermelho: #d9534f;
  --amarelo: #f0ad4e;
  --radius: 12px;
  --sombra: 0 1px 3px rgba(16,24,40,.08);
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--fundo); color: var(--texto); font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--azul-claro); text-decoration: none; }

/* ===== LAYOUT MOBILE-FIRST ===== */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--azul); color: #fff; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar .logo { font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.topbar .logo span { color: var(--verde); }
.main { flex: 1; padding: 16px; padding-bottom: 80px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--branco); border-top: 1px solid var(--borda);
  display: flex; justify-content: space-around; padding: 6px 0 max(6px, env(safe-area-inset-bottom));
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--texto3); padding: 4px 12px; border-radius: 8px;
}
.bottomnav a.active { color: var(--azul); font-weight: 600; }
.bottomnav .icon { font-size: 20px; line-height: 1; }

/* Sidebar (desktop) */
.sidebar { display: none; }

@media (min-width: 900px) {
  .app { flex-direction: row; }
  .bottomnav { display: none; }
  .sidebar {
    display: flex; flex-direction: column; width: 240px; min-height: 100vh;
    background: var(--azul); color: #fff; padding: 20px 0; position: sticky; top: 0;
    height: 100vh;
  }
  .sidebar .logo { font-size: 20px; font-weight: 700; padding: 0 20px 24px; letter-spacing: .5px; }
  .sidebar .logo span { color: var(--verde); }
  .sidebar a {
    color: rgba(255,255,255,.75); padding: 11px 20px; font-size: 14px;
    display: flex; align-items: center; gap: 10px; border-left: 3px solid transparent;
  }
  .sidebar a:hover { background: rgba(255,255,255,.06); color: #fff; }
  .sidebar a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--verde); font-weight: 600; }
  .sidebar .spacer { flex: 1; }
  .topbar { display: none; }
  .main { padding: 32px; padding-bottom: 32px; }
}

/* ===== COMPONENTES ===== */
.card {
  background: var(--branco); border-radius: var(--radius);
  box-shadow: var(--sombra); padding: 18px; margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.page-title { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--texto2); font-size: 13px; margin-bottom: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; padding: 12px 18px; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: opacity .15s; min-height: 44px;
}
.btn:active { opacity: .8; }
.btn-p { background: var(--azul); color: #fff; }
.btn-v { background: var(--verde); color: #fff; }
.btn-g { background: var(--fundo); color: var(--texto2); border: 1px solid var(--borda); }
.btn-block { width: 100%; }

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--texto2); }
.form-input, .form-select, .form-textarea {
  width: 100%; border: 1.5px solid var(--borda); border-radius: 10px;
  padding: 12px 14px; font-size: 15px; background: var(--branco);
  min-height: 46px; font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--azul-claro);
}
.form-textarea { min-height: 100px; resize: vertical; }

.badge {
  display: inline-block; padding: 4px 10px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
}
.b-verde { background: #e8f5db; color: var(--verde-escuro); }
.b-azul { background: #e3ecf7; color: var(--azul-claro); }
.b-amarelo { background: #fdf3e0; color: #b07c2a; }
.b-vermelho { background: #fbe5e4; color: var(--vermelho); }
.b-cinza { background: var(--fundo); color: var(--texto3); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; padding: 10px 12px; color: var(--texto3); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1.5px solid var(--borda); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--borda); }

/* KTH nivel selector - touch friendly */
.kth-niveis { display: flex; gap: 6px; flex-wrap: wrap; }
.kth-nivel {
  width: 42px; height: 42px; border-radius: 10px; border: 1.5px solid var(--borda);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 15px; cursor: pointer; background: var(--branco); color: var(--texto2);
}
.kth-nivel.sel { background: var(--azul); color: #fff; border-color: var(--azul); }

/* Radar/dimensao cards */
.dim-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .dim-grid { grid-template-columns: repeat(3, 1fr); } }
.dim-card {
  background: var(--branco); border: 1.5px solid var(--borda); border-radius: var(--radius);
  padding: 14px; text-align: center;
}
.dim-card .sigla { font-size: 12px; font-weight: 700; color: var(--texto3); letter-spacing: .5px; }
.dim-card .nivel { font-size: 28px; font-weight: 800; color: var(--azul); margin: 4px 0; }
.dim-card .status { font-size: 11px; }

/* Tabs mobile-friendly */
.tabs { display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 16px; padding-bottom: 4px; }
.tab {
  white-space: nowrap; padding: 10px 16px; border-radius: 20px; font-size: 13px;
  font-weight: 600; background: var(--branco); color: var(--texto2); border: 1.5px solid var(--borda);
  cursor: pointer; flex-shrink: 0;
}
.tab.active { background: var(--azul); color: #fff; border-color: var(--azul); }

.toast {
  position: fixed; top: 16px; left: 16px; right: 16px; z-index: 100;
  background: var(--verde); color: #fff; padding: 14px 18px; border-radius: 10px;
  font-weight: 600; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  animation: slideDown .3s ease;
}
@media (min-width: 700px) { .toast { left: auto; right: 24px; max-width: 380px; } }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--azul); padding: 20px;
}
.login-box {
  background: var(--branco); border-radius: 16px; padding: 32px 24px;
  width: 100%; max-width: 400px;
}
.login-box .logo { text-align: center; font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.login-box .logo span { color: var(--verde); }

@media (min-width: 600px) {
  [id^="modal-"] {
    align-items: center !important;
  }
  [id^="modal-"] > div {
    border-radius: 16px !important;
    max-height: 85vh;
  }
}

/* ── Abas ── */
.tabs { display:flex; gap:.5rem; border-bottom:2px solid var(--border); margin-bottom:1.5rem; }
.tab-btn {
  background:none; border:none; padding:.6rem 1.1rem; font-size:.9rem;
  color:var(--text3); cursor:pointer; border-bottom:3px solid transparent;
  margin-bottom:-2px; font-weight:500; transition:color .15s;
}
.tab-btn:hover { color:var(--text1); }
.tab-btn.active { color:var(--primary); border-bottom-color:var(--primary); font-weight:600; }

/* ── Modais ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 1.5rem;
  box-shadow: 0 -4px 24px rgba(0,0,0,.15);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-title { font-weight: 700; font-size: 1.05rem; }
.modal-close {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--text3); padding: .25rem .5rem;
}
.modal-footer {
  display: flex; justify-content: flex-end;
  gap: .5rem; margin-top: 1.25rem;
}
