:root {
    --ink: #25131a;
    --muted: #765060;
    --line: #f0bfd0;
    --paper: #ffffff;
    --soft: #fff7fa;
    --wine: #a30f3d;
    --wine-dark: #7f0b2f;
    --wine-bright: #c23c63;
    --wine-soft: #fff1f6;
    --blue: #1e63b6;
    --danger: #bb1636;
    --success: #0f7a4a;
    --shadow: 0 24px 70px rgba(127, 11, 47, 0.12);
    --codes-login-wine: #a30f3d;
    --codes-login-wine-dark: #7f0b2f;
    --codes-login-soft: #fff1f6;
    --codes-login-line: #f0bfd0;
    --codes-login-ink: #25131a;
    --codes-login-muted: #765060;
    --codes-login-shadow: 0 24px 70px rgba(127, 11, 47, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(255, 221, 227, 0.92), transparent 34%),
        linear-gradient(124deg, rgba(163, 15, 61, 0.11) 0 24%, transparent 24% 100%),
        linear-gradient(180deg, #fff8fb 0%, #fff 44%, #fff7fa 100%);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    overflow-x: hidden;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

.codes-topbar {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 12px clamp(18px, 5vw, 72px);
    background: linear-gradient(90deg, var(--wine-dark), var(--wine-bright));
    color: #fff;
    box-shadow: 0 14px 36px rgba(127, 11, 47, 0.16);
}

.codes-brand {
    display: inline-flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
}

.codes-brand img {
    width: 98px;
    height: auto;
    filter: brightness(0) invert(1) drop-shadow(0 8px 18px rgba(0, 0, 0, 0.16));
}

.codes-brand strong {
    color: #fff;
    font-size: 1.28rem;
    font-weight: 950;
}

.codes-nav {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.codes-nav a,
.codes-btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 14px;
    color: var(--wine);
    background: #fff;
    font-size: 0.9rem;
    font-weight: 900;
    text-decoration: none;
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, background 160ms ease, color 160ms ease;
}

.codes-nav a:hover,
.codes-nav a:focus-visible,
.codes-btn:hover,
.codes-btn:focus-visible {
    transform: translateY(-1px);
    border-color: var(--wine);
    box-shadow: 0 12px 22px rgba(127, 11, 47, 0.12);
    outline: 0;
}

.codes-btn-primary,
.codes-btn-save {
    border-color: var(--wine);
    color: #fff;
    background: linear-gradient(135deg, var(--wine), var(--wine-dark));
}

.codes-btn-danger {
    border-color: rgba(185, 28, 28, 0.2);
    color: var(--danger);
    background: #fff5f5;
}

.codes-btn-soft {
    color: var(--wine);
    background: var(--wine-soft);
}

.codes-btn-icon {
    width: 42px;
    min-width: 42px;
    padding: 0;
    color: #fff;
    background: var(--wine);
    border-color: var(--wine);
    font-size: 1.35rem;
    line-height: 1;
}

.codes-page {
    width: min(1760px, calc(100% - clamp(18px, 3vw, 56px)));
    margin: 0 auto;
    padding: 22px 0 46px;
    overflow-x: clip;
}

.codes-hero {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 12px;
}

.codes-hero h1 {
    margin: 0;
    color: var(--wine);
    font-size: clamp(2.2rem, 4.2vw, 4rem);
    line-height: 0.96;
    letter-spacing: 0;
}

.codes-kicker {
    display: block;
    color: var(--wine);
    font-size: 0.74rem;
    font-weight: 950;
    letter-spacing: 0;
    text-transform: uppercase;
}

.codes-stats {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.codes-stats span {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff;
    color: var(--muted);
    font-weight: 900;
}

.codes-stats strong {
    color: var(--wine);
    font-size: 1.28rem;
}

.codes-alert {
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    background: #fff;
    color: var(--ink);
    font-weight: 850;
}

.codes-alert.success {
    border-color: rgba(21, 128, 61, 0.28);
    color: var(--success);
    background: #f0fdf4;
}

.codes-alert.error {
    border-color: rgba(185, 28, 28, 0.28);
    color: var(--danger);
    background: #fff5f5;
}

.codes-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.codes-search {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}

.codes-search label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 950;
    text-transform: uppercase;
}

.codes-search input {
    width: min(340px, 78vw);
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--ink);
    background: #fff;
    outline: none;
}

.codes-search input:focus {
    border-color: var(--wine);
    box-shadow: 0 0 0 3px rgba(163, 15, 61, 0.12);
}

.codes-group-adder {
    display: inline-flex;
    align-items: end;
    gap: 8px;
}

.codes-group-adder input {
    width: 86px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fff;
    font-weight: 900;
    text-align: center;
    outline: none;
}

.codes-group-adder input:focus {
    border-color: var(--wine);
    box-shadow: 0 0 0 3px rgba(163, 15, 61, 0.12);
}

.codes-group-adder input.is-error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.codes-sheet-board {
    contain: layout paint;
    display: flex;
    align-items: start;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0 0 16px;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(163, 15, 61, 0.35) transparent;
}

.codes-sheet-board::-webkit-scrollbar,
.codes-sheet-scroll::-webkit-scrollbar {
    height: 11px;
}

.codes-sheet-board::-webkit-scrollbar-thumb,
.codes-sheet-scroll::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background: rgba(163, 15, 61, 0.34);
    background-clip: padding-box;
}

