/* ============================================================================
   PORTAL DE CONTRATOS FISCAIS — DESIGN SYSTEM COMPARTILHADO
   ============================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---- CSS CUSTOM PROPERTIES ---- */
:root {
    --bg:           #0d1117;
    --surface:      #161b22;
    --surface2:     #1c2128;
    --border:       #30363d;
    --accent:       #1a73e8;
    --accent-dark:  #1557b0;
    --green:        #238636;
    --green-light:  #56d364;
    --orange:       #d29922;
    --orange-light: #e3b341;
    --red:          #da3633;
    --red-light:    #ff7b72;
    --text:         #e6edf3;
    --muted:        #8b949e;
    --input-bg:     #0d1117;
    --radius:       10px;
    --radius-sm:    6px;
    --radius-lg:    14px;
}

/* ---- BASE ---- */
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes progressFill {
    from { width: 0 !important; }
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(14px) scale(.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateY(-8px) scale(.95); }
}

/* ============================================================================
   TOPBAR
   ============================================================================ */

.topbar {
    background: rgba(22, 27, 34, 0.92);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    color: inherit;
}

.topbar-brand svg { width: 20px; height: 20px; fill: var(--accent); flex-shrink: 0; }

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-left > svg { width: 18px; height: 18px; fill: var(--accent); }
.topbar-contract { font-size: 14px; font-weight: 600; color: var(--accent); }
.topbar-sep      { color: var(--border); font-size: 20px; font-weight: 300; }
.topbar-brand-text { font-weight: 700; font-size: 14px; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--muted);
}

.topbar-right strong { color: var(--text); }

.role-tag {
    background: rgba(26,115,232,.15);
    border: 1px solid rgba(26,115,232,.3);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    padding: 9px 18px;
    cursor: pointer;
    transition: background .15s, transform .1s, box-shadow .15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-dark);
    box-shadow: 0 0 14px rgba(26,115,232,.4);
}

.btn-secondary {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--muted);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
    background: rgba(218,54,51,.12);
    border: 1px solid rgba(218,54,51,.4);
    color: var(--red-light);
}
.btn-danger:hover { background: rgba(218,54,51,.22); }

.btn-block { display: block; width: 100%; text-align: center; }

.btn-back, .btn-nav, .btn-logout {
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--muted);
    padding: 5px 12px;
    cursor: pointer;
    text-decoration: none;
    transition: border-color .2s, color .2s;
    white-space: nowrap;
}

.btn-back:hover,
.btn-nav:hover  { border-color: var(--accent); color: var(--accent); }
.btn-logout:hover { border-color: var(--red); color: var(--red-light); }

.btn-sm {
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    border-radius: 5px;
    border: 1px solid var(--border);
    padding: 4px 10px;
    cursor: pointer;
    background: transparent;
    color: var(--muted);
    transition: border-color .15s, color .15s;
}

.btn-sm.edit:hover   { border-color: var(--accent); color: var(--accent); }
.btn-sm.delete:hover { border-color: var(--red); color: var(--red-light); }

/* ============================================================================
   PAGE LAYOUT
   ============================================================================ */

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 36px 24px 60px;
    animation: fadeInUp .35s ease both;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
}

.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p  { font-size: 14px; color: var(--muted); margin-top: 4px; }

/* ============================================================================
   PANELS
   ============================================================================ */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}

.panel-header h2 {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header h2 svg { width: 16px; height: 16px; fill: var(--muted); }

.panel-body { padding: 20px; }

/* ============================================================================
   ALERTS
   ============================================================================ */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 20px;
    line-height: 1.5;
    animation: fadeInUp .25s ease both;
}

.alert-error   { background: rgba(218,54,51,.1); border: 1px solid rgba(218,54,51,.4);  color: var(--red-light); }
.alert-success { background: rgba(35,134,54,.1); border: 1px solid rgba(35,134,54,.4);  color: var(--green-light); }

/* ============================================================================
   TOAST
   ============================================================================ */

.toast-container {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 380px;
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: toastIn .32s cubic-bezier(.34,1.56,.64,1) both;
    box-shadow: 0 8px 28px rgba(0,0,0,.5);
}

.toast.closing { animation: toastOut .25s ease forwards; }

.toast-success {
    background: rgba(13, 25, 13, 0.96);
    border: 1px solid rgba(35,134,54,.55);
    color: var(--green-light);
}

