:root {
    --bg: #f6f7f8;
    --surface: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --ink: #111827;
    --sidebar: #1c1917;
    --topbar: 56px;
    --sidebar-width: 220px;
}

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

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}

.app-shell {
    min-height: 100vh;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--topbar);
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-brand,
.app-topbar-brand {
    color: inherit;
    font-weight: 700;
    text-decoration: none;
}

.app-topbar-brand {
    color: var(--text);
}

.app-menu-button {
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    padding: 16px 12px 24px;
    background: var(--sidebar);
    color: #fff;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    z-index: 40;
    overflow: auto;
}

.app-sidebar.is-open {
    transform: none;
}

.app-sidebar .app-brand {
    display: block;
    color: #fff;
    padding: 8px;
    margin-bottom: 8px;
    font-size: 1.15rem;
}

.app-nav-label {
    margin: 16px 8px 4px;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #a8a29e;
}

.app-sidebar a,
.app-sidebar button {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 0 8px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font: inherit;
    text-align: left;
    text-decoration: none;
}

.app-sidebar a.is-active {
    background: rgba(255, 255, 255, 0.12);
}

.app-sidebar form {
    margin: 0;
}

.app-backdrop {
    position: fixed;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 30;
}

.app-content {
    padding: 16px;
}

.app-content > main {
    max-width: 1100px;
}

.btn {
    border-radius: 8px;
}

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

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background: #000;
    border-color: #000;
}

.form-control,
.form-select {
    min-height: 44px;
    border-radius: 8px;
    border-color: var(--border);
    font-size: 16px;
}

.form-select-sm {
    min-height: 40px;
    font-size: 16px;
}

.mobile-full {
    width: 100%;
}

.dashboard-heading {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.dashboard-heading h1 {
    margin: 0 0 8px;
    font-size: 1.75rem;
}

.dashboard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.subscription-info {
    background: var(--surface);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
}

.badge-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
}

.badge-status.active {
    background: #dcfce7;
    color: #166534;
}

.badge-status.trial {
    background: #fef9c3;
    color: #854d0e;
}

.badge-status.expired,
.badge-status.canceled {
    background: #fee2e2;
    color: #991b1b;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.stat h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
}