.codes-sheet-board::-webkit-scrollbar-track,
.codes-sheet-scroll::-webkit-scrollbar-track {
    background: rgba(255, 241, 246, 0.72);
}

.codes-sheet-panel {
    flex: 0 0 clamp(620px, 44vw, 760px);
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.93);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.codes-sheet-panel-other {
    flex-basis: clamp(620px, 44vw, 760px);
    width: auto;
}

.codes-add-panel {
    flex: 0 0 96px;
    min-height: 132px;
    display: grid;
    place-items: center;
    border-style: dashed;
    padding: 0;
    color: var(--wine);
    cursor: pointer;
}

.codes-add-panel span {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(163, 15, 61, 0.26);
    border-radius: 50%;
    background: #fff;
    font-size: 2rem;
    font-weight: 950;
    line-height: 1;
}

.codes-add-panel:hover,
.codes-add-panel:focus-visible {
    border-color: var(--wine);
    background: rgba(255, 241, 246, 0.9);
    outline: 0;
}

.codes-sheet-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--wine-soft);
}

.codes-sheet-title h2 {
    flex: 1 1 auto;
    margin: 0;
    color: var(--wine);
    font-size: 1.05rem;
    font-weight: 950;
}

.codes-sheet-title-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 0 0 auto;
}

.codes-sheet-title span {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 900;
}

.codes-btn-table-delete {
    min-height: 30px;
    padding: 5px 8px;
    border-color: rgba(185, 28, 28, 0.22);
    color: var(--danger);
    background: #fff5f5;
    font-size: 0.72rem;
}

.codes-sheet-scroll {
    overflow: auto;
}

.codes-sheet {
    min-width: 620px;
}

.codes-sheet-head,
.codes-row {
    display: grid;
    grid-template-columns: 38px minmax(300px, 1.7fr) 92px 88px 116px;
    align-items: stretch;
}

.codes-sheet-head {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 34px;
    background: linear-gradient(90deg, var(--wine-dark), var(--wine));
    color: #fff;
    font-size: 0.82rem;
    font-weight: 950;
    text-align: center;
}

.codes-sheet-head span,
.codes-row-number,
.codes-row label,
.codes-row-actions {
    min-height: 38px;
    border-right: 1px solid #f1d0d9;
    border-bottom: 1px solid #f1d0d9;
}

.codes-sheet-head span {
    display: grid;
    place-items: center;
}

.codes-row {
    margin: 0;
    background: #fff;
}