.toast-error {
    background: rgba(25, 13, 13, 0.96);
    border: 1px solid rgba(218,54,51,.55);
    color: var(--red-light);
}

.toast svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; margin-top: 1px; }

/* ============================================================================
   BADGES
   ============================================================================ */

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .3px;
    flex-shrink: 0;
}

.badge-green   { background: rgba(35,134,54,.15);  border: 1px solid rgba(35,134,54,.4);  color: var(--green-light); }
.badge-orange  { background: rgba(210,153,34,.15); border: 1px solid rgba(210,153,34,.4); color: var(--orange-light); }
.badge-red     { background: rgba(218,54,51,.15);  border: 1px solid rgba(218,54,51,.4);  color: var(--red-light); }
.badge-paid    { background: rgba(35,134,54,.15);  border: 1px solid rgba(35,134,54,.4);  color: var(--green-light); }
.badge-pending { background: rgba(210,153,34,.15); border: 1px solid rgba(210,153,34,.4); color: var(--orange-light); }

/* ============================================================================
   FORM ELEMENTS
   ============================================================================ */

.field { margin-bottom: 14px; }

.field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 5px;
    letter-spacing: .1px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}

.field textarea { resize: vertical; min-height: 60px; }
.field select   { cursor: pointer; }

.field.net-value input {
    font-weight: 700;
    color: var(--green-light);
    border-color: rgba(35,134,54,.4);
}

.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ============================================================================
   PROGRESS BAR
   ============================================================================ */

.progress-wrap { margin-top: 10px; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.progress-bar {
    background: var(--border);
    border-radius: 99px;
    height: 6px;
    overflow: hidden;
}

.progress-bar-inner {
    height: 100%;
    background: linear-gradient(90deg, var(--green), #4fc76f);
    border-radius: 99px;
    animation: progressFill .9s cubic-bezier(.22,1,.36,1) both;
    animation-delay: .15s;
}

/* ============================================================================
   TABLES
   ============================================================================ */

table { width: 100%; border-collapse: collapse; }

th, td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
    background: var(--surface2);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.014); }

.empty-row td  { text-align: center; color: var(--muted); padding: 40px; }
.totals-row td { font-weight: 600; background: var(--surface2); border-top: 1px solid var(--border); }
.td-actions    { display: flex; gap: 6px; }

/* ============================================================================
   INFO GRID (form_contract — dados do contrato)
   ============================================================================ */

.info-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.info-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.info-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }

.info-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.info-item .info-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    margin-bottom: 4px;
}

.info-item .info-val { font-size: 14px; font-weight: 500; color: var(--text); }
.info-item .info-val.mono { font-family: 'Courier New', monospace; font-size: 13px; }

/* ============================================================================
   FORM GRIDS (form_contract — formulário de pagamento)
   ============================================================================ */

.form-grid           { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-grid.cols-4    { grid-template-columns: repeat(4, 1fr); }
.form-grid.cols-5    { grid-template-columns: repeat(5, 1fr); }
.form-grid.full      { grid-template-columns: 1fr; }

.resp-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(26,115,232,.07);
    border: 1px solid rgba(26,115,232,.22);
    border-radius: 7px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 18px;
}
.resp-banner strong { color: var(--accent); }

/* ============================================================================
   METRICS GRID (dashboard)
   ============================================================================ */

.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    animation: fadeInUp .4s ease both;
    transition: border-color .2s, box-shadow .2s;
}
.metric-card:hover { border-color: rgba(26,115,232,.4); box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.metric-card:nth-child(2) { animation-delay: .08s; }
.metric-card:nth-child(3) { animation-delay: .16s; }

.metric-card .label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: .4px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.metric-card .label svg { width: 15px; height: 15px; fill: currentColor; opacity: .8; }

.metric-card .value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.5px;
}

.metric-card .value.spent      { color: var(--green-light); }
.metric-card .value.percentage { color: var(--accent); }

.row-progress-bar {
    background: var(--border);
    border-radius: 99px;
    height: 4px;
    width: 80px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
    overflow: hidden;
}
.row-progress-inner { height: 100%; background: var(--accent); animation: progressFill .8s ease both; }

.filter-select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color .2s;
}
.filter-select:focus { border-color: var(--accent); }

