/**
 * Sistema Comercial TKI — folha de estilo unica.
 *
 * CSS puro, sem build e sem framework: o app e enxuto o bastante para nao
 * justificar Tailwind, e assim ele nao depende do pipeline do ORAC.
 * Prefixo cm- em tudo para nunca colidir com estilo herdado.
 */

/* ==================================================================
   Tokens
   ================================================================== */

:root {
    --cm-bg: #f5f7fb;
    --cm-surface: #ffffff;
    --cm-surface-2: #fafbfd;
    --cm-ink: #101828;
    --cm-ink-2: #475467;
    --cm-ink-3: #98a2b3;
    --cm-line: #e4e7ec;

    --cm-brand: #2563eb;
    --cm-brand-600: #1d4ed8;
    --cm-brand-700: #1e40af;
    --cm-brand-soft: #eff4ff;
    --cm-brand-rgb: 37 99 235;

    --cm-ok: #059669;
    --cm-ok-soft: #ecfdf5;
    --cm-warn: #d97706;
    --cm-warn-soft: #fffbeb;
    --cm-danger: #dc2626;
    --cm-danger-soft: #fef2f2;

    --cm-r: 14px;
    --cm-r-sm: 9px;
    --cm-r-lg: 20px;

    --cm-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --cm-shadow: 0 4px 16px rgba(16, 24, 40, .07);
    --cm-shadow-lg: 0 24px 56px rgba(16, 24, 40, .14);

    --cm-ease: cubic-bezier(.16, 1, .3, 1);
    --cm-fast: 130ms;
    --cm-norm: 230ms;

    --cm-sidebar: 248px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-cm-theme="light"]) {
        --cm-bg: #0b1020;
        --cm-surface: #121829;
        --cm-surface-2: #161d31;
        --cm-ink: #e8ecf5;
        --cm-ink-2: #a3aec4;
        --cm-ink-3: #6b7793;
        --cm-line: #232c42;
        --cm-brand-soft: #16224a;
        --cm-ok-soft: #06251b;
        --cm-warn-soft: #2a1e05;
        --cm-danger-soft: #2b1113;
        --cm-shadow-lg: 0 24px 56px rgba(0, 0, 0, .5);
    }
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--cm-bg);
    color: var(--cm-ink);
    -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
    outline: 2px solid var(--cm-brand);
    outline-offset: 2px;
}

/* ==================================================================
   Animacoes
   ================================================================== */

@keyframes cm-spin { to { transform: rotate(360deg); } }

@keyframes cm-rise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

@keyframes cm-shimmer {
    0%   { background-position: -420px 0; }
    100% { background-position: 420px 0; }
}

@keyframes cm-float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50%      { transform: translate(18px, -22px) scale(1.06); }
}

/* ==================================================================
   Tela de acesso
   ================================================================== */

.cm-auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.cm-auth__art {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.cm-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(72px);
    opacity: .5;
    animation: cm-float 15s var(--cm-ease) infinite;
}

.cm-orb--1 {
    width: 460px; height: 460px;
    top: -140px; left: -110px;
    background: rgb(var(--cm-brand-rgb) / .5);
}

.cm-orb--2 {
    width: 400px; height: 400px;
    bottom: -150px; right: -90px;
    background: rgba(16, 185, 129, .38);
    animation-delay: -7s;
}

.cm-auth__card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 404px;
    background: var(--cm-surface);
    border: 1px solid var(--cm-line);
    border-radius: var(--cm-r-lg);
    box-shadow: var(--cm-shadow-lg);
    padding: 36px 30px 26px;
    animation: cm-rise 460ms var(--cm-ease) both;
}

.cm-auth__head { text-align: center; margin-bottom: 24px; }

.cm-auth__badge {
    display: inline-grid;
    place-items: center;
    width: 52px; height: 52px;
    margin-bottom: 14px;
    border-radius: var(--cm-r);
    background: linear-gradient(135deg, var(--cm-brand), var(--cm-brand-700));
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: .04em;
    box-shadow: 0 8px 22px rgb(var(--cm-brand-rgb) / .34);
}

.cm-auth__title {
    margin: 0;
    font-size: 25px;
    font-weight: 800;
    letter-spacing: -.02em;
}

.cm-auth__sub {
    margin: 6px 0 0;
    font-size: 13.5px;
    color: var(--cm-ink-2);
}

.cm-auth__foot {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--cm-line);
    text-align: center;
    font-size: 12px;
    color: var(--cm-ink-3);
}

/* ==================================================================
   Formulario
   ================================================================== */

