/* ============================================================
   BRMS Versioning - admin panel
   Paleta: branco + azul claro. Tipografia: Montserrat.
   ============================================================ */

:root {
    /* Superficies */
    --bg:            #f7fafc;
    --surface:       #ffffff;
    --surface-alt:   #f1f5fb;
    --surface-soft:  #f8fafc;

    /* Bordas */
    --border:        #e3e8ef;
    --border-soft:   #eef2f7;
    --border-strong: #cbd5e1;

    /* Texto */
    --text:          #1f2937;
    --text-soft:     #4b5563;
    --text-mute:     #6b7280;
    --text-faint:    #94a3b8;

    /* Escala azul */
    --blue-50:       #eff6ff;
    --blue-100:      #dbeafe;
    --blue-200:      #bfdbfe;
    --blue-500:      #3b82f6;
    --blue-600:      #2563eb;
    --blue-700:      #1d4ed8;

    /* Semantica */
    --primary:       #2563eb;
    --primary-hover: #1d4ed8;
    --primary-wash:  #eff6ff;
    --danger:        #dc2626;
    --danger-hover:  #b91c1c;
    --danger-wash:   #fef2f2;
    --success:       #059669;
    --success-wash:  #ecfdf5;

    /* Tipografia */
    --font:      "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;

    /* Layout */
    --gutter:     32px;
    --maxw:       1200px;
    --radius:     8px;
    --radius-sm:  6px;
    --radius-pill: 999px;
    --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow:     0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-hover: 0 4px 12px rgba(37, 99, 235, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button { font: inherit; cursor: pointer; }
a { color: inherit; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ----- Topbar ------------------------------------------------------ */
.masthead {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.masthead__inner {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 14px var(--gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.masthead__brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
}

.masthead__mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.02em;
}

.masthead__name {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.005em;
    color: var(--text);
}

.masthead__sub {
    color: var(--text-mute);
    font-size: 12px;
    font-weight: 500;
    margin-left: 8px;
}

.masthead__nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.masthead__nav a {
    text-decoration: none;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    transition: background 0.12s, color 0.12s;
}

.masthead__nav a:hover {
    background: var(--surface-alt);
    color: var(--primary);
}

/* ----- Main -------------------------------------------------------- */
main {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 40px var(--gutter) 80px;
}

/* ----- Flash ------------------------------------------------------- */
.flash-wrap { margin-bottom: 20px; }

.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
}

.flash--ok {
    background: var(--success-wash);
    border-color: rgba(5, 150, 105, 0.25);
    color: var(--success);
}

.flash--err {
    background: var(--danger-wash);
    border-color: rgba(220, 38, 38, 0.25);
    color: var(--danger);
}

.flash__bullet {
    font-weight: 600;
    font-size: 14px;
    line-height: 1;
}

/* ----- Page heading ------------------------------------------------ */
.eyebrow { display: none; }

.page-title {
    font-family: var(--font);
    font-weight: 600;
    font-size: 28px;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0 0 8px;
}

.page-title em {
    font-style: normal;
    color: inherit;
}

.page-lede {
    font-family: var(--font);
    font-style: normal;
    font-weight: 400;
    color: var(--text-soft);
    font-size: 14.5px;
    line-height: 1.6;
    max-width: 72ch;
    margin: 0 0 28px;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.toolbar__title { flex: 1; min-width: 0; }

.crumb {
    color: var(--text-mute);
    font-size: 13px;
    margin: 0;
}

.crumb a {
    color: var(--text-soft);
    text-decoration: none;
    transition: color 0.12s;
}

.crumb a:hover { color: var(--primary); }

/* ----- Section / card --------------------------------------------- */
.section {
    --section-accent: var(--primary);
    background: #f6f9ff;
    border: 1px solid var(--blue-100);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.04),
        0 6px 18px rgba(37, 99, 235, 0.06);
}

.section--ident    { --section-accent: var(--primary); }
.section--chaves   { --section-accent: var(--blue-400); }
.section--vigencias{ --section-accent: #0f766e; }

.section__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--blue-100);
}

.section__title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.005em;
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.section__title::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--section-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
    flex-shrink: 0;
}

/* ----- Parametro detail grid (ident + chaves lado a lado) -------- */
.parametro-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
    align-items: start;
}

.parametro-grid > .section {
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .parametro-grid {
        grid-template-columns: 1fr;
    }
}

.section__count {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-mute);
}

/* ----- Tables ------------------------------------------------------ */
.ledger {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ledger thead th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-mute);
    padding: 0 12px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: bottom;
}

.ledger thead th:first-child { padding-left: 0; }
.ledger thead th:last-child  { padding-right: 0; text-align: right; }

.ledger tbody tr {
    border-bottom: 1px solid var(--border-soft);
    transition: background 0.1s;
}

.ledger tbody tr:hover { background: var(--surface-alt); }
.ledger tbody tr:last-child { border-bottom: none; }

.ledger tbody td {
    padding: 14px 12px;
    vertical-align: top;
    color: var(--text);
}

.ledger tbody td:first-child { padding-left: 0; }
.ledger tbody td:last-child  { padding-right: 0; text-align: right; }

.row-num {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-faint);
}

.entry-name {
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    color: var(--text);
    transition: color 0.12s;
}

.entry-name:hover { color: var(--primary); }

.entry-desc {
    color: var(--text-soft);
    font-size: 13px;
    line-height: 1.5;
}

.entry-meta {
    font-size: 12px;
    color: var(--text-mute);
    white-space: nowrap;
}

.mono { font-family: var(--font-mono); font-size: 12.5px; }

.json {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    background: var(--surface-soft);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin: 0;
    white-space: pre;
    color: var(--text-soft);
    max-width: 380px;
    overflow-x: auto;
}