/* ============================================================================
   CONTRACTS GRID (select_contract)
   ============================================================================ */

.search-bar { position: relative; margin-bottom: 24px; }

.search-bar input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px 10px 40px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

.search-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.1);
}

.search-bar svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    fill: var(--muted);
    pointer-events: none;
}

.contracts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.contract-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: border-color .2s, transform .18s, box-shadow .2s;
    animation: fadeInUp .4s ease both;
}

.contract-card:nth-child(2) { animation-delay: .07s; }
.contract-card:nth-child(3) { animation-delay: .13s; }
.contract-card:nth-child(4) { animation-delay: .19s; }
.contract-card:nth-child(5) { animation-delay: .25s; }
.contract-card:nth-child(6) { animation-delay: .30s; }

.contract-card:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 8px 28px rgba(0,0,0,.35);
}

.contract-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.contract-number { font-size: 15px; font-weight: 700; color: var(--text); }

.contract-object {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 16px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.contract-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
    margin-top: 4px;
}

.meta-item { font-size: 12px; }
.meta-item .meta-label { color: var(--muted); }
.meta-item .meta-val   { color: var(--text); font-weight: 500; margin-top: 2px; }

.empty-state { text-align: center; padding: 64px 24px; color: var(--muted); animation: fadeInUp .4s ease both; }
.empty-state svg { width: 48px; height: 48px; fill: var(--border); margin: 0 auto 16px; display: block; }
.empty-state p { font-size: 15px; }

/* ============================================================================
   LOGIN PAGE
   ============================================================================ */

.login-body {
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 15% 55%, rgba(26,115,232,.13) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 10%, rgba(35,134,54,.09) 0%, transparent 50%),
        radial-gradient(ellipse at 55% 90%, rgba(26,115,232,.07) 0%, transparent 50%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-wrap {
    width: 100%;
    max-width: 420px;
    padding: 24px;
    animation: fadeInUp .5s ease both;
}

.brand { text-align: center; margin-bottom: 32px; }

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: rgba(26,115,232,.1);
    border: 1px solid rgba(26,115,232,.25);
    border-radius: 50px;
    padding: 8px 18px;
    margin-bottom: 20px;
    backdrop-filter: blur(6px);
}

.brand-badge svg  { width: 20px; height: 20px; fill: var(--accent); flex-shrink: 0; }
.brand-badge span { font-size: 13px; font-weight: 500; color: var(--accent); letter-spacing: .4px; }

.brand h1 { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.3; }
.brand p  { margin-top: 8px; font-size: 13px; color: var(--muted); }

.login-card {
    background: rgba(22, 27, 34, 0.82);
    border: 1px solid rgba(48, 54, 61, 0.75);
    border-radius: var(--radius-lg);
    padding: 28px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow:
        0 20px 56px rgba(0,0,0,.55),
        inset 0 1px 0 rgba(255,255,255,.05);
}

.login-card h2 { font-size: 17px; font-weight: 600; margin-bottom: 22px; color: var(--text); }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.link-action { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.link-action a { color: var(--accent); text-decoration: none; font-weight: 500; }
.link-action a:hover { text-decoration: underline; }

.footer-note { text-align: center; margin-top: 24px; font-size: 12px; color: var(--muted); }

/* ============================================================================
   MODAL (confirm delete)
   ============================================================================ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.68);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    backdrop-filter: blur(4px);
}

.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 380px;
    width: 90%;
    transform: scale(.94);
    transition: transform .22s cubic-bezier(.34,1.56,.64,1);
    box-shadow: 0 24px 60px rgba(0,0,0,.65);
}

.modal-backdrop.open .modal-box { transform: scale(1); }

.modal-box h3 { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
.modal-box p  { font-size: 13px; color: var(--muted); margin-bottom: 24px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    .topbar      { padding: 0 14px; height: 52px; }
    .topbar-right { gap: 8px; }
    .page        { padding: 24px 16px 48px; }
    .page-header { flex-direction: column; gap: 16px; }
    .metrics-grid { grid-template-columns: 1fr; }
    .info-grid   { grid-template-columns: repeat(2, 1fr); }
    .form-grid   { grid-template-columns: 1fr 1fr; }
    .form-grid.cols-4,
    .form-grid.cols-5 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .form-grid,
    .form-grid.cols-4,
    .form-grid.cols-5 { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column; }
}