.codes-row:nth-of-type(even) {
    background: #fff7fa;
}

.codes-row.is-dirty {
    box-shadow: inset 3px 0 0 var(--blue);
}

.codes-row.is-saving {
    box-shadow: inset 3px 0 0 #f59e0b;
}

.codes-row.is-saved {
    box-shadow: inset 3px 0 0 rgba(21, 128, 61, 0.72);
}

.codes-row.is-error {
    box-shadow: inset 3px 0 0 var(--danger);
}

.codes-row.is-dragging {
    opacity: 0.54;
}

.codes-row.is-drop-before {
    box-shadow: inset 0 3px 0 var(--blue);
}

.codes-row.is-drop-after {
    box-shadow: inset 0 -3px 0 var(--blue);
}

.codes-row-new {
    background: #fff1f6;
}

.codes-row-number {
    display: grid;
    place-items: center;
    color: var(--wine);
    font-weight: 900;
    background: rgba(255, 241, 246, 0.76);
}

.codes-row-drag-handle {
    cursor: grab;
    user-select: none;
}

.codes-row-drag-handle:active {
    cursor: grabbing;
}

.codes-row label {
    display: grid;
    align-items: stretch;
}

.codes-row label span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.codes-row input,
.codes-row textarea {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    border: 2px solid transparent;
    padding: 5px 7px;
    color: var(--ink);
    background: transparent;
    outline: none;
    font-size: 0.9rem;
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
}

.codes-row textarea {
    height: auto;
    overflow: hidden;
    resize: none;
    line-height: 1.18;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.codes-row input[name="preco"] {
    text-transform: none;
}

.codes-row input:focus,
.codes-row textarea:focus {
    border-color: var(--wine);
    background: #fff;
    box-shadow: inset 0 0 0 1px rgba(163, 15, 61, 0.16);
}

.codes-row-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.5);
}

.codes-row-actions .codes-btn {
    min-height: 28px;
    padding: 5px 7px;
    font-size: 0.72rem;
}

.codes-save-status {
    min-width: 48px;
    color: var(--success);
    font-size: 0.66rem;
    font-weight: 950;
    text-align: center;
    text-transform: uppercase;
}

.codes-save-status.is-muted {
    color: var(--muted);
}

.codes-save-status.is-saving {
    color: #b45309;
}

.codes-save-status.is-saved {
    color: var(--success);
}

.codes-save-status.is-error {
    color: var(--danger);
}

.codes-empty {
    display: grid;
    place-items: center;
    min-height: 96px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-weight: 900;
}

.codes-dialog[hidden] {
    display: none !important;
}

.codes-dialog {
    position: fixed;
    z-index: 2000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.28);
    backdrop-filter: blur(4px);
}

.codes-dialog-card {
    width: min(430px, 100%);
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 22px;
    background: #fff;
    box-shadow: 0 30px 90px rgba(15, 23, 42, 0.22);
}

.codes-dialog-kicker {
    color: var(--danger);
    font-size: 0.74rem;
    font-weight: 950;
    text-transform: uppercase;
}

.codes-dialog-card h2,
.codes-dialog-card p {
    margin: 0;
}

.codes-dialog-card h2 {
    color: var(--ink);
    font-size: 1.35rem;
}

.codes-dialog-card p {
    color: var(--muted);
    line-height: 1.45;
}

.codes-dialog-card strong {
    width: fit-content;
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--wine-soft);
    color: var(--wine);
    font-weight: 950;
}

.codes-dialog-card label {
    display: grid;
    gap: 6px;
    color: var(--ink);
    font-weight: 900;
}

.codes-dialog-card input {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--ink);
    background: #fff;
    outline: none;
}

.codes-dialog-card input:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.codes-dialog-error {
    border: 1px solid rgba(185, 28, 28, 0.24);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--danger);
    background: #fff5f5;
    font-weight: 900;
}

.codes-dialog-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.codes-btn-danger-solid {
    border-color: var(--danger);
    color: #fff;
    background: var(--danger);
}

