html {
    font-size: calc(16px * var(--app-font-scale, 1));
}

:root {
    --app-font-scale: 1;
    --theme-font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;

    --theme-bg: #e7e2f1;
    --theme-bg-soft: #f3eff9;
    --theme-shell: #f8f5fc;
    --theme-surface: #ffffff;
    --theme-surface-soft: #f6f2fb;
    --theme-surface-muted: #faf8fd;
    --theme-surface-hover: #f3eefb;

    --theme-border: #ddd6ea;
    --theme-border-strong: #cbc2de;
    --theme-divider: #ebe4f3;

    --theme-text: #262033;
    --theme-text-soft: #665e79;
    --theme-text-muted: #857d96;

    --theme-primary: #5f43c9;
    --theme-primary-strong: #4b33a7;
    --theme-primary-soft: #efe8ff;
    --theme-primary-soft-border: #d8cbff;
    --theme-primary-ink: #2f2259;

    --theme-sidebar-bg: #0a0a0a;
    --theme-sidebar-bg-soft: #121212;
    --theme-sidebar-text: #bdbdbd;
    --theme-sidebar-text-strong: #ffffff;
    --theme-sidebar-muted: #666666;
    --theme-sidebar-footer: #777777;
    --theme-sidebar-border: #1f1f1f;
    --theme-sidebar-hover: rgba(255, 255, 255, 0.05);
    --theme-sidebar-active: rgba(255, 255, 255, 0.08);
    --theme-sidebar-icon-bg: rgba(255, 255, 255, 0.04);
    --theme-sidebar-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);

    --theme-success: #27835d;
    --theme-success-soft: #edf8f2;
    --theme-success-border: #c4e2d4;

    --theme-danger: #b34765;
    --theme-danger-soft: #fff2f5;
    --theme-danger-border: #f0cad4;

    --theme-warning: #c38a25;
    --theme-warning-soft: #fff5df;
    --theme-warning-border: #edd9ab;

    --theme-shadow-sm: 0 10px 22px rgba(33, 25, 54, 0.08);
    --theme-shadow-md: 0 18px 38px rgba(33, 25, 54, 0.12);
    --theme-focus: 0 0 0 3px rgba(95, 67, 201, 0.16);

    --theme-radius-sm: 8px;
    --theme-radius-md: 12px;
    --theme-radius-lg: 16px;
    --theme-control-height: 40px;
}

.theme-host {
    min-height: 100vh;
}

:root.theme-claro,
.theme-host.theme-claro {
    --theme-bg: #e7e2f1;
    --theme-bg-soft: #f3eff9;
    --theme-shell: #f8f5fc;
    --theme-surface: #ffffff;
    --theme-surface-soft: #f6f2fb;
    --theme-surface-muted: #faf8fd;
    --theme-surface-hover: #f3eefb;
    --theme-border: #ddd6ea;
    --theme-border-strong: #cbc2de;
    --theme-divider: #ebe4f3;
    --theme-text: #262033;
    --theme-text-soft: #665e79;
    --theme-text-muted: #857d96;
    --theme-primary: #5f43c9;
    --theme-primary-strong: #4b33a7;
    --theme-primary-soft: #efe8ff;
    --theme-primary-soft-border: #d8cbff;
    --theme-primary-ink: #2f2259;
    --theme-sidebar-bg: #0a0a0a;
    --theme-sidebar-bg-soft: #121212;
    --theme-sidebar-text: #bdbdbd;
    --theme-sidebar-text-strong: #ffffff;
    --theme-sidebar-muted: #666666;
    --theme-sidebar-footer: #777777;
    --theme-sidebar-border: #1f1f1f;
    --theme-sidebar-hover: rgba(255, 255, 255, 0.05);
    --theme-sidebar-active: rgba(255, 255, 255, 0.08);
    --theme-sidebar-icon-bg: rgba(255, 255, 255, 0.04);
    --theme-sidebar-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
}

