/* DK Certificados — interface do painel (mobile first) */

:root {
  --navy: #173954;
  --navy-2: #0f2a40;
  --blue: #087da8;
  --blue-soft: #e6f3f8;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --text: #1b2b3a;
  --muted: #5d6e7e;
  --line: #dde5ec;
  --line-soft: #edf1f5;
  --green: #12805c;
  --green-soft: #e3f4ec;
  --red: #c0392b;
  --red-soft: #fbe9e7;
  --amber: #a86400;
  --amber-soft: #fff3dc;
  --gray-soft: #eef1f4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 42, 64, .06), 0 2px 8px rgba(16, 42, 64, .05);
  --sidebar: 248px;
  --bottom-nav: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--navy); line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
img { max-width: 100%; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .02em; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }

/* ---------------------------------------------------------------- Layout */

.app { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem;
  height: 56px; padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--navy); color: #fff;
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 600; }
.topbar .brand img { height: 30px; }
.topbar .spacer { flex: 1; }
.topbar .user-chip { display: none; color: #cfe0ec; font-size: .9rem; }
.topbar-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; color: #fff; background: transparent; border: 0; cursor: pointer; }
.topbar-btn:hover { background: rgba(255, 255, 255, .1); text-decoration: none; }

.sidebar { display: none; }

.main {
  padding: 16px 16px calc(var(--bottom-nav) + 24px + var(--safe-bottom));
  max-width: 1180px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--bottom-nav) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(16, 42, 64, .06);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 500;
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a.active { color: var(--blue); }
.bottom-nav .fab {
  width: 48px; height: 48px; border-radius: 50%; margin-top: -18px;
  display: flex; align-items: center; justify-content: center;
  background: var(--blue); color: #fff; box-shadow: 0 4px 12px rgba(8, 125, 168, .4);
}

@media (min-width: 960px) {
  .topbar { display: none; }
  .bottom-nav { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
    background: var(--navy); color: #c9d8e4; padding: 20px 14px;
    overflow-y: auto;
  }
  .sidebar .brand { display: block; padding: 4px 10px 20px; }
  .sidebar .brand img { height: 46px; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar .nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7f9bb2; margin: 16px 10px 6px; }
  .sidebar a.nav-item {
    display: flex; align-items: center; gap: .7rem; padding: 9px 10px; border-radius: 8px;
    color: #d5e2ec; font-size: .94rem;
  }
  .sidebar a.nav-item:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
  .sidebar a.nav-item.active { background: var(--blue); color: #fff; }
  .sidebar .sidebar-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255, 255, 255, .1); font-size: .85rem; }
  .sidebar .sidebar-foot strong { color: #fff; display: block; }
  .sidebar .sidebar-foot button { margin-top: 8px; }
  .app { padding-left: var(--sidebar); }
  .main { padding: 28px 32px 48px; }
}

/* ------------------------------------------------------------ Cabeçalho */

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }
.page-head .sub { flex-basis: 100%; margin: -.25rem 0 0; color: var(--muted); }
.back-link { display: inline-flex; align-items: center; gap: .25rem; color: var(--muted); font-size: .9rem; margin-bottom: .5rem; }

/* ---------------------------------------------------------------- Cards */

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card > h2:first-child, .card-head { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 14px 16px 0; }
@media (min-width: 720px) { .card { padding: 20px 22px; } .card-flush { padding: 0; } .card-flush .card-head { padding: 18px 22px 4px; } }

.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: inherit; }
.stat:hover { text-decoration: none; border-color: var(--blue); }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat .value { font-size: 1.7rem; font-weight: 700; color: var(--navy); line-height: 1.2; }
.stat.warn .value { color: var(--amber); }

/* ----------------------------------------------------------------- Botões */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--navy);
  font: inherit; font-weight: 600; font-size: .93rem; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; border-color: #b9c8d4; background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #066c92; border-color: #066c92; }
