/* TermCalc — folha de estilo única, sem build step. */

:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #14202e;
  --ink-soft: #5b6b7c;
  --line: #dde3ea;
  --brand: #0f5ea8;
  --brand-dark: #0b4780;
  --accent: #e8890c;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

/* ---------------------------------------------------------------- estrutura */

.topbar {
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .3px;
  color: #fff;
}
.topbar .brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 18px; margin-left: auto; align-items: center; }
.topbar nav a, .topbar nav button {
  color: #cfe0f0;
  font-size: 14px;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
.topbar nav a:hover, .topbar nav button:hover { color: #fff; text-decoration: none; }
.topbar .who { color: #8fb4d6; font-size: 13px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.wrap-wide { max-width: 100%; margin: 0; padding: 0; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
h3 { font-size: 15px; margin: 18px 0 8px; }
.sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row.tight > * { flex: 0 0 auto; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

/* ------------------------------------------------------------------ controles */

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=file], select, textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--ink-soft); margin-top: 3px; font-weight: 400; text-transform: none; letter-spacing: 0; }

.btn {
  display: inline-block;
  padding: 8px 15px;
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  border-radius: 4px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.ghost:hover { background: #eef4fa; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: #c9760a; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* -------------------------------------------------------------------- tabelas */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 7px 9px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); background: #f8fafc; font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 13px; }
tbody tr:hover { background: #f8fafc; }
tfoot td { font-weight: 700; background: #f1f5f9; border-top: 2px solid var(--line); }
.table-scroll { overflow-x: auto; }

/* -------------------------------------------------------------------- avisos */

.alert { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.alert.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.badge { display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 700; background: #e2e8f0; color: #475569; text-transform: uppercase; letter-spacing: .4px; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); }

/* ------------------------------------------------------------- números-chave */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); font-weight: 700; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .u { font-size: 12px; color: var(--ink-soft); font-weight: 500; }

/* -------------------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #0b4780, #08325c); }
.login-box { background: #fff; padding: 32px; border-radius: 8px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-box .brand { font-size: 24px; font-weight: 700; margin-bottom: 4px; color: var(--brand-dark); }
.login-box .brand span { color: var(--accent); }
.login-box .tag { color: var(--ink-soft); font-size: 13px; margin-bottom: 22px; }

/* -------------------------------------------------------------------- editor */

.editor { display: grid; grid-template-columns: 250px 1fr 330px; height: calc(100vh - 52px); overflow: hidden; }
.editor .tools, .editor .inspector { background: var(--panel); overflow-y: auto; }
.editor .tools { border-right: 1px solid var(--line); }
.editor .inspector { border-left: 1px solid var(--line); }
.editor .stage { position: relative; background: #5c6a78; overflow: hidden; }
#pdf-scroll { position: absolute; inset: 0; overflow: auto; }
#pdf-holder { position: relative; margin: 20px auto; width: max-content; box-shadow: 0 4px 24px rgba(0,0,0,.35); background: #fff; }
#pdf-canvas { display: block; }
#markup-layer { position: absolute; top: 0; left: 0; }

.panel-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-sec h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); }

.toolbtn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; margin-bottom: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
  font: inherit; font-size: 13px; text-align: left; cursor: pointer; color: var(--ink);
}
.toolbtn:hover { background: #f1f5f9; }
.toolbtn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.toolbtn .key { margin-left: auto; font-family: var(--mono); font-size: 11px; opacity: .6; }
.toolbtn.active .key { opacity: .9; }

.space-item { padding: 7px 10px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 4px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.space-item:hover { background: #f1f5f9; }
.space-item.active { border-color: var(--brand); background: #eef4fa; }
.space-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.space-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-item .ar { font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }

.zoombar { position: absolute; bottom: 14px; left: 14px; display: flex; gap: 4px; background: rgba(255,255,255,.95); padding: 5px; border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,.25); z-index: 20; align-items: center; }
.zoombar button { border: 1px solid var(--line); background: #fff; border-radius: 3px; width: 28px; height: 26px; cursor: pointer; font: inherit; font-size: 14px; }
.zoombar button:hover { background: #f1f5f9; }
.zoombar .lvl { font-family: var(--mono); font-size: 12px; padding: 0 6px; min-width: 46px; text-align: center; }

.statusbar { position: absolute; bottom: 14px; right: 14px; background: rgba(20,32,46,.9); color: #fff; padding: 6px 12px; border-radius: 5px; font-size: 12px; font-family: var(--mono); z-index: 20; max-width: 60%; }
.statusbar.warn { background: rgba(180,83,9,.95); }

.mini { font-size: 12px; }
.mini th, .mini td { padding: 4px 6px; }
.mini input, .mini select { padding: 3px 5px; font-size: 12px; }

.compass { width: 90px; height: 90px; margin: 0 auto; display: block; }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0; max-width: 440px; width: 92%; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,20,30,.55); }
dialog .dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
dialog .dlg-body { padding: 18px; }
/* row-reverse: a acao primaria vem PRIMEIRO no DOM (para o Enter aciona-la
   em vez de Cancelar) mas continua sendo exibida a direita. */
dialog .dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; flex-direction: row-reverse; gap: 8px; justify-content: flex-start; background: #f8fafc; }

/* ------------------------------------------------------------------ relatório */

.report { background: #fff; }
.report-head { border-bottom: 3px solid var(--brand-dark); padding-bottom: 14px; margin-bottom: 20px; }
.report-head .t { font-size: 24px; font-weight: 700; }
.report-head .m { color: var(--ink-soft); font-size: 14px; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 24px; font-size: 14px; }
.meta-grid div { padding: 3px 0; border-bottom: 1px dotted var(--line); }
.meta-grid b { color: var(--ink-soft); font-weight: 600; }
.space-block { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.space-block > header { background: #eef4fa; padding: 9px 14px; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.space-block > header .r { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.space-block .inner { padding: 12px 14px; }
.profile-chart { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin: 10px 0 4px; }
.profile-chart .bar { flex: 1; background: #bcd4ea; border-radius: 2px 2px 0 0; position: relative; min-height: 1px; }
.profile-chart .bar.peak { background: var(--accent); }
.profile-labels { display: flex; gap: 2px; font-size: 9px; color: var(--ink-soft); font-family: var(--mono); }
.profile-labels span { flex: 1; text-align: center; }

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .wrap { max-width: none; padding: 0; }
  .card, .space-block { border: 1px solid #999; break-inside: avoid; }
  .space-block { page-break-inside: avoid; }
  h2 { page-break-after: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* ------------------------------------------------------------------ uploader */

.up-drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 26px 18px;
  text-align: center;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.up-drop:hover, .up-drop.over { border-color: var(--brand); background: #eef4fa; color: var(--brand); }

.up-item { border: 1px solid var(--line); border-radius: 4px; padding: 9px 11px; margin-top: 8px; background: #fbfcfd; }
.up-head { display: flex; align-items: center; gap: 9px; font-size: 13px; margin-bottom: 6px; }
.up-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.up-size { color: var(--ink-soft); font-family: var(--mono); font-size: 12px; }
.up-pct { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }
.up-actions { display: flex; gap: 5px; }
.up-bar { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
.up-fill { height: 100%; background: var(--brand); transition: width .18s; }
.up-fill.ok { background: var(--ok); }
.up-fill.err { background: var(--danger); }
.up-msg { font-size: 12px; color: var(--ink-soft); margin-top: 5px; }
.up-msg.err { color: var(--danger); }