.cm-form { display: flex; flex-direction: column; gap: 15px; }

.cm-field { display: flex; flex-direction: column; gap: 6px; }

.cm-field__label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--cm-ink-2);
}

.cm-input {
    width: 100%;
    padding: 11px 13px;
    font: inherit;
    font-size: 14.5px;
    color: var(--cm-ink);
    background: var(--cm-surface);
    border: 1px solid var(--cm-line);
    border-radius: var(--cm-r-sm);
    transition: border-color var(--cm-fast) var(--cm-ease),
                box-shadow var(--cm-fast) var(--cm-ease);
}

.cm-input:focus {
    outline: none;
    border-color: var(--cm-brand);
    box-shadow: 0 0 0 3px rgb(var(--cm-brand-rgb) / .16);
}

.cm-input--code {
    text-align: center;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: .34em;
    padding: 13px;
}

.cm-hint {
    margin: -4px 0 0;
    font-size: 12.5px;
    color: var(--cm-ink-2);
    line-height: 1.5;
}

.cm-link {
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--cm-brand);
    text-decoration: none;
}

.cm-link:hover { text-decoration: underline; }

/* ==================================================================
   Botoes
   ================================================================== */

.cm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 17px;
    font: inherit;
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--cm-r-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--cm-fast) var(--cm-ease),
                border-color var(--cm-fast) var(--cm-ease),
                color var(--cm-fast) var(--cm-ease),
                transform var(--cm-fast) var(--cm-ease),
                box-shadow var(--cm-fast) var(--cm-ease);
}

.cm-btn:active:not(:disabled) { transform: translateY(1px); }
.cm-btn:disabled, .cm-btn.is-busy { opacity: .62; cursor: not-allowed; transform: none; }
.cm-btn--block { width: 100%; }
.cm-btn--sm { min-height: 34px; padding: 7px 12px; font-size: 13px; }

.cm-btn--primary {
    background: var(--cm-brand);
    color: #fff;
    box-shadow: 0 6px 16px rgb(var(--cm-brand-rgb) / .26);
}

.cm-btn--primary:hover:not(:disabled) {
    background: var(--cm-brand-600);
    box-shadow: 0 9px 22px rgb(var(--cm-brand-rgb) / .34);
}

.cm-btn--ghost {
    background: transparent;
    border-color: var(--cm-line);
    color: var(--cm-ink);
}

.cm-btn--ghost:hover:not(:disabled) { background: var(--cm-surface-2); }

.cm-btn--danger { background: var(--cm-danger); color: #fff; }
.cm-btn--danger:hover:not(:disabled) { background: #b91c1c; }

/* ==================================================================
   Alertas
   ================================================================== */

.cm-alert {
    padding: 11px 13px;
    margin-bottom: 15px;
    border-radius: var(--cm-r-sm);
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.5;
    animation: cm-rise 260ms var(--cm-ease) both;
}

.cm-alert--erro   { background: var(--cm-danger-soft); border-color: rgba(220,38,38,.28); color: #991b1b; }
.cm-alert--aviso  { background: var(--cm-warn-soft);   border-color: rgba(217,119,6,.28);  color: #92400e; }
.cm-alert--ok     { background: var(--cm-ok-soft);     border-color: rgba(5,150,105,.28);  color: #065f46; }

/* ==================================================================
   Spinner e carregamento
   ================================================================== */

.cm-spinner {
    display: inline-block;
    width: 17px; height: 17px;
    border: 2.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: cm-spin 620ms linear infinite;
}

.cm-spinner--lg { width: 30px; height: 30px; border-width: 3px; }

.cm-loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    gap: 10px;
    background: rgb(255 255 255 / .74);
    backdrop-filter: blur(2px);
    color: var(--cm-brand);
    border-radius: inherit;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-cm-theme="light"]) .cm-loading { background: rgb(18 24 41 / .74); }
}

.cm-skeleton {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: var(--cm-line);
    background-image: linear-gradient(90deg, var(--cm-line) 0, var(--cm-surface-2) 210px, var(--cm-line) 420px);
    background-size: 840px 100%;
    animation: cm-shimmer 1.4s linear infinite;
}

/* ==================================================================
   Estrutura do app
   ================================================================== */

.cm-shell { display: flex; min-height: 100vh; }

.cm-side {
    width: var(--cm-sidebar);
    flex: none;
    background: var(--cm-surface);
    border-right: 1px solid var(--cm-line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.cm-side__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 18px 16px;
    border-bottom: 1px solid var(--cm-line);
}

.cm-side__mark {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    flex: none;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--cm-brand), var(--cm-brand-700));
    color: #fff;
    font-weight: 800;
    font-size: 12px;
}

.cm-side__name { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.cm-side__tag  { font-size: 11px; color: var(--cm-ink-3); font-weight: 600; }

.cm-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }

.cm-nav__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: var(--cm-r-sm);
    font-size: 14px;
    font-weight: 650;
    color: var(--cm-ink-2);
    text-decoration: none;
    transition: background var(--cm-fast) var(--cm-ease),
                color var(--cm-fast) var(--cm-ease);
}

