/* ==========================================================================
   Kalcfy — Páginas de calculadora
   ========================================================================== */

.calc-layout {
  display: grid; gap: var(--space-6);
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
  padding-bottom: var(--space-6);
}
.calc-sidebar { position: sticky; top: calc(var(--header-h) + 16px); display: grid; gap: var(--space-4); }

/* Breadcrumb */
.breadcrumb { padding: var(--space-4) 0 var(--space-2); font-size: .85rem; color: var(--muted); }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; }
.breadcrumb li { margin: 0; display: flex; gap: 6px; align-items: center; }
.breadcrumb li + li::before { content: "/"; color: var(--line); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb [aria-current="page"] { color: var(--text); font-weight: 600; }

/* Cabeçalho da ferramenta */
.calc-header { margin-bottom: var(--space-5); }
.calc-header .lead { color: var(--muted); font-size: 1.03rem; max-width: 68ch; margin-bottom: var(--space-3); }
.calc-header-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* Cartão */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: var(--space-5); box-shadow: var(--shadow-sm); margin-bottom: var(--space-5);
}
.card > :last-child { margin-bottom: 0; }
.card-title { font-size: 1.15rem; margin-bottom: var(--space-4); }

/* Formulário */
.field-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field label, .field .field-label { font-weight: 600; font-size: .9rem; }
.field .hint { font-size: .8rem; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 1rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px;
  width: 100%; transition: border-color .18s ease, box-shadow .18s ease;
}
.field textarea { min-height: 180px; resize: vertical; line-height: 1.55; }
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23475569' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 11px;
  padding-right: 36px;
}
[data-theme="dark"] .field select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%239AA7BC' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 16%, transparent);
}
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--danger); }
.field-error { font-size: .82rem; color: var(--danger); font-weight: 600; min-height: 0; }
.field-error:empty { display: none; }

.input-group { display: flex; }
.input-group input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group select { width: auto; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; }

/* Abas de modo */
.mode-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-4); }
.mode-tab {
  font: inherit; font-size: .88rem; font-weight: 600; padding: 9px 14px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
}
.mode-tab:hover { color: var(--brand); border-color: var(--brand); }
.mode-tab[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.radio-row { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.radio-row label { display: inline-flex; align-items: center; gap: 7px; font-size: .93rem; font-weight: 500; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: .93rem; }
.check-row input { width: 18px; height: 18px; }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-5); }
.form-actions .btn-primary { flex: 1 1 200px; }

/* Resultado */
.result-box {
  background: linear-gradient(180deg, var(--success-soft), var(--surface));
  border: 1px solid color-mix(in srgb, var(--success) 35%, var(--line));
  border-radius: var(--radius-lg); padding: var(--space-5); margin-bottom: var(--space-5);
}
.result-box[hidden] { display: none; }
.result-box.is-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}
.result-label { font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.result-main {
  font-size: clamp(1.9rem, 1.4rem + 2.4vw, 2.8rem); font-weight: 800; letter-spacing: -.03em;
  color: var(--success); line-height: 1.1; margin: 4px 0 8px; overflow-wrap: anywhere;
}
.result-box.is-error .result-main { color: var(--danger); font-size: 1.15rem; }
.result-note { color: var(--muted); font-size: .95rem; margin: 0; }
.result-grid {
  display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-top: var(--space-4);
}
.result-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.result-item dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.result-item dd { margin: 4px 0 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; overflow-wrap: anywhere; }
.result-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }

.calc-loading { display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, #fff 40%, transparent); border-top-color: #fff;
  animation: kalcfy-spin .7s linear infinite; }
@keyframes kalcfy-spin { to { transform: rotate(360deg); } }

/* Barra indicadora (IMC, etc.) */
.gauge { margin-top: var(--space-4); }
.gauge-track {
  position: relative; height: 12px; border-radius: 999px; overflow: hidden;
  background: linear-gradient(90deg, #60A5FA 0%, #10B981 32%, #F59E0B 62%, #EF4444 100%);
}
.gauge-pointer {
  position: absolute; top: -5px; width: 4px; height: 22px; border-radius: 2px;
  background: var(--text); box-shadow: 0 0 0 2px var(--surface); transition: left .35s ease;
}
.gauge-scale { display: flex; justify-content: space-between; font-size: .74rem; color: var(--muted); margin-top: 6px; }

/* Tabelas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: var(--space-4); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 420px; }
table.data caption { text-align: left; color: var(--muted); font-size: .85rem; padding-bottom: 8px; }
table.data th, table.data td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
table.data tbody tr:hover { background: var(--surface-2); }

/* Gráficos */
.chart-box { margin-bottom: var(--space-4); }
.chart-box canvas { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-top: var(--space-3); font-size: .85rem; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Avisos */
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--warning-soft); border: 1px solid color-mix(in srgb, var(--warning) 35%, var(--line));
  border-radius: var(--radius); padding: 14px 16px; font-size: .9rem; color: var(--text);
  margin-bottom: var(--space-5);
}
.notice svg { width: 20px; height: 20px; flex: 0 0 20px; color: var(--warning); margin-top: 1px; }
.notice p { margin: 0; }