.codes-login-body {
    position: relative;
    isolation: isolate;
    min-height: 100vh;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 28px;
    color: var(--codes-login-ink);
    background:
        linear-gradient(124deg, rgba(163, 15, 61, 0.13) 0 24%, transparent 24% 100%),
        linear-gradient(180deg, #fff8fb 0%, #fff 44%, #fff7fa 100%);
}

.codes-login-body::before {
    content: "";
    position: absolute;
    z-index: 0;
    inset: 0;
    opacity: 0.32;
    pointer-events: none;
    background-image:
        linear-gradient(90deg, rgba(127, 11, 47, 0.08) 1px, transparent 1px),
        linear-gradient(180deg, rgba(163, 15, 61, 0.06) 1px, transparent 1px);
    background-size: 46px 46px;
    animation: codes-login-grid-drift 24s linear infinite;
}

.codes-login-card {
    position: relative;
    z-index: 2;
    width: min(520px, calc(100vw - 34px));
    min-height: 520px;
    border: 1px solid var(--codes-login-line);
    border-radius: 8px;
    padding: clamp(34px, 5vw, 58px);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--codes-login-shadow);
    animation: codes-login-card-in 380ms ease-out both;
}

.codes-login-logo {
    display: block;
    width: 158px;
    height: auto;
    margin: 0 auto 54px;
}

.codes-login-card h1 {
    margin: 12px 0 6px;
    color: var(--codes-login-wine);
    font-size: clamp(2.1rem, 6vw, 3.35rem);
    line-height: 0.98;
    letter-spacing: 0;
}

.codes-login-card p {
    margin: 0 0 22px;
    color: var(--codes-login-muted);
}

.codes-login-card .codes-kicker {
    color: var(--codes-login-wine);
    font-weight: 900;
}

.codes-login-form {
    display: grid;
    gap: 14px;
}

.codes-login-form label {
    display: grid;
    gap: 6px;
    color: #713246;
    font-weight: 900;
}

.codes-login-form input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--codes-login-line);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--codes-login-ink);
    background: #fff;
    outline: none;
}

.codes-login-form input:focus {
    border-color: var(--codes-login-wine);
    box-shadow: 0 0 0 3px rgba(163, 15, 61, 0.12);
}

.codes-login-card .codes-btn-primary {
    border-color: var(--codes-login-wine);
    color: #fff;
    background: linear-gradient(135deg, var(--codes-login-wine), var(--codes-login-wine-dark));
}

.codes-login-card .codes-alert.error {
    border-color: #ffc4d0;
    color: var(--danger);
    background: #fff3f6;
}

.login-screen-runner {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1;
    width: min(154px, 24vw);
    height: auto;
    pointer-events: none;
    filter: drop-shadow(0 18px 25px rgba(127, 11, 47, 0.18));
    transform: translate3d(var(--login-runner-x, 15vw), var(--login-runner-y, 60vh), 0) scaleX(var(--login-runner-dir, 1));
    will-change: transform;
}

@keyframes codes-login-grid-drift {
    from {
        background-position: 0 0, 0 0;
    }

    to {
        background-position: 46px 46px, -46px 46px;
    }
}

@keyframes codes-login-card-in {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1180px) {
    .codes-sheet-panel-other {
        width: auto;
    }
}

@media (max-width: 760px) {
    .codes-topbar,
    .codes-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .codes-page {
        width: calc(100% - 16px);
        margin: 0 auto;
        padding-top: 22px;
    }

    .codes-sheet-panel {
        flex-basis: calc(100vw - 22px);
    }

    .codes-add-panel {
        flex-basis: 82px;
    }

    .codes-dialog-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .codes-hero h1 {
        font-size: clamp(2.25rem, 14vw, 3.5rem);
    }

    .codes-sheet {
        min-width: 560px;
    }

    .codes-sheet-head,
    .codes-row {
        grid-template-columns: 36px minmax(230px, 1.4fr) 86px 82px 108px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