.cm-nav__item:hover { background: var(--cm-surface-2); color: var(--cm-ink); }

.cm-nav__item.is-active {
    background: var(--cm-brand-soft);
    color: var(--cm-brand-700);
}

.cm-nav__icon { width: 18px; height: 18px; flex: none; }

.cm-side__foot { padding: 12px; border-top: 1px solid var(--cm-line); }

.cm-user { display: flex; align-items: center; gap: 10px; }

.cm-user__avatar {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    flex: none;
    border-radius: 50%;
    background: var(--cm-brand-soft);
    color: var(--cm-brand-700);
    font-weight: 800;
    font-size: 13px;
}

.cm-user__name { font-size: 13px; font-weight: 700; line-height: 1.2; }
.cm-user__role { font-size: 11.5px; color: var(--cm-ink-3); }

.cm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.cm-top {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 24px;
    background: var(--cm-surface);
    border-bottom: 1px solid var(--cm-line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.cm-top__title { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.cm-top__sub   { margin: 2px 0 0; font-size: 13px; color: var(--cm-ink-2); }
.cm-top__spacer { flex: 1; }

.cm-burger {
    display: none;
    width: 38px; height: 38px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--cm-line);
    border-radius: var(--cm-r-sm);
    cursor: pointer;
    color: var(--cm-ink);
}

.cm-content { padding: 24px; flex: 1; }

/* ==================================================================
   Cartoes e indicadores
   ================================================================== */

.cm-grid { display: grid; gap: 16px; }
.cm-grid--kpi { grid-template-columns: repeat(auto-fit, minmax(216px, 1fr)); }
.cm-grid--2   { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.cm-card {
    position: relative;
    background: var(--cm-surface);
    border: 1px solid var(--cm-line);
    border-radius: var(--cm-r);
    box-shadow: var(--cm-shadow-sm);
    padding: 18px;
    animation: cm-rise 340ms var(--cm-ease) both;
}

.cm-card__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.cm-card__title { margin: 0; font-size: 15px; font-weight: 800; }

.cm-kpi__label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--cm-ink-3);
}

.cm-kpi__value {
    margin-top: 7px;
    font-size: 27px;
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.1;
}

.cm-kpi__delta { margin-top: 5px; font-size: 12.5px; font-weight: 700; }
.cm-kpi__delta--up   { color: var(--cm-ok); }
.cm-kpi__delta--down { color: var(--cm-danger); }

/* ==================================================================
   Tabelas
   ================================================================== */

.cm-tablewrap {
    overflow-x: auto;
    border: 1px solid var(--cm-line);
    border-radius: var(--cm-r);
    background: var(--cm-surface);
}

.cm-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.cm-table th {
    text-align: left;
    padding: 11px 14px;
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--cm-ink-3);
    background: var(--cm-surface-2);
    border-bottom: 1px solid var(--cm-line);
    white-space: nowrap;
}

.cm-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--cm-line);
    color: var(--cm-ink);
}

.cm-table tbody tr:last-child td { border-bottom: 0; }
.cm-table tbody tr { transition: background var(--cm-fast) var(--cm-ease); }
.cm-table tbody tr:hover { background: var(--cm-surface-2); }

.cm-num { text-align: right; font-variant-numeric: tabular-nums; }

/* ==================================================================
   Etiquetas
   ================================================================== */

.cm-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}

.cm-tag--neutro { background: var(--cm-surface-2); color: var(--cm-ink-2); }
.cm-tag--info   { background: var(--cm-brand-soft); color: var(--cm-brand-700); }
.cm-tag--ok     { background: var(--cm-ok-soft); color: var(--cm-ok); }
.cm-tag--aviso  { background: var(--cm-warn-soft); color: var(--cm-warn); }
.cm-tag--risco  { background: var(--cm-danger-soft); color: var(--cm-danger); }

/* ==================================================================
   Vazio
   ================================================================== */

.cm-empty {
    display: grid;
    place-items: center;
    gap: 5px;
    padding: 46px 20px;
    text-align: center;
}