.stat p {
    margin: 8px 0 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-cancelado {
    background: #fee2e2;
}

.dashboard-panels {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.dashboard-panel {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.dashboard-panel h2 {
    margin: 0 0 12px;
    font-size: 1rem;
}

.attention-list {
    display: grid;
    gap: 8px;
}

.attention-list a {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: inherit;
    font-weight: 600;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.attention-vehicle {
    color: var(--muted);
    font-weight: 500;
}

.finance-period {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 14px;
}

.finance-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    border-top: 1px solid var(--border);
}

.finance-line span,
.finance-line strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.dashboard-more {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-top: 4px;
    font-weight: 600;
    color: var(--ink);
}

.activity-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    row-gap: 2px;
    align-items: center;
    min-height: 44px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
}

.activity-number {
    grid-column: 1;
    grid-row: 1;
    font-weight: 700;
}

.activity-amount {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    font-weight: 700;
    text-align: right;
}

.activity-client {
    grid-column: 1 / -1;
    grid-row: 2;
    overflow-wrap: anywhere;
}

.activity-status {
    grid-column: 1 / -1;
    grid-row: 3;
    color: var(--muted);
    font-size: 14px;
}

.page-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
}

.page-head h1 {
    margin: 0;
    font-size: 1.5rem;
}

.list-tools {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.list-pager {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.data-table th {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.client-picker {
    position: relative;
}

.client-picker-control {
    position: relative;
}

.client-picker.is-selected .client-picker-control input {
    padding-right: 44px;
}

.client-picker-clear {
    position: absolute;
    top: 0;
    right: 0;
    width: 44px;
    height: 44px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
}

.client-picker-clear[hidden],
.client-picker-detail[hidden],
.client-picker-results[hidden] {
    display: none;
}

.client-picker-detail {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.client-picker-results {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: 100%;
    list-style: none;
    margin: 4px 0 0;
    padding: 4px 0;
    max-height: 240px;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.client-picker-results button {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    border: 0;
    background: transparent;
    text-align: left;
    font-size: 16px;
}

.client-picker-results button small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.client-picker-results button:hover,
.client-picker-results button:focus,
.client-picker-results button.is-active {
    background: #f3f4f6;
}

.client-picker-empty {
    padding: 10px 12px;
    color: var(--muted);
}

.row-actions,
.record-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.row-actions > form,
.record-actions > form {
    display: inline-flex;
    margin: 0;
}

.record-list {
    display: none;
}

.record {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.record-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.record-meta {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.record-value {
    margin: 8px 0 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.doc {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.doc p {
    margin: 0;
}

.doc-kicker,
.doc-block h2,
.doc-section {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.doc-section {
    margin-top: 8px;
}

.doc-strong {
    font-weight: 700;
}

.doc-company,
.doc-block p {
    color: var(--text);
}

.doc-company {
    margin-top: 16px;
}

.doc-grid {
    display: grid;
    gap: 16px;
    margin: 20px 0;
}

.doc-table {
    display: none;
    width: 100%;
    border-collapse: collapse;
}

.doc-table th,
.doc-table td {
    padding: 12px 8px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.doc-table th {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.doc-table td:not(:first-child),
.doc-table th:not(:first-child) {
    text-align: right;
    white-space: nowrap;
}

.doc-lines {
    display: grid;
}

.doc-line {
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.doc-line:first-child {
    border-top: 0;
    padding-top: 0;
}

.doc p.doc-total {
    margin-top: 16px;
    text-align: right;
    font-size: 1.25rem;
    font-weight: 700;
}

.doc-note {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.doc > .doc-block {
    margin-top: 16px;
}

.doc-status {
    margin-top: 8px;
}

.doc-status .form-select,
.list-status .form-select {
    width: 100%;
}

.list-status {
    margin: 0;
}

.public-page {
    min-height: 100vh;
    background: var(--bg);
}

.public-main {
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
    padding: 16px;
}

.public-main .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 16px;
    color: #fff;
    text-decoration: none;
    text-align: center;
}

.public-main .page-head .btn,
.public-main .row-actions .btn {
    width: 100%;
}

.record-primary,
.record-status {
    margin-top: 12px;
}

.promo-note {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.promo-note h2 {
    margin: 0 0 8px;
    font-size: 1.05rem;
}

.promo-note p,
.promo-note li {
    margin: 0 0 8px;
}

.promo-note ul {
    margin: 8px 0 12px;
    padding-left: 1.1rem;
}

.promo-note form {
    margin: 12px 0 0;
}

.promo-note.soon h2,
.promo-note .soon {
    color: #854d0e;
}

.stock-promo {
    margin: 0 0 16px;
    padding: 12px 0 0;
    border-top: 0;
}

.empty-note {
    margin: 0;
    color: var(--muted);
}

.section-title {
    margin: 8px 0 12px;
    font-size: 1.15rem;
}

.field-narrow {
    max-width: 16rem;
}

.form-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 8px;
}

.item-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
}

.item-table th,
.item-table td {
    padding: 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.item-table tr:last-child td {
    border-bottom: 0;
}

.item-table th {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.item-table .col-qty,
.item-table .col-price {
    width: 8.5rem;
}

.logo-preview {
    display: block;
    max-width: 100%;
    max-height: 120px;
    object-fit: contain;
    margin: 0 auto 12px;
}

.plan-grid {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.plan {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.plan.is-featured {
    border-color: var(--ink);
}

.plan h2 {
    margin: 0 0 4px;
    font-size: 1.15rem;
}

.plan-price {
    margin: 4px 0 12px;
    font-size: 1.75rem;
    font-weight: 700;
}

.plan .btn {
    width: 100%;
}

.guest {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.guest-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}

.guest-card h1 {
    margin: 0;
    font-size: 1.5rem;
    text-align: center;
}

.guest-lead {
    margin: 8px 0 16px;
    color: var(--muted);
    text-align: center;
}

.guest-card .btn-primary,
.guest-card .form-actions .btn {
    width: 100%;
}

.guest-links {
    margin: 16px 0 0;
    text-align: center;
}

.amount-trial {
    color: #854d0e;
}

.amount-in {
    color: #166534;
}

.amount-out {
    color: #991b1b;
}

.admin-kpis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-kpi {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    color: inherit;
    text-decoration: none;
}

.admin-kpi span,
.admin-meter-label span,
.admin-list p {
    color: var(--muted);
    font-size: 13px;
}

.admin-kpi strong {
    display: block;
    margin-top: 6px;
    color: var(--ink);
    font-size: 1.6rem;
    line-height: 1.1;
}

.admin-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.admin-panel h2 {
    margin: 0 0 12px;
    font-size: 1.05rem;
}

.admin-split {
    display: grid;
    gap: 16px;
}

.admin-meter {
    margin-top: 10px;
}

.admin-meter-label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.admin-meter-label strong {
    color: var(--text);
    font-size: 14px;
}

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

.admin-bar span {
    display: block;
    height: 100%;
    background: var(--ink);
    border-radius: 99px;
}

.admin-alerts {
    margin: 0;
    padding-left: 1.1rem;
}

.admin-alerts li + li {
    margin-top: 6px;
}

.admin-list article,
.admin-message-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.admin-list article {
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.admin-list article:first-child {
    border-top: 0;
    padding-top: 0;
}

.admin-list strong,
.admin-list p,
.admin-message-head p {
    margin: 0;
}

.admin-messages {
    display: grid;
    gap: 12px;
}

.admin-message-body {
    margin: 8px 0 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.admin-shell .data-table td {
    overflow-wrap: anywhere;
}

@media (min-width: 900px) {
    .app-shell {
        display: grid;
        grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    }

    .app-topbar,
    .app-menu-button,
    .app-backdrop {
        display: none;
    }

    .app-sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        width: auto;
        transform: none;
    }

    .app-content {
        padding: 32px;
    }

    .mobile-full {
        width: auto;
    }

    .dashboard-heading {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }

    .stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .dashboard-panels {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .dashboard-panel-wide {
        grid-column: 1 / -1;
    }

    .activity-row {
        grid-template-columns: 5rem minmax(0, 1fr) 10rem auto;
        padding: 10px 0;
    }

    .activity-number,
    .activity-client,
    .activity-status,
    .activity-amount {
        grid-row: 1;
        grid-column: auto;
    }

    .activity-status {
        font-size: inherit;
    }

    .activity-amount {
        justify-self: end;
    }

    .page-head {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .list-tools {
        grid-template-columns: minmax(0, 1fr) 220px;
        align-items: center;
    }

    .form-actions {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .plan-grid {
        grid-template-columns: 1fr 1fr;
    }

    .stats-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .admin-shell .page-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-shell .page-head p {
        margin: 0;
        max-width: 42rem;
    }

    .admin-kpis {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .admin-split {
        grid-template-columns: 1fr 1fr;
    }

    .doc {
        padding: 24px;
    }

    .doc-top,
    .doc-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
    }

    .doc-company {
        margin-top: 0;
        text-align: right;
    }

    .doc-lines {
        display: none;
    }

    .doc-table {
        display: table;
    }

    .doc-status .form-select {
        max-width: 220px;
    }

    .public-main {
        padding: 32px 24px;
    }

    .public-main .page-head .btn,
    .public-main .row-actions .btn {
        width: auto;
    }

    .data-table .list-status .form-select {
        width: auto;
        min-width: 160px;
    }
}

@media (max-width: 899px) {
    .btn {
        min-height: 44px;
    }

    .dashboard-actions {
        display: grid;
        gap: 8px;
    }

    .dashboard-actions .btn {
        width: 100%;
    }

    .page-head .btn,
    .page-head .row-actions form,
    .record-primary .btn,
    .promo-note .btn {
        width: 100%;
    }

    .data-table {
        display: none;
    }

    .record-list {
        display: grid;
        gap: 12px;
    }

    .field-narrow {
        max-width: none;
    }

    .form-actions .btn {
        width: 100%;
    }

    .item-table,
    .item-table tbody,
    .item-table tr,
    .item-table td {
        display: block;
        width: 100%;
    }

    .item-table {
        border: 0;
        background: transparent;
    }

    .item-table thead {
        display: none;
    }

    .item-table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 12px;
    }

    .item-table td {
        border: 0;
        padding: 0 0 8px;
    }

    .item-table td:last-child {
        padding-bottom: 0;
    }

    .item-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 4px;
        font-size: 13px;
        font-weight: 600;
        color: var(--muted);
    }

    .item-remove {
        width: 100%;
    }

    .record-actions .btn,
    .record-actions > form {
        flex: 1 1 calc(50% - 8px);
    }

    .record-actions > form .btn {
        width: 100%;
    }
}
