:root {
    --bg: #f5f5f2;
    --card: #ffffff;
    --ink: #171717;
    --muted: #6b7280;
    --line: #e5e7eb;
    --danger: #c81e1e;
    --danger-bg: #fee2e2;
    --success: #047857;
    --success-bg: #d1fae5;
    --brand: #111827;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
}
a { color: inherit; text-decoration: none; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
}
.brand { font-weight: 800; letter-spacing: -0.04em; font-size: 22px; }
.brand span { color: var(--muted); }
.nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.nav a, .logout-form button {
    border: 0;
    background: transparent;
    color: #374151;
    cursor: pointer;
    font: inherit;
    padding: 8px 0;
}
.logout-form { margin: 0; }
.container { width: min(1180px, calc(100% - 32px)); margin: 32px auto; }
.hero, .page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}
h1 { font-size: clamp(32px, 5vw, 56px); line-height: .94; letter-spacing: -0.06em; margin: 0 0 10px; }
h2 { margin: 0; letter-spacing: -0.03em; }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; color: var(--muted); font-size: 12px; font-weight: 700; margin: 0 0 10px; }
.muted { color: var(--muted); margin: 0; }
.btn {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 12px 18px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}
.btn.primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn.secondary { background: white; color: var(--ink); }
.btn.ghost { background: transparent; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: white; border: 1px solid var(--line); border-radius: 24px; padding: 20px; }
.stat span { color: var(--muted); display: block; margin-bottom: 8px; }
.stat strong { font-size: 34px; letter-spacing: -0.05em; }
.stat.danger strong { color: var(--danger); }
.stat.success strong { color: var(--success); }
.search-box {
    position: relative;
    display: flex;
    gap: 10px;
    margin: 20px 0 24px;
}
.search-box input, input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 15px;
    background: white;
    font: inherit;
    outline: none;
}
.search-box input:focus, input:focus, textarea:focus, select:focus { border-color: #111827; }
.autocomplete {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 120px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 20px 40px rgba(0,0,0,.08);
    overflow: hidden;
    z-index: 10;
}
.autocomplete a { display: block; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.autocomplete a:hover { background: #f9fafb; }
.hidden { display: none; }
.cards-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.devedor-card, .form-card, .profile-card, .history-card, .table-card, .auth-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: 0 12px 30px rgba(0,0,0,.035);
}
.card-link { display: flex; gap: 16px; padding: 16px; min-height: 152px; }
.avatar {
    width: 96px;
    height: 120px;
    border-radius: 18px;
    object-fit: cover;
    background: #eee;
}
.card-content { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.card-content h2 { font-size: 20px; }
.card-content p { color: var(--muted); margin: 0; }
.badge { width: fit-content; display: inline-flex; align-items: center; border-radius: 999px; padding: 7px 11px; font-size: 13px; font-weight: 800; }
.badge-danger { color: var(--danger); background: var(--danger-bg); }
.badge-success { color: var(--success); background: var(--success-bg); }
.form-card { padding: 24px; max-width: 760px; }
.form-card.compact { max-width: 420px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 800; margin-bottom: 7px; }
.field-error, .message.error { color: var(--danger); }
.messages { margin-bottom: 16px; }
.message { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.message.success { color: var(--success); }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.detail-layout { display: grid; grid-template-columns: 1fr 360px; gap: 18px; }
.profile-card { padding: 18px; display: grid; grid-template-columns: 280px 1fr; gap: 24px; }
.profile-photo { width: 100%; height: 360px; object-fit: cover; border-radius: 22px; background: #eee; }
.profile-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.data-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 20px 0; }
.data-list div { background: #f9fafb; border-radius: 18px; padding: 14px; }
dt { color: var(--muted); font-size: 13px; margin-bottom: 5px; }
dd { margin: 0; font-weight: 800; }
.notes { border-top: 1px solid var(--line); padding-top: 18px; }
.history-card { padding: 22px; height: fit-content; }
.history-item { border-top: 1px solid var(--line); padding: 14px 0; }
.history-item p { margin: 6px 0; color: #374151; }
.history-item small { color: var(--muted); }
.table-card { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th, td { text-align: left; padding: 15px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; }
.auth-card {
    max-width: 940px;
    margin: 8vh auto;
    padding: 32px;
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 32px;
    align-items: center;
}
.empty { grid-column: 1 / -1; background: white; border: 1px solid var(--line); border-radius: 20px; padding: 24px; color: var(--muted); }

@media (max-width: 900px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .hero, .page-head { align-items: flex-start; flex-direction: column; }
    .stats-grid, .cards-grid, .detail-layout, .profile-card, .auth-card { grid-template-columns: 1fr; }
    .profile-photo { height: 280px; }
    .data-list { grid-template-columns: 1fr; }
    .autocomplete { right: 0; }
}

@media (max-width: 560px) {
    .container { width: min(100% - 20px, 1180px); margin: 20px auto; }
    .nav { gap: 10px; }
    .search-box { flex-direction: column; }
    .card-link { flex-direction: column; }
    .avatar { width: 100%; height: 220px; }
    .form-card, .auth-card { padding: 18px; border-radius: 22px; }
}

/* Tags colaborativas */
.notif-link { position: relative; }
.notif-link strong {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px; margin-left: 4px;
    border-radius: 999px; background: #dc2626; color: white; font-size: 12px;
}
.filters-panel {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto auto;
    gap: 10px;
    margin: 20px 0 24px;
    align-items: center;
}
.inline-search { margin: 0; }
.mini-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mini-tag {
    border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 800;
    background: #eef2ff; color: #312e81; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mini-tag.more { background: #111827; color: white; }
.risk-glow {
    border-color: #7f1d1d !important;
    box-shadow: 0 0 0 2px rgba(220,38,38,.16), 0 18px 45px rgba(127,29,29,.22) !important;
}
.risk-note { color: #991b1b; font-weight: 900; }
.detail-layout.wide { grid-template-columns: 1fr 460px; }
.profile-card-full { min-height: 420px; }
.tag-panel { padding: 20px; }
.section-head { margin-bottom: 16px; }
.section-head h2 { margin-bottom: 6px; }
.tag-grid { display: grid; gap: 10px; }
.tag-card {
    border: 1px solid var(--line); border-radius: 18px; padding: 12px; background: #fff;
    display: flex; flex-direction: column; gap: 7px;
}
.tag-pill {
    width: fit-content; border-radius: 999px; padding: 8px 11px; font-weight: 900; font-size: 13px;
    display: inline-flex; gap: 6px; align-items: center;
}
.tag-card small { color: var(--muted); }
.tag-card p { margin: 0; color: #374151; font-size: 14px; }
.remove-tag-btn {
    border: 1px solid #fecaca; color: #b91c1c; background: #fff5f5;
    border-radius: 999px; padding: 8px 10px; cursor: pointer; font-weight: 800; width: fit-content;
}
.tag-add-form { display: grid; gap: 10px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.tag-add-form label { font-weight: 900; }
.form-feedback { min-height: 20px; margin: 0; font-size: 13px; color: var(--muted); }
.form-feedback.error { color: var(--danger); }
.form-feedback.success { color: var(--success); }
.custom-tag-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.custom-tag-box summary { cursor: pointer; font-weight: 900; }
.custom-tag-box form { display: grid; gap: 10px; margin-top: 12px; }
.color-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.color-row label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 800; }
.timeline-card {
    margin-top: 18px; padding: 22px; background: white; border: 1px solid var(--line); border-radius: 28px;
    box-shadow: 0 12px 30px rgba(0,0,0,.035);
}
.timeline-list { display: grid; gap: 10px; }
.timeline-item {
    display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 18px;
    background: #fff;
}
.timeline-item.tag { background: #f8fafc; }
.timeline-dot { width: 34px; height: 34px; border-radius: 50%; background: #f3f4f6; display: grid; place-items: center; }
.timeline-item p { margin: 4px 0; color: #374151; }
.timeline-item small { color: var(--muted); }
.notification-item {
    display: grid; gap: 5px; padding: 14px; border-bottom: 1px solid var(--line); border-radius: 14px;
}
.notification-item:hover { background: #f9fafb; }
.notification-item.unread { background: #fff7ed; border-left: 4px solid #f97316; }
.notification-item small { color: var(--muted); }

@media (max-width: 1100px) {
    .filters-panel { grid-template-columns: 1fr 1fr; }
    .detail-layout.wide { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
    .filters-panel { grid-template-columns: 1fr; }
    .color-row { grid-template-columns: 1fr; }
    .tag-panel { padding: 16px; }
}

/* Melhorias de status calculado, risco e auditoria */
.stats-grid-5 { grid-template-columns: repeat(5, 1fr); }
.stat.critical strong { color: #7f1d1d; }
.quick-filters {
    display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 18px;
}
.chip {
    border: 1px solid var(--line); background: #fff; border-radius: 999px;
    padding: 10px 14px; font-weight: 800; color: #374151;
}
.chip.active { background: #111827; color: #fff; border-color: #111827; }
.filters-panel-pro { grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto auto; }
.card-title-row { display: flex; align-items: flex-start; gap: 8px; justify-content: space-between; }
.recent-dot { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; border-radius: 999px; padding: 4px 7px; font-size: 11px; font-weight: 900; }
.recent-card { border-color: #fed7aa; }
.card-status-row { display: flex; gap: 6px; flex-wrap: wrap; }
.status-pill, .risk-pill {
    width: fit-content; display: inline-flex; align-items: center; border-radius: 999px;
    padding: 6px 9px; font-size: 12px; font-weight: 900;
}
.risk-pill.big { padding: 9px 12px; font-size: 13px; }
.status-pill.success, .status-text.success { background: #d1fae5; color: #047857; }
.status-pill.danger, .status-text.danger { background: #fee2e2; color: #991b1b; }
.status-pill.warning, .status-text.warning { background: #fef3c7; color: #92400e; }
.status-pill.neutral, .status-text.neutral { background: #f3f4f6; color: #374151; }
.risk-pill.low, .risk-text.low { background: #d1fae5; color: #047857; }
.risk-pill.medium, .risk-text.medium { background: #fef3c7; color: #92400e; }
.risk-pill.high, .risk-text.high { background: #ffedd5; color: #c2410c; }
.risk-pill.critical, .risk-text.critical { background: #fee2e2; color: #7f1d1d; }
.empty-tag { background: #f3f4f6; color: #6b7280; }
.summary-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0;
}
.summary-item { background: #f9fafb; border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.summary-item span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.summary-item strong { font-size: 18px; letter-spacing: -.03em; border-radius: 999px; padding: 6px 9px; display: inline-flex; width: fit-content; }
.creditors-box { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.audit-table td { vertical-align: top; }

@media (max-width: 1100px) {
    .stats-grid-5 { grid-template-columns: repeat(2, 1fr); }
    .filters-panel-pro { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
    .stats-grid-5, .filters-panel-pro, .summary-grid { grid-template-columns: 1fr; }
    .card-title-row { flex-direction: column; }
}