.cm-empty__icon { font-size: 30px; opacity: .6; }
.cm-empty__title { font-size: 15px; font-weight: 700; }
.cm-empty__text { font-size: 13.5px; color: var(--cm-ink-2); max-width: 42ch; line-height: 1.55; }

/* ==================================================================
   Responsivo
   ================================================================== */

@media (max-width: 1024px) {
    .cm-side {
        position: fixed;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform var(--cm-norm) var(--cm-ease);
        box-shadow: var(--cm-shadow-lg);
    }
    .cm-side.is-open { transform: none; }
    .cm-burger { display: inline-flex; }
    .cm-backdrop {
        position: fixed;
        inset: 0;
        z-index: 50;
        background: rgba(16, 24, 40, .45);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--cm-norm) var(--cm-ease);
    }
    .cm-backdrop.is-open { opacity: 1; pointer-events: auto; }
}

@media (max-width: 640px) {
    .cm-content { padding: 16px; }
    .cm-top { padding: 12px 16px; }
    .cm-top__title { font-size: 17px; }
    .cm-kpi__value { font-size: 23px; }
    .cm-auth__card { padding: 28px 22px 20px; }
}

/* ==================================================================
   Avisos flutuantes
   ================================================================== */

.cm-toasts {
    position: fixed;
    z-index: 9999;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-width: min(370px, calc(100vw - 32px));
    pointer-events: none;
}

.cm-toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 13px;
    border-radius: var(--cm-r-sm);
    background: var(--cm-surface);
    border: 1px solid var(--cm-line);
    border-left: 4px solid var(--cm-brand);
    box-shadow: var(--cm-shadow-lg);
    font-size: 13.5px;
    font-weight: 650;
    line-height: 1.45;
    color: var(--cm-ink);
    pointer-events: auto;
    opacity: 0;
    transform: translateX(14px) scale(.98);
    transition: opacity var(--cm-norm) var(--cm-ease),
                transform var(--cm-norm) var(--cm-ease);
}

.cm-toast.is-open { opacity: 1; transform: none; }

.cm-toast__txt { flex: 1; }

.cm-toast__x {
    flex: none;
    border: 0;
    background: transparent;
    font-size: 19px;
    line-height: 1;
    color: var(--cm-ink-3);
    cursor: pointer;
    padding: 0 2px;
}

.cm-toast__x:hover { color: var(--cm-ink); }

.cm-toast--ok   { border-left-color: var(--cm-ok); }
.cm-toast--erro { border-left-color: var(--cm-danger); }
.cm-toast--info { border-left-color: var(--cm-brand); }

@media (max-width: 640px) {
    .cm-toasts { top: auto; bottom: 16px; left: 16px; right: 16px; max-width: none; }
    .cm-toast { transform: translateY(14px) scale(.98); }
}

/* ==================================================================
   Filtros e seletor de periodo
   ================================================================== */

.cm-filtros {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cm-filtros__info { font-size: 13px; color: var(--cm-ink-2); font-weight: 600; }

.cm-seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--cm-surface-2);
    border: 1px solid var(--cm-line);
    border-radius: var(--cm-r-sm);
}

.cm-seg__btn {
    padding: 7px 13px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--cm-ink-2);
    background: transparent;
    border: 0;
    border-radius: 7px;
    cursor: pointer;
    transition: background var(--cm-fast) var(--cm-ease),
                color var(--cm-fast) var(--cm-ease);
}

.cm-seg__btn:hover { color: var(--cm-ink); }

.cm-seg__btn.is-active {
    background: var(--cm-surface);
    color: var(--cm-brand-700);
    box-shadow: var(--cm-shadow-sm);
}

/* ==================================================================
   Barra de progresso
   ================================================================== */

.cm-barra {
    height: 9px;
    border-radius: 999px;
    background: var(--cm-line);
    overflow: hidden;
}

.cm-barra__fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--cm-brand);
    transition: width 620ms var(--cm-ease);
}

.cm-barra__fill--ok    { background: var(--cm-ok); }
.cm-barra__fill--aviso { background: var(--cm-warn); }
.cm-barra__fill--info  { background: var(--cm-brand); }

/* ==================================================================
   Lista de definicoes
   ================================================================== */

.cm-dl { margin: 0; display: flex; flex-direction: column; gap: 10px; }

.cm-dl > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.cm-dl dt { font-size: 13.5px; color: var(--cm-ink-2); font-weight: 600; }
.cm-dl dd { margin: 0; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