:root.theme-escuro,
.theme-host.theme-escuro {
    --theme-bg: #111827;
    --theme-bg-soft: #1a2234;
    --theme-shell: #0f172a;
    --theme-surface: #172033;
    --theme-surface-soft: #1d2940;
    --theme-surface-muted: #22304a;
    --theme-surface-hover: #273650;
    --theme-border: #30415f;
    --theme-border-strong: #405272;
    --theme-divider: #2b3a54;
    --theme-text: #ecf2ff;
    --theme-text-soft: #c2cee7;
    --theme-text-muted: #96a5c6;
    --theme-primary: #60a5fa;
    --theme-primary-strong: #3b82f6;
    --theme-primary-soft: rgba(96, 165, 250, 0.16);
    --theme-primary-soft-border: rgba(147, 197, 253, 0.26);
    --theme-primary-ink: #eff6ff;
    --theme-sidebar-bg: #020617;
    --theme-sidebar-bg-soft: #08101f;
    --theme-sidebar-text: #97a6ba;
    --theme-sidebar-text-strong: #f8fbff;
    --theme-sidebar-muted: #5d708e;
    --theme-sidebar-footer: #7f91ac;
    --theme-sidebar-border: #162033;
    --theme-sidebar-hover: rgba(96, 165, 250, 0.12);
    --theme-sidebar-active: rgba(96, 165, 250, 0.16);
    --theme-sidebar-icon-bg: rgba(148, 163, 184, 0.08);
    --theme-sidebar-shadow: 0 24px 48px rgba(2, 6, 23, 0.5);
    --theme-success: #36c285;
    --theme-success-soft: rgba(54, 194, 133, 0.16);
    --theme-success-border: rgba(74, 222, 128, 0.22);
    --theme-danger: #fb7185;
    --theme-danger-soft: rgba(251, 113, 133, 0.14);
    --theme-danger-border: rgba(251, 113, 133, 0.22);
    --theme-warning: #fbbf24;
    --theme-warning-soft: rgba(251, 191, 36, 0.14);
    --theme-warning-border: rgba(251, 191, 36, 0.24);
    --theme-shadow-sm: 0 12px 22px rgba(2, 6, 23, 0.22);
    --theme-shadow-md: 0 18px 38px rgba(2, 6, 23, 0.34);
    --theme-focus: 0 0 0 3px rgba(96, 165, 250, 0.24);
}