/* Conteúdo SEO */
.calc-content { max-width: 72ch; }
.calc-content h2 { margin-top: var(--space-6); }
.calc-content h3 { margin-top: var(--space-5); }
.calc-content p, .calc-content li { color: var(--text); }
.formula {
  font-family: var(--font-mono); font-size: .95rem; background: var(--surface-2);
  border-left: 3px solid var(--brand); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 16px; overflow-x: auto; margin-bottom: var(--space-4);
}
.example-box {
  background: var(--brand-soft); border-radius: var(--radius); padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.example-box p:last-child { margin-bottom: 0; }

/* Relacionadas / sidebar */
.side-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-4); box-shadow: var(--shadow-sm);
}
.side-card h2, .side-card h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-card ul { list-style: none; padding: 0; margin: 0; }
.side-card li { margin-bottom: 4px; }
.side-card a { display: block; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); font-size: .92rem; font-weight: 500; }
.side-card a:hover { background: var(--surface-2); color: var(--brand); text-decoration: none; }

.related { margin-top: var(--space-6); }

/* Ferramentas de tempo (cronômetro, pomodoro) */
.timer-display {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 1.5rem + 9vw, 5rem); font-weight: 700; letter-spacing: -.03em;
  text-align: center; line-height: 1.05; margin: var(--space-4) 0;
}
.timer-display small { font-size: .32em; color: var(--muted); }
.timer-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: center; }
.lap-list { list-style: none; padding: 0; margin: var(--space-4) 0 0; max-height: 220px; overflow-y: auto; }
.lap-list li {
  display: flex; justify-content: space-between; padding: 8px 4px;
  border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: .9rem;
}
.is-fullscreen { background: var(--bg); display: grid; place-content: center; }

/* Teclado da calculadora científica */
.calc-screen {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-4); text-align: right; margin-bottom: var(--space-4);
}
.calc-expression {
  font-family: var(--font-mono); font-size: 1rem; color: var(--muted);
  min-height: 24px; overflow-x: auto; white-space: nowrap;
}
.calc-output {
  font-family: var(--font-mono); font-size: 2rem; font-weight: 700; letter-spacing: -.02em;
  overflow-x: auto; white-space: nowrap;
}
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.key {
  font: inherit; font-weight: 600; font-size: 1rem; padding: 15px 4px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.key:hover { border-color: var(--brand); color: var(--brand); }
.key-fn { background: var(--surface-2); font-size: .87rem; }
.key-op { color: var(--brand); }
.key-eq { background: var(--brand); color: #fff; border-color: var(--brand); }
.key-eq:hover { background: var(--brand-dark); color: #fff; }
.key-clear { color: var(--danger); }
.history-list { list-style: none; padding: 0; margin: 0; font-family: var(--font-mono); font-size: .85rem; }
.history-list li { padding: 7px 0; border-bottom: 1px solid var(--line); color: var(--muted); overflow-x: auto; }

/* Linhas dinâmicas (média, metros quadrados) */
.row-list { display: grid; gap: var(--space-3); margin-bottom: var(--space-3); }
.dyn-row { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) auto; align-items: end; }
.row-remove {
  background: var(--danger-soft); border: 1px solid transparent; color: var(--danger);
  border-radius: var(--radius-sm); width: 44px; height: 44px; cursor: pointer; font-size: 1.1rem; line-height: 1;
}
.row-remove:hover { border-color: var(--danger); }

/* Contadores de texto */
.counter-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.counter-item {
  background: var(--surface-2); border-radius: var(--radius); padding: 14px; text-align: center;
}
.counter-item strong { display: block; font-size: 1.5rem; font-weight: 800; color: var(--brand); letter-spacing: -.02em; }
.counter-item span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Página de favoritos */
.empty-state {
  text-align: center; padding: var(--space-7) var(--space-4);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-lg);
}
.empty-state p { color: var(--muted); }

/* Lista de atalhos da barra lateral */
.side-list { list-style: none; padding: 0; margin: 0 0 var(--space-3); }
.side-list li { margin: 0; }
