/* Cofre WebRenave (secured by KeyDock) */

@font-face {
  font-family: 'Inter Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('/fonts/inter-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('/fonts/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* WebRenave */
  --petrol: #0B282F;
  --petrol-hover: #163d46;
  --green: #4BAE75;
  --green-text: #217447;
  --green-soft: #E6F4EC;
  /* KeyDock: só em momentos de segurança */
  --kd-blue: #1E63E9;
  --kd-blue-soft: #8DB2FF;
  --kd-navy: #0B1F3A;
  --kd-navy-2: #14305A;
  /* Neutros */
  --bg: #F3F6F5;
  --surface: #FFFFFF;
  --line: #DCE4E2;
  --line-soft: #EAF0EE;
  --text: #0B282F;
  --muted: #56696C;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --warn: #8A5A00;
  --warn-soft: #FFF4D6;

  --radius: 10px;
  --radius-lg: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --focus: 0 0 0 3px rgba(30, 99, 233, 0.35);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter Variable', Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 650; }
p { margin: 0 0 12px; }
a { color: var(--green-text); }
code, .mono { font-family: var(--mono); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--petrol); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--petrol-hover); }
.btn-secondary { background: var(--surface); color: var(--petrol); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { border-color: var(--petrol); }
.btn-ghost { background: transparent; color: var(--petrol); }
.btn-ghost:hover:not(:disabled) { background: var(--line-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #8f1c13; }
.btn-block { width: 100%; }
.btn-lg { min-height: 48px; font-size: 15px; }

.btn-icon {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--muted); cursor: pointer;
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--line-soft); color: var(--petrol); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }

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

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .label { font-weight: 600; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--muted); }
.field-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; min-height: 42px; padding: 9px 12px;
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
textarea.mono { font-family: var(--mono); font-size: 14px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--kd-blue); box-shadow: var(--focus); }

.check-row { display: flex; gap: 10px; align-items: center; margin: 0 0 16px; cursor: pointer; }
.check-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--petrol); flex: none; }

.error-text { color: var(--danger); font-size: 14px; margin: 0 0 12px; }