.btn-navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #0e6b4c; border-color: #0e6b4c; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: #f0c2bc; }
.btn-danger-solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-solid:hover { background: #a93226; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--gray-soft); border-color: transparent; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .86rem; border-radius: 8px; }
.btn-lg { min-height: 52px; padding: 0 22px; font-size: 1.02rem; }
.btn-block { width: 100%; }
.btn-icon { width: 38px; min-height: 38px; padding: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn-row.stretch > .btn { flex: 1 1 180px; }
form.inline { display: inline; }

/* ------------------------------------------------------------- Formulários */

.form-grid { display: grid; gap: 14px; }
@media (min-width: 720px) {
  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .form-grid .span-2 { grid-column: span 2; }
  .form-grid .span-all { grid-column: 1 / -1; }
}
.field label, .label { display: block; font-weight: 600; font-size: .88rem; color: var(--navy); margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid #c9d5df; border-radius: 10px; background: #fff; color: var(--text);
  font: inherit; font-size: 16px; /* evita zoom no iPhone */
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(8, 125, 168, .2); border-color: var(--blue); }
input[type=file] { width: 100%; font: inherit; padding: 10px; border: 1px dashed #b6c6d3; border-radius: 10px; background: #fafcfd; }
.check { display: flex; align-items: flex-start; gap: .55rem; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--blue); }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 18px; }
.form-actions .btn-primary { min-width: 160px; }
@media (max-width: 719px) { .form-actions > .btn { flex: 1 1 100%; } }
fieldset { border: 0; padding: 0; margin: 0; }
.input-group { display: flex; gap: .5rem; }
.input-group > :first-child { flex: 1; }

.search-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 14px; }
.search-bar input[type=search] { flex: 1 1 220px; }
.search-bar select { flex: 0 1 200px; width: auto; }

/* ---------------------------------------------------------------- Avisos */

