@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-bg: #eef2ff;
  --accent-border: #c7d2fe;

  --green: #059669;
  --green-bg: #ecfdf5;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 1px 3px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.06), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-lg: 0 20px 40px rgba(15,23,42,0.10), 0 8px 16px rgba(15,23,42,0.06);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #12161f;
  --surface-2: #171c27;
  --border: #232a38;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent-bg: rgba(79,70,229,0.15);
  --accent-border: rgba(99,102,241,0.35);
  --green-bg: rgba(5,150,105,0.12);
  --red-bg: rgba(220,38,38,0.12);
  --amber-bg: rgba(217,119,6,0.12);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 22px; margin-bottom: 20px; }
h3 { font-size: 16px; margin-bottom: 14px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- LAYOUT ---- */
.app {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar-header {
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header strong {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.sidebar-logo { display: block; width: 100%; max-width: 190px; height: auto; }
.main {
  flex: 1;
  min-width: 0;
}
.content {
  padding: 32px 36px;
  max-width: 1600px;
  margin: 0 auto;
}
[data-page] { display: none; }
[data-page].active { display: block; }

/* ---- NAV ---- */
.nav {
  padding: 14px 12px;
  flex: 1;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 13.5px;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }

/* ---- CONFIGURAÇÕES: abas ---- */
.config-tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.config-tab-btn {
  background: none; border: none; padding: 10px 14px; font-size: 13px; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.config-tab-btn:hover { color: var(--text); }
.config-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
[data-config-tab] { display: none; }
[data-config-tab].active { display: block; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--surface-2);
  color: var(--text);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.form-group textarea { min-height: 90px; resize: vertical; }

/* ---- CARDS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

/* ---- METRICS ---- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.m-label { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.m-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }

/* ---- TABLES ---- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 16px;
  box-shadow: var(--shadow-sm);
}
thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-2);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.table-turmas tbody td { padding: 16px 18px; vertical-align: middle; }
.table-turmas thead th { padding: 12px 18px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.row-highlight td { background: var(--accent-bg); font-weight: 600; }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  box-shadow: var(--shadow-lg);
  position: relative;
  display: flex;
  flex-direction: column;
}
.modal.modal-lg { max-width: 700px; }
#modal-content { overflow-y: auto; }
.modal-close {
  position: absolute; top: 14px; right: 14px; z-index: 2;
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 14px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--border); color: var(--text); }

/* ---- Bloco de contrato/assinaturas (mesmo visual do PDF e da tela pública) ---- */
.contract-logo { height: 28px; width: auto; }
.contract-box {
  max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px;
  padding: 20px; font-size: 13px; line-height: 1.55; text-align: justify; background: var(--surface-2); margin-bottom: 16px;
}
.sign-section { margin-bottom: 16px; }
.sign-section h4 { font-size: 12px; color: var(--accent); margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; }
.sign-box { display: flex; gap: 10px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 8px; font-size: 12.5px; line-height: 1.5; }
.sign-box.sign-ok { background: var(--green-bg); border-color: #a7e8c5; }
.sign-box.sign-pending { background: var(--amber-bg); border-color: #fde3a7; }
.sign-check { flex-shrink: 0; }
.sign-status { color: var(--green); font-weight: 700; }
.sign-pending .sign-status { color: var(--amber); }
.sign-meta { color: var(--muted); font-size: 11px; }
.sign-footnote { font-size: 10.5px; color: var(--muted); line-height: 1.5; margin-top: 4px; }
.status-badge { padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-badge-green { background: var(--green-bg); color: var(--green); }
.status-badge-amber { background: var(--amber-bg); color: var(--amber); }
.btn-toggle-on { background: var(--green-bg); color: var(--green); border: 1px solid #a7e8c5; }
.btn-toggle-on:hover { background: var(--green); color: #fff; }
.btn-toggle-off { background: var(--red-bg); color: var(--red); border: 1px solid #fca5a5; }
.btn-toggle-off:hover { background: var(--red); color: #fff; }

/* ---- LOGIN ---- */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, var(--accent-bg), transparent 45%),
    radial-gradient(circle at 80% 80%, var(--accent-bg), transparent 45%),
    var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 44px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-box h1 { font-size: 22px; margin-bottom: 4px; }
.login-logo { display: block; width: 100%; max-width: 260px; height: auto; margin: 0 auto 12px; }

/* ---- RANKING / LEADERBOARD ---- */
.rank-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.rank-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.rank-mes-nav { display: flex; align-items: center; gap: 8px; }
.rank-mes-nav strong { font-size: 13.5px; min-width: 150px; text-align: center; }

.rank-podium-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 40px 24px 0;
  margin-bottom: 22px;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.14), transparent 40%),
    radial-gradient(circle at 85% 15%, rgba(255,255,255,0.10), transparent 35%),
    linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #a21caf 100%);
  box-shadow: 0 16px 40px -12px rgba(124,58,237,0.55);
}
.rank-podium-card::before {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.35) 1.5px, transparent 1.5px);
  background-size: 26px 26px;
  opacity: 0.12;
  pointer-events: none;
}
.rank-podium { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 18px; }
.rank-slot { display: flex; flex-direction: column; align-items: center; width: 120px; }
.rank-slot-2 { order: 1; padding-bottom: 8px; }
.rank-slot-1 { order: 2; padding-bottom: 0; }
.rank-slot-3 { order: 3; padding-bottom: 20px; }

.rank-crown { font-size: 26px; margin-bottom: -6px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.35)); animation: rank-float 2.4s ease-in-out infinite; }
@keyframes rank-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.rank-avatar {
  width: 62px; height: 62px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #fff;
  background: linear-gradient(135deg, #fbbf24, #f97316);
  border: 3px solid rgba(255,255,255,0.85);
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  object-fit: cover;
  flex-shrink: 0;
}
.rank-avatar-lg { width: 84px; height: 84px; font-size: 26px; border-width: 4px; box-shadow: 0 0 0 5px rgba(251,191,36,0.35), 0 10px 22px rgba(0,0,0,0.3); }
.rank-slot-2 .rank-avatar { background: linear-gradient(135deg, #cbd5e1, #64748b); }
.rank-slot-3 .rank-avatar { background: linear-gradient(135deg, #d97706, #92400e); }
.rank-avatar-sm { width: 36px; height: 36px; font-size: 13px; border-width: 2px; box-shadow: none; }

.rank-podium-name { color: #fff; font-weight: 700; font-size: 12.5px; margin-top: 8px; text-align: center; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-podium-score { color: #fde68a; font-weight: 800; font-size: 15px; margin-top: 2px; }
.rank-podium-score span { color: rgba(255,255,255,0.75); font-weight: 500; font-size: 10.5px; margin-left: 3px; }
.rank-podium-valor { color: rgba(255,255,255,0.85); font-size: 10.5px; margin-top: 1px; }

.rank-bar { width: 100%; margin-top: 14px; border-radius: 10px 10px 0 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; font-weight: 800; font-size: 20px; color: rgba(255,255,255,0.55); }
.rank-bar-1 { height: 78px; background: linear-gradient(180deg, #fde047, #f59e0b); color: #78350f; }
.rank-bar-2 { height: 54px; background: linear-gradient(180deg, #e2e8f0, #94a3b8); color: #1e293b; }
.rank-bar-3 { height: 36px; background: linear-gradient(180deg, #fdba74, #c2410c); color: #431407; }

.rank-list { display: flex; flex-direction: column; gap: 8px; }
.rank-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 10px 16px;
  box-shadow: var(--shadow-sm);
}
.rank-row-pos { width: 22px; text-align: center; font-weight: 800; color: var(--muted); font-size: 13px; }
.rank-row-name { flex: 1; font-weight: 600; font-size: 13.5px; }
.rank-row-stats { display: flex; align-items: center; gap: 16px; font-size: 12px; color: var(--muted); }
.rank-row-stats strong { color: var(--text); }
.rank-row-valor { color: var(--green) !important; font-weight: 700; }

/* ---- MISC ---- */
.msg-error {
  background: var(--red-bg);
  border: 1px solid rgba(220,38,38,0.25);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
}

/* ---- CONVERSAS (inbox WhatsApp) ---- */
.conv-wrap {
  display: flex;
  height: calc(100vh - 140px);
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.conv-sidebar { width: 300px; flex-shrink: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface-2); }
.conv-sidebar-header { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.conv-sidebar-header select { flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12.5px; }
.conv-chats-list { flex: 1; overflow-y: auto; }
.conv-chat-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .12s; }
.conv-chat-row:hover { background: var(--accent-bg); }
.conv-chat-row.active { background: var(--accent-bg); border-left: 3px solid var(--accent); }
.conv-chat-avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; object-fit: cover; }
.conv-chat-info { min-width: 0; flex: 1; }
.conv-chat-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-chat-preview { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-chat-time { font-size: 10px; color: var(--faint); flex-shrink: 0; }

.conv-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.conv-thread-header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 13.5px; }
.conv-messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.conv-bubble { max-width: 62%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; box-shadow: var(--shadow-sm); }
.conv-bubble-in { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 3px; }
.conv-bubble-out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.conv-bubble-time { display: block; font-size: 9.5px; margin-top: 3px; opacity: .65; text-align: right; }
.conv-audio-play { border: none; border-radius: 14px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; background: rgba(0,0,0,.08); color: inherit; }
.conv-bubble-out .conv-audio-play { background: rgba(255,255,255,.22); }
.conv-audio-play:disabled { opacity: .6; cursor: default; }
.conv-composer { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.conv-composer input { flex: 1; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; }
.conv-composer button { width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 15px; }
