/* Incrementos UI. Palette tokens (--c-*) are injected from app/theme.py in base.html. */

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--c-text);
  background: var(--c-surface);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
ul { margin: 0; }
.muted { color: var(--c-muted); }
.small { font-size: 0.85rem; }
.lead { color: var(--c-muted); max-width: 64ch; margin-top: 6px; }
.link { font-weight: 600; }
.text-danger { color: var(--c-danger); }
.error-text { margin: 10px 0 14px; }
.narrow { max-width: 560px; }

/* ---- top bar ---- */
.topbar { background: var(--c-primary); color: #fff; box-shadow: 0 6px 20px rgba(0, 30, 80, 0.18); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 24px; height: 64px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: rgba(255, 255, 255, 0.14); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em; }
.brand-org { font-size: 0.7rem; opacity: 0.78; text-transform: uppercase; letter-spacing: 0.08em; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a { color: rgba(255, 255, 255, 0.84); padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, 0.1); text-decoration: none; color: #fff; }
.nav a.is-active { background: rgba(255, 255, 255, 0.16); color: #fff; }
.user-box { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 0.9rem; opacity: 0.92; }

/* ---- layout ---- */
.container { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 28px 24px 48px; }
.footer { text-align: center; color: var(--c-muted); font-size: 0.8rem; padding: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 24px; }
.page-head h1 .chip { vertical-align: middle; margin-left: 8px; }
.page-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.section { margin-top: 32px; }
.section-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 14px; }
.section-head .muted { font-size: 0.9rem; }
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-top: 16px; }
.stack { display: grid; gap: 16px; }

/* ---- cards ---- */
.card { background: var(--c-card); border: 1px solid var(--c-border); border-radius: 14px; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); }
.card-body { padding: 22px; }
.card-body h2 + .bars, .card-body h2 + .form-grid { margin-top: 14px; }
.table-card { overflow: hidden; }
.form-intro { margin: 6px 0 16px; }