.num-cell {
    font-family: var(--font-mono);
    font-feature-settings: "tnum";
    font-size: 13px;
    color: var(--text);
}

/* ----- Buttons ----------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface-alt);
    border-color: var(--text-faint);
}

.btn:active { transform: translateY(0.5px); }

.btn--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn--primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
    box-shadow: var(--shadow-hover);
}

.btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-soft);
}

.btn--ghost:hover {
    background: var(--surface-alt);
    border-color: transparent;
    color: var(--primary);
}

.btn--danger {
    background: transparent;
    border-color: var(--border);
    color: var(--danger);
}

.btn--danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn--sm {
    font-size: 12px;
    padding: 5px 10px;
}

.btn-row {
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ----- Forms ------------------------------------------------------- */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.section .form-card {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin-bottom: 0;
}

.field { margin-bottom: 18px; }

.field label,
.field > .label {
    display: block;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-soft);
    margin-bottom: 6px;
    letter-spacing: 0;
    text-transform: none;
}

.field input[type=text],
.field input[type=number],
.field input[type=date],
.field input[type=email],
.field textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-family: var(--font);
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.1s, box-shadow 0.1s;
}

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-wash);
}

.field input:disabled {
    color: var(--text-mute);
    background: var(--surface-soft);
    border-style: dashed;
}

.field textarea {
    min-height: 110px;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    resize: vertical;
}

.field--mono input,
.field--mono textarea {
    font-family: var(--font-mono);
    font-size: 13px;
}

.field__hint {
    margin-top: 6px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-mute);
    letter-spacing: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

@media (max-width: 720px) {
    .grid-2 { grid-template-columns: 1fr; gap: 0; }
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
}

.section .form-card .form-actions {
    border-top-color: var(--border-soft);
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

.inline-form input[type=text] {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 6px 10px;
    min-width: 240px;
    font-family: var(--font);
    font-size: 13px;
}

.inline-form input[type=text]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-wash);
}

/* ----- Pills / tags ------------------------------------------------ */
.pill {
    display: inline-flex;
    align-items: center;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    color: var(--primary);
    background: var(--primary-wash);
    border: 1px solid var(--blue-100);
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    letter-spacing: 0;
    text-transform: none;
}

.stamp {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font);
    font-style: normal;
    font-weight: 500;
    font-size: 12px;
    color: var(--success);
    background: var(--success-wash);
    border: 1px solid rgba(5, 150, 105, 0.25);
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    transform: none;
    letter-spacing: 0;
}

.stamp::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
}

/* ----- Empty state ------------------------------------------------- */
.empty {
    padding: 40px 0;
    text-align: center;
    color: var(--text-mute);
    font-family: var(--font);
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    border-top: none;
    border-bottom: none;
}

/* ----- Vigencia indicator ----------------------------------------- */
.vig {
    font-family: var(--font-mono);
    font-feature-settings: "tnum";
    font-size: 12.5px;
    color: var(--text-soft);
    white-space: nowrap;
}

.vig em {
    font-style: normal;
    color: var(--text-faint);
    margin: 0 6px;
    font-family: var(--font);
}

.vig--open { color: var(--success); }

/* ----- Danger zone ------------------------------------------------- */
.danger-zone {
    margin-top: 32px;
    padding: 18px 22px;
    border: 1px solid rgba(220, 38, 38, 0.25);
    background: var(--danger-wash);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.danger-zone p {
    margin: 0;
    font-family: var(--font);
    font-style: normal;
    font-size: 13px;
    color: var(--danger);
}

/* ----- Misc -------------------------------------------------------- */
.muted { color: var(--text-mute); }

::selection {
    background: var(--primary-wash);
    color: var(--primary);
}

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

/* ----- Pill variants ----------------------------------------------- */
.pill--ok {
    color: var(--success);
    background: var(--success-wash);
    border-color: rgba(5, 150, 105, 0.25);
}

.pill--mute {
    color: var(--text-mute);
    background: var(--surface-soft);
    border-color: var(--border);
}

/* ----- Chaves tag cloud (parametro_valor.chaves) ------------------ */
.chaves-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.chave-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    font-family: var(--font);
    font-size: 12px;
    background: var(--blue-50);
    border: 1px solid var(--blue-100);
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    line-height: 1.4;
}

.chave-pill__k {
    color: var(--primary);
    font-weight: 600;
}

.chave-pill__sep {
    color: var(--text-faint);
    margin: 0 1px;
}

.chave-pill__v {
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11.5px;
}

/* ----- Drawer (top sheet) ----------------------------------------- */
.drawer-root {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.drawer__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    animation: drawer-fade 160ms ease-out;
    text-decoration: none;
    cursor: pointer;
}

.drawer {
    position: relative;
    width: min(960px, 92vw);
    max-height: 80vh;
    background: var(--surface);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    animation: drawer-down 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
    overflow: hidden;
}

@keyframes drawer-down {
    from { transform: translateY(-100%); opacity: 0.6; }
    to   { transform: translateY(0);     opacity: 1;   }
}

@keyframes drawer-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.drawer__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-soft);
}

.drawer__eyebrow {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-mute);
    margin: 0 0 4px;
}

.drawer__title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.drawer__arrow {
    color: var(--text-faint);
    font-weight: 400;
}

.drawer__close {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    color: var(--text-mute);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: background 0.12s, color 0.12s;
}

.drawer__close:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.drawer__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.drawer__topform {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--blue-50);
}

.drawer__scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px 24px;
}

.drawer__scroll .ledger thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.drawer__foot {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 16px 24px;
    border-top: 1px solid var(--border-soft);
    background: var(--surface-soft);
}

.drawer__input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text);
    transition: border-color 0.1s, box-shadow 0.1s;
}

.drawer__input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-wash);
}