.flash-stack { display: grid; gap: 8px; margin-bottom: 14px; }
.alert { display: flex; gap: .6rem; align-items: flex-start; padding: 12px 14px; border-radius: 10px; border: 1px solid; font-size: .93rem; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--green-soft); border-color: #b9e2cf; color: #0b5a40; }
.alert-error { background: var(--red-soft); border-color: #f2c4bd; color: #8e2a1f; }
.alert-warning { background: var(--amber-soft); border-color: #f1d49a; color: #7a4a00; }
.alert-info { background: var(--blue-soft); border-color: #bfe0ec; color: #0b5877; }
.alert ul { margin: .25rem 0 0; padding-left: 1.1rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.badge-valido { background: var(--green-soft); color: var(--green); }
.badge-cancelado { background: var(--red-soft); color: var(--red); }
.badge-substituido { background: var(--gray-soft); color: #4d5d6c; }
.badge-vencido { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-gray { background: var(--gray-soft); color: var(--muted); }

/* ---------------------------------------------------------------- Tabelas */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f9fbfc; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafcfd; }
.table .actions { text-align: right; white-space: nowrap; }
.table .title { font-weight: 600; color: var(--navy); }

/* No celular, cada linha vira um cartão */
@media (max-width: 719px) {
  table.table.responsive thead { display: none; }
  table.table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
  .table.responsive tr:last-child { border-bottom: 0; }
  .table.responsive td { border: 0; padding: 2px 0; }
  .table.responsive td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .82rem; }
  .table.responsive td.title::before, .table.responsive td.no-label::before { content: none; }
  .table.responsive .actions { text-align: left; padding-top: 8px; white-space: normal; }
  .table.responsive tbody tr:hover td { background: transparent; }
}

/* Listas tocáveis (celular e desktop) */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: .75rem; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover { background: #f8fbfd; text-decoration: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; }
.list-item .meta { color: var(--muted); font-size: .84rem; }
.list-item .chev { color: #a5b4c1; }
@media (min-width: 720px) { .list-item { padding: 12px 22px; } }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty .icon { width: 40px; height: 40px; color: #a9bccb; margin-bottom: 8px; }
.empty h3 { color: var(--navy); }

/* ------------------------------------------------------------- Turma */

.steps { display: grid; gap: 10px; counter-reset: step; margin-bottom: 16px; }
@media (min-width: 900px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.step { display: flex; gap: .75rem; align-items: center; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.step .num { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem; background: var(--gray-soft); color: var(--muted); flex: none; }
.step.done .num { background: var(--green); color: #fff; }
.step.current { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(8, 125, 168, .12); }
.step.current .num { background: var(--blue); color: #fff; }
.step .t { font-weight: 600; color: var(--navy); font-size: .93rem; }
.step .d { color: var(--muted); font-size: .82rem; }

.info-list { display: grid; grid-template-columns: minmax(96px, max-content) 1fr; gap: 6px 14px; margin: 0; font-size: .93rem; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; color: var(--text); font-weight: 500; overflow-wrap: anywhere; }

.issue-panel { background: linear-gradient(135deg, var(--navy), #1f5378); color: #fff; border: 0; }
.issue-panel h2 { color: #fff; }
.issue-panel p { color: #d6e5f0; }
.issue-panel .btn { border-color: rgba(255, 255, 255, .3); }
.issue-panel .btn:not(.btn-success):not(.btn-primary) { background: rgba(255, 255, 255, .1); color: #fff; }
.issue-panel .btn:not(.btn-success):not(.btn-primary):hover { background: rgba(255, 255, 255, .18); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 0; padding: 0 16px; overflow-x: auto; }
.tabs a { padding: 10px 12px; color: var(--muted); font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--navy); }
.tabs a.active { color: var(--blue); border-color: var(--blue); }

details.disclosure { border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd; }
details.disclosure > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; color: var(--navy); list-style: none; display: flex; align-items: center; gap: .5rem; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure[open] > summary { border-bottom: 1px solid var(--line); }
details.disclosure > .body { padding: 14px; }

/* ------------------------------------------------------------- Histórico */

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--muted); font-size: .8rem; }
.timeline .what { font-size: .92rem; }
.diff { margin-top: 4px; font-size: .8rem; background: #f6f9fb; border: 1px solid var(--line-soft); border-radius: 8px; padding: 6px 10px; }
.diff div { overflow-wrap: anywhere; }
.diff del { color: var(--red); }
.diff ins { color: var(--green); text-decoration: none; }

/* --------------------------------------------------------- Certificado */

.cert-hero { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.cert-hero .qr { width: 132px; height: 132px; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: #fff; }
.cert-hero .qr img { width: 100%; height: 100%; }
.code-big { font-size: 1.25rem; font-weight: 700; color: var(--navy); letter-spacing: .04em; }

/* ------------------------------------------------------------ Paginação */

.pagination { display: flex; justify-content: center; align-items: center; gap: .5rem; padding: 14px; }

/* ------------------------------------------------------------ Diálogos */

dialog.modal { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog.modal::backdrop { background: rgba(15, 30, 45, .5); }
dialog.modal .modal-body { padding: 20px; }
dialog.modal .modal-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: 14px 20px; background: #f7f9fb; border-top: 1px solid var(--line); }

.install-banner {
  display: none; align-items: center; gap: .75rem;
  background: var(--blue-soft); border: 1px solid #bfe0ec; color: #0b5877;
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: .9rem;
}
.install-banner.show { display: flex; }
.install-banner .grow { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-nav) + 20px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
@media (min-width: 960px) { .toast { bottom: 24px; } }

.loading-overlay { position: fixed; inset: 0; background: rgba(244, 247, 250, .8); display: none; align-items: center; justify-content: center; z-index: 200; flex-direction: column; gap: 12px; color: var(--navy); font-weight: 600; }
.loading-overlay.show { display: flex; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------- Área pública */

body.public { background: linear-gradient(180deg, var(--navy) 0, var(--navy) 260px, var(--bg) 260px); min-height: 100vh; }
.public-main { max-width: 560px; margin: 0 auto; padding: 32px 16px 48px; }
.public-top { text-align: center; margin-bottom: 20px; }
.public-top img { height: 64px; }
.public-card { background: var(--surface); border-radius: 18px; box-shadow: 0 10px 40px rgba(16, 42, 64, .14); padding: 24px 20px; }
@media (min-width: 560px) { .public-card { padding: 30px 32px; } }
.public-logo { height: 56px; margin-bottom: 14px; }
.public-foot { text-align: center; color: var(--muted); font-size: .82rem; margin-top: 18px; }
.public-foot a { color: var(--muted); }

.verdict { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-radius: 12px; margin-bottom: 18px; }
.verdict .icon { width: 36px; height: 36px; }
.verdict strong { display: block; font-size: 1.1rem; }
.verdict span { font-size: .9rem; }
.verdict.ok { background: var(--green-soft); color: #0b5a40; }
.verdict.bad { background: var(--red-soft); color: #8e2a1f; }
.verdict.warn { background: var(--amber-soft); color: #7a4a00; }
.verdict.neutral { background: var(--gray-soft); color: #3d4d5c; }

.data-rows { margin: 0; }
.data-rows div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.data-rows div:last-child { border-bottom: 0; }
.data-rows dt { color: var(--muted); font-size: .9rem; }
.data-rows dd { margin: 0; font-weight: 600; color: var(--navy); text-align: right; overflow-wrap: anywhere; }

.code-input { text-transform: uppercase; letter-spacing: .08em; font-weight: 600; text-align: center; font-size: 1.15rem !important; }

@media print {
  .sidebar, .topbar, .bottom-nav, .actions, .btn { display: none !important; }
  .app { padding: 0; }
}