/* ---- file slots ---- */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.slot-card {
  background: var(--c-card); border: 1px solid var(--c-border); border-radius: 14px; padding: 18px 18px 16px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: box-shadow 0.15s, transform 0.15s;
}
.slot-card:hover { box-shadow: 0 8px 22px rgba(0, 30, 80, 0.1); transform: translateY(-1px); }
.slot-card.is-empty { border-style: dashed; background: rgba(255, 255, 255, 0.6); }
.slot-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.slot-hint { color: var(--c-muted); font-size: 0.85rem; min-height: 2.6em; }
.slot-file { background: var(--c-surface); border-radius: 10px; padding: 10px 12px; }
.slot-file-empty { color: var(--c-muted); font-size: 0.85rem; border: 1px dashed var(--c-border); background: transparent; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--c-muted); font-size: 0.8rem; margin-top: 2px; }
.slot-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; }
.upload-form label { position: relative; cursor: pointer; overflow: hidden; }
.upload-form input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer;
  background: var(--c-primary-light); color: var(--c-primary); transition: background 0.15s, box-shadow 0.15s;
  line-height: 1.2; white-space: nowrap;
}
.btn:hover { background: #d3dff0; text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-ghost { background: transparent; border-color: var(--c-border); color: var(--c-text); }
.btn-ghost:hover { background: var(--c-surface); }
.btn-on-dark { color: #fff; border-color: rgba(255, 255, 255, 0.32); }
.btn-on-dark:hover { background: rgba(255, 255, 255, 0.12); }
.btn-danger { background: transparent; border-color: var(--c-danger); color: var(--c-danger); }
.btn-danger:hover { background: #fbeae9; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 1rem; border-radius: 12px; box-shadow: 0 6px 16px rgba(0, 30, 80, 0.18); }
.btn-block { width: 100%; }

/* ---- chips & hints ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem;
  font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; white-space: nowrap; vertical-align: middle;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-ok { background: #e3f3e8; color: var(--c-success); }
.chip-err { background: #fbeae9; color: var(--c-danger); }
.chip-warn { background: #fdf1e1; color: var(--c-warning); }
.chip-info { background: var(--c-primary-light); color: var(--c-primary); }
.chip-muted { background: #eef1f5; color: var(--c-muted); }
.hint-ok { color: var(--c-success); font-size: 0.85rem; font-weight: 600; }
.hint-danger { color: var(--c-danger); font-size: 0.85rem; font-weight: 600; }

/* ---- tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th {
  text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-muted);
  padding: 12px 16px; background: var(--c-surface); border-bottom: 1px solid var(--c-border); font-weight: 600;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form, .table .actions details { display: inline-block; margin-left: 6px; }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; font-weight: 600; }
.field input, .field select, .inline-form input, .inline-form select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 10px; background: #fff; color: var(--c-text);
}
.field input:focus, .field select:focus, .inline-form input:focus, .inline-form select:focus {
  outline: 2px solid var(--c-accent); outline-offset: 1px; border-color: var(--c-accent);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 4px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { padding: 6px 10px; border-radius: 8px; font-size: 0.88rem; }
.inline-form input { width: 180px; }
.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details[open] summary { margin-bottom: 6px; }

/* ---- flash messages ---- */
.flashes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px;
  border-radius: 12px; border: 1px solid; font-size: 0.92rem;
}
.flash-ok { background: #e3f3e8; border-color: #bfe3cb; color: #145c38; }
.flash-error { background: #fbeae9; border-color: #f3c4c0; color: #8a1c16; }
.flash-warn { background: #fdf1e1; border-color: #f5d9ae; color: #7c3e07; margin-bottom: 20px; }
.flash a { color: inherit; font-weight: 600; text-decoration: underline; }
.flash button { border: 0; background: transparent; font-size: 1.25rem; line-height: 1; cursor: pointer; color: inherit; opacity: 0.7; }
.notice { padding: 14px 16px; border-radius: 12px; background: var(--c-primary-light); color: var(--c-primary); font-size: 0.92rem; margin-bottom: 18px; }

/* ---- progress ---- */
.progress-note { margin: 6px 0 16px; }
.progress { height: 12px; background: var(--c-primary-light); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 2%; background: linear-gradient(90deg, var(--c-primary), var(--c-accent)); border-radius: 999px; transition: width 0.5s ease; }
.progress-text { margin-top: 10px; color: var(--c-muted); }

/* ---- KPI tiles & bars ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 18px 0 0; }
.kpi { background: var(--c-card); border: 1px solid var(--c-border); border-radius: 14px; padding: 16px 18px; }
.kpi-label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-muted); font-weight: 600; }
.kpi-value { font-size: 1.55rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi-sub { font-size: 0.8rem; color: var(--c-muted); margin-top: 2px; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 170px) 1fr minmax(120px, auto); align-items: center; gap: 12px; font-size: 0.9rem; }
.bar-track { height: 10px; background: var(--c-surface); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--c-primary); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--c-muted); }
.bars-note { margin-top: 12px; }

/* ---- run hero ---- */
.hero {
  display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 24px 28px;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dark) 100%); color: #fff; border-radius: 16px;
}
.hero h2 { color: #fff; font-size: 1.35rem; }
.hero .muted { color: rgba(255, 255, 255, 0.78); margin-top: 4px; }
.hero .btn-primary { background: #fff; color: var(--c-primary); }
.hero .btn-primary:hover { background: #eef3fa; }

/* ---- login ---- */
.login-wrap { flex: 1; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 420px at 50% -10%, var(--c-primary-light), transparent 65%); }
.login-card { width: 100%; max-width: 410px; background: #fff; border: 1px solid var(--c-border); border-radius: 18px; padding: 32px; box-shadow: 0 20px 50px rgba(0, 30, 80, 0.12); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-mark { background: var(--c-primary); }
.login-brand .brand-name { color: var(--c-primary); }
.login-brand .brand-org { color: var(--c-muted); }
.login-title { font-size: 1.4rem; }
.login-sub { margin: 6px 0 18px; }

/* ---- warnings, overlay ---- */
.warn-list { padding-left: 20px; color: #7c3e07; }
.warn-list li { margin: 4px 0; }
.error-card h1 { font-size: 1.4rem; }
.busy { position: fixed; inset: 0; background: rgba(10, 20, 40, 0.45); display: grid; place-items: center; z-index: 50; }
.busy[hidden] { display: none; }
.busy-card { background: #fff; border-radius: 14px; padding: 22px 28px; display: flex; align-items: center; gap: 14px; font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--c-primary-light); border-top-color: var(--c-primary); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
.spinner-sm { width: 14px; height: 14px; border-width: 2px; border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- flash details ---- */
.flash-body { display: grid; gap: 4px; }
.flash-text { font-weight: 600; }
.flash-detail { font-size: 0.88rem; opacity: 0.92; }
.flash-fix { font-size: 0.88rem; }

/* ---- notices ---- */
.chip-error { background: #fbeae9; color: var(--c-danger); }
.chip-warning { background: #fdf1e1; color: var(--c-warning); }
.notice-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.notice { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; padding: 10px 12px; border-radius: 10px; background: var(--c-surface); font-size: 0.9rem; }
.notice-error { background: #fdf3f2; }
.notice-warning { background: #fdf6ea; }
.notice-body { display: grid; gap: 4px; }
.notice-fix { color: var(--c-muted); font-size: 0.85rem; }
.slot-notices summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--c-warning); }
.slot-notices[open] summary { margin-bottom: 8px; }
.slot-notices .notice { padding: 8px 10px; font-size: 0.82rem; }
.slot-links { display: inline-flex; gap: 12px; }
.fix-box { padding: 12px 14px; border-radius: 10px; background: var(--c-primary-light); color: var(--c-primary); font-size: 0.92rem; margin: 10px 0; }
.fail-card .fail-title { font-size: 1.05rem; margin: 10px 0 6px; }

/* ---- file view ---- */
.kpi-value-sm { font-size: 1.15rem; }
.dist-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-top: 16px; }
.dist-grid .bars { margin-top: 14px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.column-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.column-list li { padding: 6px 10px; border-radius: 8px; background: var(--c-surface); font-size: 0.88rem; font-family: ui-monospace, Consolas, monospace; }
.column-list li.is-required { background: var(--c-primary-light); }
.search-form { margin-left: auto; }
.search-form input { width: 260px; }
.preview-note { margin-bottom: 10px; }
.preview-wrap { overflow-x: auto; }
.table-compact { font-size: 0.82rem; white-space: nowrap; }
.table-compact th, .table-compact td { padding: 7px 10px; }
.table-compact th.is-key, .table-compact td.is-key { background: var(--c-primary-light); font-weight: 600; }

/* ---- responsive ---- */
@media (max-width: 880px) {
  .two-col { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .page-actions { align-items: flex-start; }
  .topbar-inner { gap: 12px; height: auto; flex-wrap: wrap; padding: 10px 16px; }
  .nav { order: 3; width: 100%; margin-left: 0; }
  .hero { flex-direction: column; align-items: flex-start; }
  .bar-row { grid-template-columns: 90px 1fr auto; }
}
