:root {
    --bg: #f3f5f8;
    --panel: #ffffff;
    --text: #172033;
    --muted: #687385;
    --border: #dfe4ea;
    --primary: #2457d6;
    --primary-dark: #183fa3;
    --danger: #b42318;
    --success: #087a42;
    --warning: #9a6700;
    --shadow: 0 12px 30px rgba(23, 32, 51, .10);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; font-family: "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.login-body { background: radial-gradient(circle at top, #e8eeff 0, #f3f5f8 42%, #edf0f4 100%); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 430px); background: var(--panel); border: 1px solid rgba(255,255,255,.75); border-radius: 22px; box-shadow: var(--shadow); padding: 36px; }
.login-icon { width: 72px; height: 72px; display: grid; place-items: center; background: #f0f3f8; border-radius: 18px; margin-bottom: 22px; }
.login-icon img { width: 56px; }
.login-card h1 { font-size: 27px; line-height: 1.15; margin: 4px 0 10px; }
.eyebrow { margin: 0 0 6px; color: var(--primary); font-weight: 800; font-size: 12px; letter-spacing: .11em; }
.muted, .page-heading p, .context-bar small { color: var(--muted); }

.topbar { height: 66px; background: #111827; color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 clamp(16px, 4vw, 48px); position: sticky; top: 0; z-index: 20; box-shadow: 0 5px 18px rgba(0,0,0,.16); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 900; background: var(--primary); }
.brand strong, .brand small { display: block; }
.brand small { color: #aab3c2; font-size: 11px; margin-top: 1px; }
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav a { padding: 9px 12px; border-radius: 9px; color: #dce2ec; font-size: 14px; }
.topnav a:hover { background: #263044; color: #fff; }

.page-shell { width: min(1180px, calc(100% - 32px)); margin: 34px auto 60px; }
.narrow-shell { width: min(860px, calc(100% - 32px)); }
.dashboard-shell { display: flex; flex-direction: column; align-items: center; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin: 2px 0 6px; font-size: clamp(25px, 3vw, 34px); }
.page-heading p { margin: 0; }

.btn { appearance: none; border: 1px solid transparent; border-radius: 10px; padding: 10px 15px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 7px; line-height: 1.1; }
.btn-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: #fff; border-color: var(--border); color: #344054; }
.btn-light:hover { background: #f6f7f9; }
.btn-danger-soft { color: var(--danger); background: #fff4f2; border-color: #fecdca; }
.btn-small { padding: 8px 11px; border-radius: 8px; font-size: 13px; }
.btn-block { width: 100%; }

.status-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 20px; }
.status-strip > div, .report-summary > div { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.status-strip span, .report-summary span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.status-strip strong, .report-summary strong { font-size: 17px; }

.company-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.company-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 14px rgba(23,32,51,.05); overflow: hidden; }
.company-main { min-height: 122px; padding: 20px; display: flex; align-items: center; gap: 15px; }
.company-main:hover { background: #fafbfc; }
.company-avatar { flex: 0 0 48px; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; color: #fff; background: var(--primary); font-size: 22px; font-weight: 800; }
.company-info { min-width: 0; flex: 1; }
.company-info strong, .company-info small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.company-info strong { font-size: 18px; margin-bottom: 6px; }
.company-info small { color: var(--muted); line-height: 1.5; }
.open-arrow { font-size: 31px; color: #98a2b3; }
.company-actions { border-top: 1px solid var(--border); background: #fafbfc; padding: 11px 14px; display: flex; justify-content: flex-end; gap: 8px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 14px rgba(23,32,51,.05); }
.form-panel { padding: 24px; }
.field-grid { display: grid; grid-template-columns: 1fr 180px; gap: 18px; }
.field-grid label, .form-stack label { display: block; }
.field-grid label > span:first-child, .form-stack label > span:first-child { display: block; font-weight: 700; font-size: 14px; margin-bottom: 7px; }
.field-wide { grid-column: 1 / -1; }
input, select { width: 100%; min-height: 42px; border: 1px solid #cfd6df; border-radius: 9px; padding: 9px 11px; color: var(--text); background: #fff; outline: none; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36,87,214,.13); }
label small { display: block; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.form-stack { display: grid; gap: 16px; margin-top: 24px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 45px; }
.password-toggle { position: absolute; right: 4px; top: 4px; bottom: 4px; width: 38px; border: 0; background: transparent; color: #667085; border-radius: 7px; }

.alert { border-radius: 11px; padding: 13px 15px; margin-bottom: 18px; line-height: 1.5; }
.alert ul { margin-bottom: 0; }
.alert-error { color: #912018; background: #fff1f0; border: 1px solid #fecdca; }
.alert-success { color: #05603a; background: #ecfdf3; border: 1px solid #abefc6; }
.alert-warning { color: #7a4d00; background: #fffaeb; border: 1px solid #fedf89; }
.flash-stack { position: fixed; top: 78px; right: 18px; z-index: 50; width: min(390px, calc(100% - 36px)); }
.flash { background: #fff; border-radius: 10px; box-shadow: var(--shadow); padding: 13px 15px; margin-bottom: 9px; border-left: 4px solid var(--primary); }
.flash-success { border-left-color: var(--success); }
.flash-error { border-left-color: var(--danger); }

.empty-state, .error-card { background: var(--panel); border: 1px dashed #cfd6df; border-radius: var(--radius); text-align: center; padding: 50px 24px; }
.empty-state img { width: 74px; opacity: .82; }
.empty-state h2, .error-card h1 { margin-bottom: 7px; }
.empty-state p, .error-card p { color: var(--muted); }
.compact-empty { padding: 34px 20px; }
.error-code { width: 60px; height: 60px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 32px; font-weight: 900; color: var(--danger); background: #fff1f0; }
.error-card .form-actions { justify-content: center; }

.context-bar { width: min(860px, 100%); display: flex; justify-content: space-between; align-items: center; gap: 20px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 13px 16px; margin-bottom: 22px; }
.context-bar span, .context-bar strong, .context-bar small { display: block; }
.context-bar span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.context-bar strong { margin: 2px 0; }
.context-actions { display: flex; gap: 8px; }

/* Réplica da janela Delphi original: 700 x 400 em telas grandes. */
.legacy-window { width: 700px; max-width: 100%; min-height: 400px; background: #f0f0f0; border: 1px solid #a8a8a8; box-shadow: 0 16px 36px rgba(0,0,0,.18); font-family: "Segoe UI", Arial, sans-serif; }
.legacy-title { min-height: 32px; padding: 7px 11px; background: linear-gradient(#fff, #e9e9e9); border-bottom: 1px solid #b9b9b9; color: #202020; font-size: 13px; }
.legacy-filter { height: 52px; display: flex; align-items: center; gap: 7px; padding: 0 16px; background: #f0f0f0; }
.legacy-filter strong { font-size: 13px; }
.legacy-filter input { width: 106px; min-height: 26px; height: 26px; border-radius: 1px; padding: 2px 5px; font-size: 13px; }
.legacy-note { margin-left: 14px; }
.advanced-filter { margin: 0 16px 8px; font-size: 12px; }
.advanced-filter summary { cursor: pointer; color: #555; }
.advanced-filter label { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.advanced-filter input { width: 110px; min-height: 28px; }
.legacy-content { min-height: 316px; display: grid; grid-template-columns: 192px 1fr; }
.legacy-image { display: grid; place-items: center; }
.legacy-image img { width: 96px; height: 96px; image-rendering: auto; }
.legacy-options { display: grid; grid-template-rows: repeat(5, 64px); align-content: start; padding-top: 12px; }
.legacy-option { display: grid; grid-template-columns: 240px 1fr; align-items: center; gap: 17px; }
.legacy-button { width: 240px; height: 46px; border: 1px solid #9d9d9d; background: linear-gradient(#fff, #e5e5e5); border-radius: 2px; color: #202020; font-weight: 700; font-size: 12px; box-shadow: inset 0 1px rgba(255,255,255,.8); }
.legacy-button:hover { background: linear-gradient(#fff, #dce9f7); border-color: #4d87c7; }
.legacy-button:active { background: #d6d6d6; }
.legacy-option span { color: #6d6d6d; font-size: 11px; line-height: 1.25; padding-right: 10px; }

.report-shell { width: min(1480px, calc(100% - 28px)); margin: 28px auto 50px; }
.report-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 20px; }
.report-toolbar-actions { display: flex; align-items: center; gap: 9px; }
.table-search { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.table-search input { width: 220px; min-height: 38px; }
.report-header { background: #fff; border: 1px solid var(--border); border-radius: 14px 14px 0 0; padding: 23px 25px; }
.report-header h1 { margin: 3px 0 6px; font-size: clamp(23px, 3vw, 32px); }
.report-header p:last-child { margin: 0; color: var(--muted); }
.report-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 12px 0; }
.table-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.table-scroll { overflow: auto; max-height: calc(100vh - 250px); }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data-table th { position: sticky; top: 0; z-index: 2; background: #eef2f6; color: #344054; white-space: nowrap; }
.data-table th, .data-table td { border-right: 1px solid #e5e9ef; border-bottom: 1px solid #e5e9ef; padding: 9px 10px; vertical-align: top; }
.data-table tbody tr:nth-child(even) td { background: #fafbfc; }
.data-table tbody tr:hover td { background: #f2f6ff; }
.data-table tfoot td { position: sticky; bottom: 0; background: #eaf0ff; font-weight: 800; }
.align-left { text-align: left; }
.align-center { text-align: center; }
.align-right { text-align: right; }
.table-filter-empty { text-align: center; color: var(--muted); padding: 22px; }
.report-footer { color: var(--muted); font-size: 12px; text-align: right; margin-top: 13px; }

.diagnostic-panel { padding: 20px; margin-bottom: 16px; }
.diagnostic-panel h2 { margin-top: 0; font-size: 18px; }
.diagnostic-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.diagnostic-row:last-child { border-bottom: 0; }
.status-ok { color: var(--success); }
.status-error { color: var(--danger); }

@media (max-width: 760px) {
    .topbar { height: auto; min-height: 62px; padding: 10px 14px; }
    .brand small { display: none; }
    .topnav { gap: 0; }
    .topnav a { padding: 8px; font-size: 12px; }
    .page-shell, .narrow-shell { width: min(100% - 20px, 1000px); margin-top: 20px; }
    .page-heading { flex-direction: column; }
    .page-heading .btn { width: 100%; }
    .status-strip { grid-template-columns: 1fr; }
    .company-grid { grid-template-columns: 1fr; }
    .company-actions { flex-wrap: wrap; }
    .field-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .form-panel { padding: 18px; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .context-bar { align-items: flex-start; }
    .context-actions { flex-direction: column; }

    .legacy-window { width: 100%; min-height: 0; }
    .legacy-title { font-size: 12px; }
    .legacy-filter { height: auto; min-height: 80px; display: grid; grid-template-columns: auto 1fr; padding: 12px; gap: 8px 10px; }
    .legacy-filter input { width: 100%; height: 36px; }
    .legacy-note { grid-column: 1 / -1; margin-left: 0; font-size: 11px !important; }
    .legacy-content { display: block; padding: 8px 12px 18px; }
    .legacy-image { height: 90px; }
    .legacy-image img { width: 74px; height: 74px; }
    .legacy-options { display: block; padding: 0; }
    .legacy-option { display: block; margin-bottom: 13px; }
    .legacy-button { width: 100%; height: 48px; }
    .legacy-option span { display: block; padding: 6px 4px 0; }

    .report-toolbar { align-items: stretch; flex-direction: column; }
    .report-toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .table-search { grid-column: 1 / -1; display: block; }
    .table-search input { width: 100%; margin-top: 5px; }
    .table-scroll { max-height: none; overflow: visible; }
    .data-table, .data-table thead, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table thead { display: none; }
    .data-table tr { border-bottom: 8px solid var(--bg); }
    .data-table td { display: grid; grid-template-columns: minmax(112px, 40%) 1fr; gap: 10px; text-align: right !important; border-right: 0; padding: 9px 12px; }
    .data-table td::before { content: attr(data-label); text-align: left; font-weight: 700; color: #475467; }
    .data-table tfoot { display: none; }
    .report-footer { text-align: center; }
}

@media print {
    @page { size: landscape; margin: 10mm; }
    body { background: #fff; }
    .no-print, .topbar, .flash-stack { display: none !important; }
    .report-shell { width: 100%; margin: 0; }
    .report-header { border: 0; padding: 0 0 12px; }
    .report-summary { break-inside: avoid; }
    .table-card { border: 0; overflow: visible; }
    .table-scroll { max-height: none; overflow: visible; }
    .data-table { font-size: 9px; }
    .data-table th { position: static; }
    .data-table tfoot td { position: static; }
    .data-table th, .data-table td { padding: 4px; }
}
