:root {
    /* Identidade King Nox — bordô do logo (#4F1A13) + dourado da coroa */
    --accent: #4F1A13;
    --accent-dark: #37110b;
    --accent-tint: rgba(79, 26, 19, .08);
    --accent-tint-2: rgba(79, 26, 19, .14);
    --gold: #C9962C;
    --gold-deep: #8f6716;
    --gold-soft: #f5e6c6;

    --ink: #241a18;
    --muted: #7c6f6a;
    --line: #e8e0da;
    --line-soft: #efe8e4;
    --bg: #f5eeeb;
    --surface: #ffffff;

    --ok-bg: #ecfdf3; --ok-fg: #1c7a44; --ok-bd: #bbe9cd;
    --err-bg: #fdf2f0; --err-fg: #a12f1f; --err-bd: #f3ccc4;
    --info-bg: #fbf3e3; --info-fg: #8f6716; --info-bd: #ecd9ac;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- Autenticação ---------------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(120% 120% at 50% -10%, #6b2a1a 0%, #4F1A13 42%, #2a0d09 100%);
    padding: 24px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 32px 28px;
    box-shadow: 0 24px 60px rgba(20, 6, 4, .38);
    border-top: 3px solid var(--gold);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { height: 52px; width: auto; display: inline-block; }
.brand-mark {
    display: inline-block;
    font-weight: 800;
    letter-spacing: 2px;
    font-size: 20px;
    color: var(--accent);
    border: 2px solid var(--accent);
    border-radius: 6px;
    padding: 5px 12px;
}
.brand-sub { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.auth-title { font-size: 20px; margin: 0 0 4px; text-align: center; }
.auth-lead { margin: 0 0 20px; font-size: 13px; color: var(--muted); text-align: center; }
.approve-card { background: #faf5f2; border: 1px solid var(--line); border-radius: 10px; padding: 6px 16px; margin-bottom: 18px; }
.approve-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; font-size: 14px; }
.approve-row + .approve-row { border-top: 1px solid var(--line); }
.approve-k { color: var(--muted); font-weight: 600; }
.approve-v { color: var(--ink); text-align: right; word-break: break-all; }

.auth-links { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-links .sep { margin: 0 8px; color: var(--line); }
.auth-foot { text-align: center; margin-top: 18px; font-size: 12px; color: rgba(255, 235, 228, .75); }

/* ---------------- Formulários ---------------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: #4a3f3b; }
.field input,
.field select {
    width: 100%;
    min-width: 0;
    padding: 11px 12px;
    border: 1px solid #d8cec8;
    border-radius: 9px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.field select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4.5l4 4 4-4' fill='none' stroke='%237c6f6a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    text-overflow: ellipsis;
}
.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint-2);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 9px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, opacity .15s, border-color .15s, transform .1s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: #4a3f3b; border: 1px solid #d8cec8; }
.btn-ghost:hover { background: var(--line-soft); border-color: #b9aca5; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.inline { display: inline; margin: 0; }

/* ---------------- Alertas ---------------- */
.alert { border-radius: 10px; padding: 11px 13px; font-size: 13px; margin-bottom: 16px; border: 1px solid; }
.alert-ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd); }
.alert-err { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-bd); }
.alert-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-bd); word-break: break-all; }