/* Escolha em botões segmentados (leituras, validade) */
.choices { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
.choices legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.choices label { position: relative; }
.choices input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choices span {
  display: inline-block; min-width: 44px; padding: 7px 12px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  font-size: 14px; font-weight: 550; cursor: pointer;
}
.choices input:checked + span { background: var(--petrol); border-color: var(--petrol); color: #fff; }
.choices input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- Páginas públicas e login ---------- */

body.public {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 16px 24px; position: relative; overflow-x: hidden;
}
/* Símbolo da WebRenave em marca d'água, saindo pelo canto inferior esquerdo */
body.public::before {
  content: ''; position: fixed; z-index: 0; pointer-events: none;
  left: -8vmin; bottom: -14vmin; width: 52vmin; height: 60vmin;
  background: url('/img/webrenave-mark.svg') no-repeat center / contain;
  opacity: .14;
}
.panel {
  position: relative; z-index: 1;
  width: 100%; max-width: 460px;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px rgba(11, 40, 47, .06), 0 12px 32px rgba(11, 40, 47, .08);
  padding: 32px;
}
.panel.wide { max-width: 560px; }
.panel .brand-logo { display: block; height: 40px; width: auto; margin-bottom: 28px; }
.panel h1 { font-size: 24px; }
.panel > p { color: var(--muted); }
.panel .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.panel .dropzone { margin-top: 4px; }
.panel .file-list + p, .panel .dropzone + p { margin-top: 10px; }
.panel .small.muted:last-child { margin: 12px 0 0; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin: 16px 0;
  border-radius: var(--radius); background: var(--line-soft); font-size: 14px;
}
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.notice.warn { background: var(--warn-soft); color: #5c3c00; }
.notice.secure { background: #EAF1FE; color: var(--kd-navy); }
.notice.secure svg { color: var(--kd-blue); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }

.state-icon {
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px;
  background: var(--green-soft); color: var(--green-text); margin-bottom: 16px;
}
.state-icon svg { width: 26px; height: 26px; }
.state-icon.off { background: var(--line-soft); color: var(--muted); }

.secret-box {
  margin: 16px 0 12px; padding: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--mono); font-size: 14px;
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}

/* Selo KeyDock, conforme o manual da marca: símbolo + "SECURED BY" sobre "KEYDOCK" */
.seal {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 9px; justify-content: center;
  margin-top: 24px; text-decoration: none;
}
.seal img { width: 30px; height: 30px; flex: none; }
.seal-text { display: grid; line-height: 1; }
.seal-by { font-size: 8.5px; font-weight: 600; letter-spacing: .32em; text-transform: uppercase; color: #3D4B5C; margin-bottom: 3px; }
.seal-word { font-size: 17px; letter-spacing: -0.01em; color: var(--kd-blue); font-weight: 450; }
.seal-word b { color: var(--kd-navy); font-weight: 800; }

/* Lista de arquivos (download e upload) */
.file-list { list-style: none; margin: 16px 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); }
.file-list li {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-top: 1px solid var(--line-soft);
}
.file-list li:first-child { border-top: 0; }
.file-list .file-ico { color: var(--muted); display: grid; place-items: center; }
.file-list .file-ico svg { width: 20px; height: 20px; }
.file-list .file-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-sub { font-size: 13px; color: var(--muted); }
.file-list .file-main { min-width: 0; }
.file-list .ok { color: var(--green-text); }
.file-list .fail { color: var(--danger); }

/* Dropzone e progresso */
.dropzone {
  display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 28px 16px; border: 1.5px dashed #b9c8c4; border-radius: var(--radius);
  background: #FAFCFB; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.dropzone svg { width: 28px; height: 28px; color: var(--green-text); }
.dropzone strong { color: var(--text); }
.dropzone.drag, .dropzone:hover { border-color: var(--green); background: var(--green-soft); }
.dropzone input { display: none; }

.progress { height: 6px; border-radius: 99px; background: var(--line-soft); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .15s linear; }
.progress.fail > div { background: var(--danger); }

/* ---------- Painel administrativo ---------- */

body.admin { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 14px 16px;
}
.sidebar .brand-logo { height: 36px; width: auto; margin: 0 8px 22px; align-self: flex-start; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 550; text-decoration: none; white-space: nowrap;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--bg); color: var(--petrol); }
.nav a[aria-current=page] { background: var(--green-soft); color: var(--petrol); }
.nav a[aria-current=page] svg { color: var(--green-text); }

/* minmax(0, 1fr): a coluna nunca passa da largura da sidebar, mesmo com textos longos. */
.sidebar-bottom { margin-top: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.vault-head > div { min-width: 0; }
/* Selo KeyDock no rodapé da sidebar, separado por uma linha */
.seal-sidebar { margin: 14px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
.seal-sidebar img { width: 26px; height: 26px; }
.seal-sidebar .seal-word { font-size: 15px; }

/* Bloco do cofre (KeyDock) */
.vault-block {
  background: var(--kd-navy); color: #fff; border-radius: 12px; padding: 14px;
  display: grid; gap: 10px;
}
.vault-head { display: flex; align-items: center; gap: 10px; }
.vault-head img { width: 28px; height: 28px; flex: none; }
.vault-title { font-weight: 650; font-size: 14px; }
.vault-state { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: #c4d3ea; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #F5B83D; flex: none; }
.dot.on { background: var(--green); }
.dot.none { background: #7a8aa3; }
.vault-block .btn { min-height: 34px; font-size: 13px; background: var(--kd-blue); color: #fff; }
.vault-block .btn:hover { background: #1953c6; }

.user-row { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--petrol); color: #fff; font-weight: 650; font-size: 13px;
}
.user-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { padding: 32px 40px 48px; min-width: 0; }
.main > div { max-width: 1200px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }

/* Faixa de números */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  margin-bottom: 28px;
}
.stat { padding: 20px 24px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat-value { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* Atalhos */
.shortcuts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 32px; }
.shortcut {
  display: flex; gap: 14px; align-items: flex-start; text-align: left;
  padding: 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font: inherit; color: inherit; cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.shortcut:hover { border-color: var(--green); background: #FAFDFB; }
.shortcut .sc-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--green-soft); color: var(--green-text); flex: none; }
.shortcut .sc-ico svg { width: 21px; height: 21px; }
.shortcut strong { display: block; font-size: 15px; margin-bottom: 2px; }
.shortcut span { color: var(--muted); font-size: 13.5px; }

/* Tabelas */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
thead th { border-top: 0; font-size: 13px; font-weight: 600; color: var(--muted); background: #FAFCFB; white-space: nowrap; }
td .label-cell { font-weight: 600; }
td .sub { font-size: 13px; color: var(--muted); }
td.nowrap, .nowrap { white-space: nowrap; }
td .actions, .file-list .actions { display: flex; gap: 4px; align-items: center; }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
tr.detail > td { background: #FAFCFB; padding: 16px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: var(--line-soft); color: var(--muted);
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--green-soft); color: var(--green-text); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }

.empty {
  display: grid; justify-items: center; gap: 8px; text-align: center;
  padding: 48px 24px; background: var(--surface); border: 1px dashed #c9d6d2; border-radius: 12px;
}
.empty svg { width: 32px; height: 32px; color: var(--green-text); }
.empty p { color: var(--muted); max-width: 380px; margin: 0 0 8px; }

/* Diálogos */
dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--text);
  box-shadow: 0 24px 64px rgba(11, 31, 58, .28);
}
dialog::backdrop { background: rgba(11, 31, 58, .45); }
.dialog-body { padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialog-head h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
dialog.small { width: min(420px, calc(100vw - 32px)); }

/* Resultado: o link com a chave em destaque */
.link-result {
  background: var(--kd-navy); color: #dfe8f7; border-radius: 12px;
  padding: 16px; font-family: var(--mono); font-size: 13.5px; line-height: 1.55;
  word-break: break-all; margin: 8px 0 10px;
}
.link-result .link-key { color: var(--kd-blue-soft); background: rgba(30, 99, 233, .22); border-radius: 4px; padding: 0 2px; }
.link-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.link-legend span { display: flex; align-items: center; gap: 6px; }
.link-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--kd-navy); flex: none; }
.link-legend i.key { background: var(--kd-blue); }

/* Chave do cofre */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; max-width: 640px; }
.fingerprint { font-family: var(--mono); font-size: 15px; letter-spacing: .04em; color: var(--kd-navy); background: #EAF1FE; padding: 6px 10px; border-radius: 8px; display: inline-block; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 16px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }

/* Toasts */
.toasts { position: fixed; z-index: 1000; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 10px; background: var(--petrol); color: #fff;
  box-shadow: 0 8px 24px rgba(11, 40, 47, .25); font-size: 14px;
  animation: toast-in .18s ease-out;
}
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--green); }
.toast.error { background: var(--danger); }
.toast.error svg { color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsivo ---------- */

@media (max-width: 1080px) {
  .main { padding: 28px 24px 40px; }
  .shortcuts { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  body.admin { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    min-width: 0; position: static; height: auto;
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 12px;
    padding: 12px 16px 0; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar .brand-logo { margin: 0; height: 28px; }
  .nav {
    grid-column: 1 / -1; flex-direction: row; min-width: 0; margin: 0 -16px; padding: 0 12px 8px;
    overflow-x: auto; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 8px 10px; }
  .sidebar-bottom { grid-row: 1; grid-column: 2; margin: 0; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
  .vault-block { padding: 6px 8px; display: flex; align-items: center; gap: 8px; border-radius: 10px; }
  .vault-block .vault-title, .vault-head img { display: none; }
  .vault-head { gap: 0; }
  .vault-block .btn { min-height: 28px; padding: 0 10px; }
  .user-row .user-name { display: none; }
  .seal-sidebar { display: none; }
  .user-row { padding: 0; gap: 4px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .main { padding: 20px 16px 32px; }
  .panel { padding: 24px 20px; }
  h1 { font-size: 22px; }
  .stat { padding: 16px; }
  .stat-value { font-size: 28px; }
  th, td { padding: 10px 12px; }
  .hide-sm { display: none; }
  .vault-state span.txt { display: none; }
  .link-legend { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .dialog-body { padding: 20px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