html,
body {
    font-family: var(--theme-font-family);
    background:
        radial-gradient(circle at top right, rgba(111, 85, 215, 0.12), transparent 26%),
        linear-gradient(180deg, #f0ebf8 0%, var(--theme-bg) 100%);
    color: var(--theme-text);
}

.app-sidebar {
    background: linear-gradient(180deg, var(--theme-sidebar-bg-soft) 0%, var(--theme-sidebar-bg) 100%);
    border-right: 1px solid var(--theme-sidebar-border);
}

.theme-host.theme-escuro .app-main,
.theme-host.theme-escuro .app-content {
    background:
        radial-gradient(circle at top right, rgba(96, 165, 250, 0.08), transparent 24%),
        linear-gradient(180deg, #0f172a 0%, #111827 100%);
}

.theme-host.theme-claro .app-main,
.theme-host.theme-claro .app-content {
    background: transparent;
}

.app-main-frame {
    border-color: var(--theme-border);
    background: var(--theme-shell);
    box-shadow: var(--theme-shadow-md);
}

.page-card,
.metric-card,
.modal-shell {
    border-color: var(--theme-border);
    background: linear-gradient(180deg, var(--theme-surface) 0%, var(--theme-surface-muted) 100%);
}

.page-head h1,
.section-title,
.header-title,
.metric-value,
.os-status-item strong,
.os-table-title,
.modal-header h3 {
    color: var(--theme-primary-ink);
}

.page-head p,
.form-section-header p,
.toolbar-meta,
.metric-label,
.header-label,
.header-subtitle,
.modal-header p,
.os-created-note,
.autocomplete-meta,
.autocomplete-empty {
    color: var(--theme-text-soft);
}

.form-section-header,
.os-block-header,
.modal-header,
.modal-footer {
    border-color: var(--theme-divider);
}

.header-shell {
    padding: 14px 20px;
    background: linear-gradient(180deg, #fbf8ff 0%, #f2eef8 100%);
    border-bottom: 1px solid var(--theme-divider);
}

.header-logo {
    border-color: var(--theme-border-strong);
    background: linear-gradient(135deg, var(--theme-primary-ink) 0%, #4f3c92 100%);
}

.header-logo-wrap {
    position: relative;
}

.header-logo-button {
    padding: 0;
    border: 0;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.header-logo-button:hover {
    transform: translateY(-1px);
    box-shadow: var(--theme-shadow-sm);
}

.header-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-logo-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.header-logo-menu {
    position: absolute;
    top: calc(100% + 0.55rem);
    left: 0;
    min-width: 220px;
    display: grid;
    gap: 0.25rem;
    padding: 0.4rem;
    border-radius: 12px;
    border: 1px solid var(--theme-border);
    background: var(--theme-surface);
    box-shadow: var(--theme-shadow-md);
    z-index: 40;
}

.header-logo-menu__item {
    width: 100%;
    min-height: 40px;
    padding: 0.7rem 0.85rem;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--theme-text);
    text-align: left;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease;
}

.header-logo-menu__item:hover:not(:disabled) {
    background: var(--theme-primary-soft);
    color: var(--theme-primary-ink);
}

.header-logo-menu__item:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}

.header-logo-menu__item--label {
    display: flex;
    align-items: center;
}

.header-feedback {
    margin: 0 20px 16px;
    padding: 0.85rem 1rem;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 0.92rem;
}

.header-feedback--success {
    background: var(--theme-success-soft);
    border-color: var(--theme-success-border);
    color: #29573a;
}

.header-feedback--error {
    background: var(--theme-danger-soft);
    border-color: var(--theme-danger-border);
    color: #8f3050;
}

.header-button,
.primary-button,
.secondary-button,
.danger-button {
    min-height: var(--theme-control-height);
    border-radius: var(--theme-radius-sm);
    border: 1px solid transparent;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.header-button,
.primary-button {
    background: linear-gradient(180deg, var(--theme-primary) 0%, var(--theme-primary-strong) 100%);
    border-color: rgba(47, 34, 89, 0.18);
    color: #fff;
}

.secondary-button {
    background: var(--theme-primary-soft);
    border-color: var(--theme-primary-soft-border);
    color: var(--theme-primary-ink);
}

.danger-button {
    background: var(--theme-danger-soft);
    border-color: var(--theme-danger-border);
    color: #8f3050;
}

.header-button:hover,
.primary-button:hover,
.secondary-button:hover,
.danger-button:hover {
    box-shadow: var(--theme-shadow-sm);
}

.header-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.danger-button:focus-visible,
.sidebar-link:focus-visible,
.table-link:focus-visible,
.form-input:focus-visible {
    outline: none;
    box-shadow: var(--theme-focus);
}

.sidebar-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 16px;
    color: var(--theme-sidebar-text);
    background:
        radial-gradient(circle at top left, rgba(124, 58, 237, 0.08), transparent 20%),
        linear-gradient(180deg, #0a0a0a 0%, #121212 100%);
}

.sidebar-brand,
.sidebar-footer {
    border-color: var(--theme-sidebar-border);
}

.sidebar-top {
    margin-bottom: 18px;
}

.sidebar-brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    color: #fff;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        0 14px 28px rgba(79, 70, 229, 0.28);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 12px 18px;
    border-bottom: 1px solid var(--theme-sidebar-border);
}

.sidebar-brand-copy {
    display: grid;
    gap: 2px;
}

.sidebar-brand-title {
    color: var(--theme-sidebar-text-strong);
    font-size: 0.98rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sidebar-brand-subtitle,
.sidebar-meta-label,
.sidebar-group-title,
.sidebar-footer-text {
    color: var(--theme-sidebar-muted);
}

.sidebar-nav-groups {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 18px;
}

.sidebar-group {
    display: grid;
    gap: 8px;
}

.sidebar-group-title {
    padding: 0 10px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.sidebar-meta {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
}

.sidebar-link {
    min-height: 46px;
    padding: 0.55rem 0.7rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--theme-sidebar-text);
    background: transparent;
    border: 1px solid transparent;
    text-decoration: none;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.sidebar-link:hover {
    background: var(--theme-sidebar-hover);
    color: var(--theme-sidebar-text-strong);
    border-color: rgba(255, 255, 255, 0.04);
    transform: translateY(-1px);
}

.sidebar-link.active {
    background: var(--theme-sidebar-active);
    color: var(--theme-sidebar-text-strong);
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 12px 24px rgba(0, 0, 0, 0.18);
}

.sidebar-link-icon {
    flex: 0 0 auto;
    width: 36px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--theme-sidebar-icon-bg);
    border: 1px solid rgba(255, 255, 255, 0.04);
    color: #d7d7d7;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.sidebar-link-icon-svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.sidebar-link:hover .sidebar-link-icon,
.sidebar-link.active .sidebar-link-icon {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.08);
}

.sidebar-link.active .sidebar-link-icon {
    transform: scale(1.02);
}

.sidebar-link-button {
    width: 100%;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.sidebar-link > span:last-child {
    font-size: 0.94rem;
    font-weight: 500;
    line-height: 1.2;
}

.sidebar-footer {
    margin-top: 18px;
    padding: 14px 10px 4px;
    border-top: 1px solid var(--theme-sidebar-border);
}

.sidebar-footer-title {
    color: var(--theme-sidebar-text-strong);
    font-size: 0.86rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.sidebar-footer-text {
    color: var(--theme-sidebar-footer);
    font-size: 0.8rem;
    line-height: 1.5;
}

.form-label {
    color: var(--theme-text-soft);
}

.form-input {
    min-height: var(--theme-control-height);
    border-color: var(--theme-border-strong);
    border-radius: var(--theme-radius-sm);
    color: var(--theme-text);
}

.form-input:focus {
    border-color: var(--theme-primary);
    box-shadow: var(--theme-focus);
}

.selection-card,
.total-box,
.piece-total {
    background: var(--theme-surface-soft);
    border-color: var(--theme-border);
}

.feedback-success {
    background: var(--theme-success-soft);
    border-color: var(--theme-success-border);
    color: #29573a;
}

.feedback-error,
.form-error {
    background: var(--theme-danger-soft);
    border-color: var(--theme-danger-border);
    color: #8f3050;
}

.feedback-info,
.state-box {
    background: var(--theme-primary-soft);
    border-color: var(--theme-primary-soft-border);
    color: #5d507e;
}

.data-table {
    background: var(--theme-surface);
}

.data-table thead th {
    background: var(--theme-surface-soft);
    color: var(--theme-text-muted);
}

.data-table th,
.data-table td {
    border-bottom-color: var(--theme-divider);
}

.data-table tbody tr:hover {
    background: var(--theme-surface-hover);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    min-height: 30px;
    padding: 0.2rem 0.7rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.status-pill-paid {
    background: var(--theme-success-soft);
    border-color: var(--theme-success-border);
    color: #29573a;
}

.status-pill-open {
    background: var(--theme-danger-soft);
    border-color: var(--theme-danger-border);
    color: #8f3050;
}

.status-pill-cancelled {
    background: #ececf1;
    border-color: #d4d4dd;
    color: #4e4e58;
}

.payment-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.payment-toggle input {
    position: absolute;
    opacity: 0;
    inset: 0;
    cursor: pointer;
}

.payment-toggle span {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid var(--theme-border-strong);
    background: #fff;
    box-shadow: inset 0 1px 1px rgba(19, 14, 33, 0.06);
    transition: all 0.18s ease;
}

.payment-toggle input:checked + span {
    background: linear-gradient(180deg, var(--theme-success) 0%, #1f6a4b 100%);
    border-color: #1f6a4b;
}

.payment-toggle input:checked + span::after {
    content: "";
    display: block;
    width: 10px;
    height: 6px;
    margin: 5px 0 0 4px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg);
}

.payment-toggle input:disabled + span {
    opacity: 0.55;
    cursor: not-allowed;
}

.os-search-page .data-table tbody tr.order-row-paid {
    background: #e8f5e9;
}

.os-search-page .data-table tbody tr.order-row-open {
    background: #fdecea;
}

.os-search-page .data-table tbody tr.order-row-cancelled {
    background: #e0e0e0;
    color: #22242a;
}

.os-search-page .data-table tbody tr.order-row-paid:hover {
    background: #dff0e2;
}

.os-search-page .data-table tbody tr.order-row-open:hover {
    background: #f8dfdb;
}

.os-search-page .data-table tbody tr.order-row-cancelled:hover {
    background: #d8d8dc;
}

.table-link {
    color: var(--theme-primary);
}

.danger-link {
    color: var(--theme-danger);
}

.modal-backdrop {
    background: rgba(24, 18, 39, 0.52);
}

.os-page {
    --os-accent: var(--theme-primary);
    --os-accent-soft: var(--theme-primary-soft);
    --os-accent-soft-border: var(--theme-primary-soft-border);
    --os-accent-deep: var(--theme-primary-ink);
    --os-surface: #f8f5ff;
}

.os-page .page-card {
    border-color: #ddd3fb;
    background: linear-gradient(180deg, #ffffff 0%, #faf8ff 100%);
}

.os-page .os-status-strip {
    background: linear-gradient(180deg, #f8f5ff 0%, #f1ecff 100%);
    border-color: #ddd3fb;
}

.os-page .os-status-item {
    border-left-color: var(--theme-primary);
}

.os-page .os-panel-shell {
    border-color: #e0d8f5;
    background: linear-gradient(180deg, #fdfcff 0%, #f6f2ff 100%);
}

.os-page .data-table thead th {
    background: #f1ecff;
    color: #655c87;
}

.os-page .data-table td,
.os-page .data-table th {
    border-bottom-color: #ece5fa;
}

.os-page .piece-total {
    background: #f0ebff;
    border-color: #d6caff;
}

.os-page .totals-card {
    border-color: #ddd3fb;
    background: linear-gradient(180deg, #fbf9ff 0%, #f4f0ff 100%);
}

.os-page .total-box {
    border-color: #ddd3fb;
    background: rgba(255, 255, 255, 0.8);
}

.os-page .total-box-highlight {
    border-color: #b9a8f3;
    background: linear-gradient(180deg, #f3eeff 0%, #e7deff 100%);
}

.os-page .total-box-highlight .metric-label,
.os-page .total-box-highlight .metric-value {
    color: var(--theme-primary-ink);
}

@media (max-width: 960px) {
    .app-shell {
        background: var(--theme-bg);
    }
}
