:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #182230;
    --muted: #667085;
    --line: #e5e9f0;
    --primary: #155eef;
    --primary-dark: #004eeb;
    --success: #087443;
    --success-bg: #ecfdf3;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --warning-bg: #fffaeb;
    --sidebar: #101828;
    --shadow: 0 8px 28px rgba(16, 24, 40, .07);
    --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar {
    height: 68px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), #7f56d9);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 18px;
}
.brand div { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); margin-top: 3px; }
.user-menu { display: flex; align-items: center; gap: 16px; }
.user-menu span { color: var(--muted); }

.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.sidebar {
    background: var(--sidebar);
    color: #fff;
    padding: 22px 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a {
    color: #d0d5dd;
    padding: 11px 12px;
    border-radius: 9px;
    font-weight: 600;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-footer { color: #98a2b3; font-size: 12px; padding: 12px; }
.content { padding: 28px; min-width: 0; }
.auth-content { width: min(460px, calc(100% - 32px)); margin: 64px auto; }
.page-heading { margin-bottom: 20px; }
.page-heading h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; }

.card, .auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}
.card h2, .auth-card h2 { margin: 0; font-size: 18px; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.card-title-row h2 { margin-bottom: 5px; }
.warning-card { border-color: #fedf89; background: #fffdf5; }
.success-card { text-align: center; padding: 40px 24px; }
.success-card h1 { margin-top: 0; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }

.cards-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: block; font-size: 24px; margin: 9px 0 5px; }

.flow-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.flow-grid > div { border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 6px; }
.flow-grid > div > span { width: 28px; height: 28px; border-radius: 50%; background: #eff4ff; color: var(--primary); display: grid; place-items: center; font-weight: 800; }
.flow-grid small { color: var(--muted); }
.flow-grid .disabled { opacity: .55; }

.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.one-column { grid-template-columns: 1fr; }
.form-grid label { display: grid; gap: 7px; font-weight: 600; }
.form-grid label small { color: var(--muted); font-weight: 400; }
.form-grid .full, .full { grid-column: 1 / -1; }
.form-section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section h2 { font-size: 16px; margin: 0; }
input, select, textarea {
    width: 100%;
    border: 1px solid #cfd6e1;
    border-radius: 9px;
    padding: 11px 12px;
    font: inherit;
    color: var(--text);
    background: #fff;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,94,239,.12); }
.checkbox-label { display: flex !important; align-items: center; gap: 9px !important; font-weight: 500 !important; }
.checkbox-label input { width: auto; }
.actions-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 10px 15px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: #344054; border-color: #d0d5dd; }
.btn-danger { background: var(--danger); color: #fff; }

.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; transition: opacity .4s; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #abefc6; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecdca; }
.alert-warning, .alert-info { background: var(--warning-bg); color: #93370d; border: 1px solid #fedf89; }
.alert-fade { opacity: .45; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td code { white-space: nowrap; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.status { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.status-ok { color: var(--success); background: var(--success-bg); }
.status-error { color: var(--danger); background: var(--danger-bg); }
details summary { color: var(--primary); cursor: pointer; font-weight: 600; }
details pre { max-width: 600px; max-height: 280px; overflow: auto; white-space: pre-wrap; word-break: break-word; background: #101828; color: #e4e7ec; padding: 12px; border-radius: 8px; font-size: 12px; }
.error-text { color: var(--danger); }
.filter-row { display: flex; align-items: end; gap: 12px; }
.filter-row label { min-width: 220px; display: grid; gap: 6px; font-weight: 600; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 18px; padding-top: 18px; }

.installer-body { background: linear-gradient(145deg, #eff4ff 0%, #f8f9fc 55%, #f4ebff 100%); min-height: 100vh; padding: 36px 16px; }
.installer-wrap { width: min(900px, 100%); margin: 0 auto; }
.installer-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.badge { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 7px 11px; font-weight: 700; color: var(--muted); }
.requirements { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 24px; }
.requirement { padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.requirement.ok { background: var(--success-bg); color: var(--success); }
.requirement.fail { background: var(--danger-bg); color: var(--danger); }

@media (max-width: 1050px) {
    .cards-grid, .flow-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .topbar { padding: 0 14px; }
    .user-menu span { display: none; }
    .layout { display: block; }
    .sidebar { padding: 9px; position: sticky; top: 68px; z-index: 15; }
    .sidebar nav { display: flex; overflow-x: auto; }
    .sidebar nav a { white-space: nowrap; }
    .sidebar-footer { display: none; }
    .content { padding: 18px 12px; }
    .cards-grid, .flow-grid, .form-grid { grid-template-columns: 1fr; }
    .card { padding: 17px; }
    .card-title-row { flex-direction: column; }
    .filter-row { align-items: stretch; flex-direction: column; }
    .filter-row label { min-width: 0; }
}

/* Pacote 2 — HSMs e Automações */
.compact-cards .metric-card strong { font-size: 22px; }
.accent-card { border-color: #b2ccff; background: #f5f8ff; }
.optional-label { color: var(--muted); font-size: 11px; font-weight: 500; }
.is-hidden { display: none !important; }
.status-muted { color: #475467; background: #f2f4f7; }
.table-spaced { margin-top: 18px; }
.table-subtitle { display: block; color: var(--muted); margin-top: 5px; }
.mini-count {
    display: inline-flex;
    margin: 2px 5px 2px 0;
    padding: 4px 7px;
    border-radius: 999px;
    background: #f2f4f7;
    color: #475467;
    font-size: 11px;
    white-space: nowrap;
}
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; min-width: 210px; }
.row-actions form { margin: 0; }
.link-button {
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    color: var(--primary);
    font: inherit;
    cursor: pointer;
    font-weight: 600;
}
.link-button:hover { text-decoration: underline; }
.danger-link { color: var(--danger); }
.hsm-filter-row { margin: 10px 0 2px; flex-wrap: wrap; }
.hsm-editor { padding-bottom: 72px; }
.switch-label {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    white-space: nowrap;
}
.switch-label input[type="checkbox"] { width: 18px; height: 18px; }
.timing-offset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.timing-offset-grid label { display: grid; gap: 7px; font-weight: 600; }
.dynamic-list { display: grid; gap: 14px; }
.dynamic-row {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fcfcfd;
    padding: 15px;
}
.dynamic-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.variable-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.rule-grid { grid-template-columns: 110px repeat(3, minmax(0, 1fr)); }
.variable-required { align-self: end; min-height: 43px; }
.empty-inline { color: var(--muted); text-align: center; padding: 18px 0 4px; }
.sticky-actions {
    position: sticky;
    bottom: 12px;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: rgba(255,255,255,.95);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}
.update-list { display: grid; gap: 12px; margin: 20px 0; }
.update-list > div {
    display: grid;
    gap: 4px;
    border-left: 3px solid var(--primary);
    padding: 10px 14px;
    background: #f8faff;
    border-radius: 0 9px 9px 0;
}
.update-list span { color: var(--muted); }
.info-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}
.info-strip > div { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.info-strip span, .info-strip strong { display: block; }
.info-strip span { color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.test-history { display: grid; gap: 12px; }
.history-item { border: 1px solid var(--line); border-radius: 11px; padding: 13px; }
.history-item > div:first-child { display: flex; flex-direction: column; gap: 4px; margin-bottom: 9px; }
.history-item small { color: var(--muted); }
.history-item .status { margin-bottom: 7px; }
.history-item details pre { max-width: 100%; }

@media (max-width: 1100px) {
    .variable-grid, .rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .variable-grid, .rule-grid, .info-strip, .timing-offset-grid { grid-template-columns: 1fr; }
    .row-actions { min-width: 0; }
    .sticky-actions { bottom: 8px; }
}

/* Pacote 3 — Sincronização da Clínica nas Nuvens */
.selection-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    max-height: 520px;
    overflow: auto;
    padding-right: 4px;
}
.selection-list {
    display: grid;
    gap: 9px;
    max-height: 430px;
    overflow: auto;
    padding-right: 4px;
}
.selection-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    background: #fff;
    cursor: pointer;
}
.selection-item:hover { border-color: #b2ccff; background: #f8faff; }
.selection-item input { width: auto; margin-top: 3px; }
.selection-item span { min-width: 0; }
.selection-item strong, .selection-item small { display: block; }
.selection-item small { color: var(--muted); margin-top: 4px; line-height: 1.35; }
.selection-inactive { opacity: .58; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    background: #f9fafb;
    border-radius: 999px;
    padding: 7px 10px;
    font-weight: 600;
}
.tag-pill small { color: var(--muted); font-weight: 500; }
.sync-form-row {
    display: grid;
    grid-template-columns: 210px 210px auto;
    align-items: end;
    gap: 12px;
}
.sync-form-row label, .appointment-filter-grid label {
    display: grid;
    gap: 6px;
    font-weight: 600;
}
.appointment-filter-grid {
    display: grid;
    grid-template-columns: 150px 150px minmax(190px, 1fr) minmax(150px, .7fr) minmax(230px, 1.2fr) auto;
    align-items: end;
    gap: 12px;
}
.filter-actions { min-height: 43px; }
button:disabled, .btn:disabled { opacity: .55; cursor: not-allowed; }

@media (max-width: 1200px) {
    .selection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .appointment-filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .selection-grid, .appointment-filter-grid, .sync-form-row { grid-template-columns: 1fr; }
}