/* ---------------- App (área protegida) ---------------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: 0 1px 3px rgba(40, 15, 10, .04); }
.topbar-inner {
    max-width: 1100px; margin: 0 auto; padding: 0 20px;
    height: 60px; display: flex; align-items: center; gap: 26px;
}
.topbar-brand { display: flex; align-items: center; gap: 11px; }
.topbar-logo { height: 28px; width: auto; display: block; }
.topbar-brand span {
    font-weight: 600; color: var(--muted); font-size: 12px; letter-spacing: .02em;
    padding-left: 11px; border-left: 1px solid var(--line);
}
.topnav { display: flex; gap: 2px; flex: 1; }
.topnav a {
    padding: 8px 13px; border-radius: 8px; font-size: 14px; color: #5b4f4b;
}
.topnav a:hover { background: var(--line-soft); text-decoration: none; }
.topnav a.active { background: var(--accent-tint); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: var(--muted); }
.topbar-user .btn-ghost { color: #5b4f4b; border-color: #d8cec8; }
.topbar-user .btn-ghost:hover { background: var(--line-soft); }

.app-main { max-width: 1100px; margin: 0 auto; padding: 28px 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.01em; }
.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 24px; }
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px;
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.card-action { position: relative; overflow: hidden; }
.card-action::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background: var(--gold); opacity: .9;
}
.card-action:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(79, 26, 19, .10); border-color: var(--accent); text-decoration: none; }
.card-icon {
    width: 42px; height: 42px; border-radius: 11px; background: var(--accent-tint);
    color: var(--accent); font-size: 20px; display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px; box-shadow: inset 0 0 0 1px var(--line);
}
.card-title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.card-desc { font-size: 13px; color: var(--muted); }

.placeholder-note {
    margin-top: 28px; padding: 14px 16px; border: 1px dashed #d6c7bf;
    border-radius: 12px; font-size: 13px; color: var(--muted); background: var(--surface);
}

/* ---------------- Listagem / tabela ---------------- */
.page-head--row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.back-link { font-size: 13px; color: var(--muted); display: inline-block; margin-bottom: 6px; }
.empty-state {
    background: var(--surface); border: 1px dashed #d6c7bf; border-radius: 14px;
    padding: 40px; text-align: center; color: var(--muted); margin-top: 20px;
}
.empty-state p { margin: 0 0 14px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; margin-top: 20px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: #faf5f2; font-weight: 700;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; font-variant-numeric: tabular-nums; }
.data-table tr:last-child td { border-bottom: none; }
.row-inactive { opacity: .55; }
.cell-main { display: flex; align-items: center; gap: 10px; }
.cell-main .strong { font-weight: 600; }
.sm { font-size: 12px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 1px solid rgba(0, 0, 0, .1); }
.ta-right { text-align: right; }
.ta-center { text-align: center; }
/* vence o text-align:left padrão do cabeçalho (.data-table th) */
.data-table th.ta-center { text-align: center; }
.data-table th.ta-right { text-align: right; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-off { background: #f1ece9; color: #8a7d77; }

.actions { display: inline-flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: nowrap; }
.actions .btn { min-width: 84px; }
.btn-danger { color: var(--err-fg); }
.btn-danger:hover { background: var(--err-bg); }

/* ---------------- Formulário em card ---------------- */
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 24px 24px; margin-top: 20px; }
.fs { border: none; border-top: 1px solid var(--line); padding: 18px 0 4px; margin: 0; }
.fs:first-of-type { border-top: none; }
.fs legend { font-size: 12px; font-weight: 700; color: var(--accent); padding: 0; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-endereco { grid-template-columns: repeat(4, 1fr); }
.grid-endereco .col-span-2 { grid-column: span 2; }
.grid-logo { grid-template-columns: 1fr auto auto; align-items: start; }
.field-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.field-color input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid #d8cec8; border-radius: 9px; background: #fff; cursor: pointer; }
.logo-preview { display: flex; flex-direction: column; gap: 6px; }
.logo-preview img { max-height: 46px; max-width: 160px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 14px; color: #4a3f3b; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------------- Emissão: upload ---------------- */
.upload-card { padding: 24px; }
.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; padding: 44px 20px; text-align: center; cursor: pointer;
    border: 2px dashed #d6c7bf; border-radius: 14px; background: #faf5f2;
    transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-tint); }
.dz-icon { font-size: 28px; color: var(--accent); }
.dz-text { font-size: 14px; color: #4a3f3b; }
.dz-file { font-size: 13px; margin-top: 4px; }

/* ---------------- Emissão: formulário ---------------- */
.grid-emissao-head { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
.section-head { margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 18px; }

.produto-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; }
.produto-card-head { display: flex; align-items: center; gap: 12px; }
.pc-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.pc-codigo {
    flex: none; font-size: 12px; font-weight: 700; color: var(--accent);
    background: var(--accent-tint); padding: 4px 9px; border-radius: 7px;
}
.pc-descricao { flex: 1; font-weight: 600; border: 1px solid transparent; background: transparent;
    padding: 6px 8px; border-radius: 7px; font-size: 15px; min-width: 0; }
.pc-descricao:hover { border-color: var(--line); }
.pc-descricao:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-tint-2); }
.pc-remove {
    flex: none; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
    background: #fff; color: #b0a49e; font-size: 20px; line-height: 1; cursor: pointer; transition: all .12s;
}
.pc-remove:hover { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-bd); }

.pc-fields { display: flex; gap: 12px; margin: 14px 0 6px; flex-wrap: wrap; }
.field-sm { width: 130px; }
.field-corrida { width: 180px; }
.field-corrida input { border-color: var(--accent); }

.tech-block { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.tech-block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.tech-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.btn-xs { padding: 4px 10px; font-size: 12px; }
.tech-rows { display: flex; flex-direction: column; gap: 6px; }
.tech-row { display: flex; gap: 6px; align-items: center; }
.tech-row input { padding: 7px 9px; border: 1px solid #d8cec8; border-radius: 8px; font-size: 13px; }
.ti-el { width: 90px; } .ti-val { width: 100px; } .ti-un { width: 70px; }
.ti-prop { flex: 1; min-width: 160px; } .ti-sig { width: 80px; }
.tech-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint-2); }
.row-remove {
    width: 28px; height: 28px; flex: none; border: 1px solid var(--line); background: #fff;
    color: #b0a49e; border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1;
}
.row-remove:hover { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-bd); }

.empty-produtos { padding: 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed #d6c7bf; border-radius: 14px; }

.form-actions-sticky {
    position: sticky; bottom: 0; background: rgba(245, 238, 235, .9); backdrop-filter: blur(4px);
    margin: 20px -20px 0; padding: 16px 20px; border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
    .grid-2, .grid-3, .grid-endereco, .grid-logo, .grid-emissao-head { grid-template-columns: 1fr; }
    .grid-endereco .col-span-2 { grid-column: auto; }
    .topnav { display: none; }
}
