:root {
    --brand-navy: #153f7a;
    --brand-blue: #087eae;
    --brand-cyan: #16a4b8;
    --brand-green: #63bd4f;

    --ink: #14233a;
    --ink-soft: #667587;
    --bg: #f4f7f8;
    --panel: #ffffff;
    --line: #dce4e8;
    --line-dark: #bcc8d0;
    --danger: #b83232;
    --success: #267749;

    --plastic: #e8b900;
    --paper: #1e6fd9;
    --glass: #1b8a4b;
    --organic: #8a5a2b;

    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 10px 30px rgba(16, 45, 75, .08);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    margin: 0;
    background:
        radial-gradient(circle at 85% 0%, rgba(22, 164, 184, .08), transparent 34rem),
        var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-user-select: none;
    user-select: none;
}

a {
    color: inherit;
}

.brand-strip {
    height: 5px;
    background: linear-gradient(90deg, var(--brand-navy), var(--brand-cyan), var(--brand-green));
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.site-header {
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 30;
}

.sticky-header {
    position: sticky;
    top: 0;
}

.header-inner {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.brand-link {
    display: inline-flex;
    align-items: center;
}

.brand-logo {
    display: block;
    width: 170px;
    max-height: 58px;
    object-fit: contain;
}

.header-action {
    color: var(--brand-navy);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 750;
    border: 1px solid var(--line-dark);
    border-radius: 999px;
    padding: 10px 15px;
    background: #fff;
}

.header-action:hover {
    border-color: var(--brand-blue);
}

.page {
    padding: 52px 0 64px;
}

.narrow-page,
.form-page {
    max-width: 860px;
}

.hero {
    margin-bottom: 30px;
}

.compact-hero {
    margin-bottom: 20px;
}

.kicker {
    margin: 0 0 6px;
    color: var(--brand-cyan);
    font-size: .76rem;
    font-weight: 850;
    letter-spacing: .16em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 10px;
    color: var(--brand-navy);
    font-size: clamp(2rem, 5vw, 3.6rem);
    line-height: .98;
    letter-spacing: -.04em;
}

h2 {
    color: var(--ink);
    line-height: 1.15;
}

.hero-copy,
.muted,
.machine-location {
    color: var(--ink-soft);
}

.hero-copy {
    margin-bottom: 0;
    max-width: 680px;
    font-size: 1.05rem;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.machine-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.machine-card {
    min-height: 210px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.machine-card:hover {
    transform: translateY(-3px);
    border-color: #b5d9df;
    box-shadow: 0 15px 40px rgba(16, 45, 75, .13);
}

.machine-card h2 {
    font-size: 1.5rem;
    margin: 10px 0 8px;
}

.machine-code {
    width: fit-content;
    color: var(--brand-navy);
    background: #eef5fb;
    border: 1px solid #d7e7f3;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: .75rem;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.machine-location {
    margin-bottom: 20px;
}

.machine-open {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--brand-blue);
    font-weight: 800;
}

.empty-state {
    text-align: center;
    padding: 42px 24px;
}

.empty-icon {
    width: 74px;
    height: 74px;
    margin: 0 auto 18px;
    display: grid;
    place-items: center;
    border-radius: 22px;
    background: #eaf5f5;
    color: var(--brand-cyan);
    font-weight: 900;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    padding: 10px 16px;
    border: 1px solid transparent;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button-primary {
    background: linear-gradient(135deg, var(--brand-navy), var(--brand-blue));
    color: #fff;
    box-shadow: 0 8px 20px rgba(21, 63, 122, .16);
}

.button-primary:hover {
    filter: brightness(1.04);
}

.button-secondary {
    background: #fff;
    border-color: var(--line-dark);
    color: var(--ink);
}

.button-danger-outline {
    background: #fff;
    border-color: #e8bcbc;
    color: var(--danger);
}

.button-full {
    width: 100%;
}

.page-heading-row {
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
}

.page-heading-row h1 {
    font-size: clamp(2rem, 4vw, 3rem);
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-machine {
    padding: 20px;
}

.settings-machine-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.settings-machine h2 {
    margin: 8px 0 5px;
}

.status-pill {
    border-radius: 999px;
    padding: 5px 9px;
    font-size: .75rem;
    font-weight: 850;
}

.status-active {
    color: var(--success);
    background: #e9f6ed;
}

.status-inactive {
    color: var(--ink-soft);
    background: #edf0f2;
}

.settings-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.settings-actions form {
    margin: 0;
}

.alert {
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    color: #1c633a;
    background: #eaf7ef;
    border-color: #ccebd8;
}

.alert-error {
    color: #8d2828;
    background: #fff0f0;
    border-color: #efcaca;
}

.machine-form {
    padding: 24px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.machine-form .field + .field {
    margin-top: 18px;
}

.field > span {
    color: var(--ink);
    font-size: .86rem;
    font-weight: 800;
}

.field input,
.field textarea,
.date-control input {
    width: 100%;
    border: 1px solid var(--line-dark);
    border-radius: 11px;
    background: #fff;
    color: var(--ink);
    padding: 11px 12px;
    outline: none;
}

.field textarea {
    resize: vertical;
    min-height: 82px;
}

.field input:focus,
.field textarea:focus,
.date-control input:focus {
    border-color: var(--brand-cyan);
    box-shadow: 0 0 0 3px rgba(22, 164, 184, .12);
}

.field small {
    color: var(--danger);
}

.toggle-field {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 20px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.toggle-field input {
    margin-top: 3px;
    accent-color: var(--brand-blue);
}

.toggle-field span {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toggle-field small {
    color: var(--ink-soft);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* Machine screen */
.machine-page {
    padding: 28px 0 54px;
}

.machine-title {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.machine-title h1 {
    display: inline;
    margin: 0;
    font-size: clamp(2rem, 5vw, 3rem);
}

.machine-title-line {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}

.machine-title-line strong {
    font-size: 1.3rem;
}

.machine-separator {
    color: #a5b0ba;
    font-size: 1.4rem;
}

.date-control {
    min-width: 170px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.date-control span {
    color: var(--ink-soft);
    font-size: .75rem;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.work-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.03fr) minmax(360px, .97fr);
    gap: 20px;
    align-items: start;
}

.entry-column,
.summary-column {
    min-width: 0;
}

.summary-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-dark {
    border-radius: var(--radius);
    background: #101a28;
    color: #fff;
    box-shadow: 0 13px 28px rgba(10, 25, 45, .16);
}

.readout {
    padding: 20px 22px;
}

.readout-top {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    color: #9eabb9;
    font-size: .72rem;
    font-weight: 850;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 7px;
    border-radius: 50%;
    background: #435163;
}

.status-dot.on {
    background: #71d059;
    box-shadow: 0 0 0 4px rgba(113, 208, 89, .12);
}

.weight-display {
    min-height: 92px;
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 10px;
}

.weight-display strong {
    font-variant-numeric: tabular-nums;
    font-size: clamp(3.9rem, 12vw, 5.8rem);
    line-height: 1;
    letter-spacing: -.055em;
}

.weight-display span {
    color: #9eabb9;
    font-size: 1.2rem;
    font-weight: 800;
}

.selected-fraction {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #bac4ce;
    font-size: .82rem;
    font-weight: 750;
}

.fraction-chip {
    width: 13px;
    height: 13px;
    border-radius: 4px;
    background: #435163;
}

.fraction-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 12px;
}

.fraction-button {
    min-height: 84px;
    padding: 15px;
    border: 0;
    border-radius: 14px;
    text-align: left;
    color: #fff;
    opacity: .62;
    filter: saturate(.7);
    cursor: pointer;
    transition: transform .1s ease, opacity .1s ease, filter .1s ease, box-shadow .1s ease;
}

.fraction-button span {
    display: block;
    font-size: 1.08rem;
    font-weight: 900;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.fraction-button small {
    display: block;
    margin-top: 4px;
    opacity: .88;
    font-size: .72rem;
    font-weight: 750;
}

.fraction-button.active {
    opacity: 1;
    filter: none;
    box-shadow: 0 0 0 3px var(--ink);
    transform: translateY(-1px);
}

.fraction-plastic {
    background: var(--plastic);
    color: #172132;
}

.fraction-paper {
    background: var(--paper);
}

.fraction-glass {
    background: var(--glass);
}

.fraction-organic {
    background: var(--organic);
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.key {
    min-height: 62px;
    border: 1px solid var(--line-dark);
    border-radius: 13px;
    background: #fff;
    color: var(--ink);
    font-size: 1.45rem;
    font-weight: 850;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 45, 75, .05);
}

.key:active {
    transform: translateY(1px);
    background: #eef3f5;
}

.key-alt {
    color: var(--brand-navy);
    font-size: .95rem;
}

.entry-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 16px;
    margin-top: 12px;
    box-shadow: none;
}

.entry-meta .field small {
    color: var(--ink-soft);
    text-align: right;
}

.register-button {
    width: 100%;
    min-height: 64px;
    margin-top: 12px;
    border: 0;
    border-radius: 15px;
    background: linear-gradient(135deg, var(--brand-navy), var(--brand-blue));
    color: #fff;
    font-size: 1.05rem;
    font-weight: 900;
    letter-spacing: .055em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 12px 26px rgba(21, 63, 122, .20);
}

.register-button:disabled {
    background: #c8d0d5;
    color: #7b8790;
    box-shadow: none;
    cursor: not-allowed;
}

.summary-card,
.log-card,
.report-card {
    padding: 20px;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.section-heading h2 {
    margin-bottom: 0;
    font-size: 1.23rem;
}

.compact-heading {
    margin-bottom: 14px;
}

.summary-total {
    text-align: right;
}

.summary-total strong {
    display: block;
    color: var(--brand-navy);
    font-size: 2rem;
    line-height: .95;
    font-variant-numeric: tabular-nums;
}

.summary-total span {
    color: var(--ink-soft);
    font-size: .75rem;
    font-weight: 800;
}

.stacked-bar {
    height: 14px;
    margin: 18px 0 10px;
    display: flex;
    overflow: hidden;
    border-radius: 999px;
    background: #e7ecef;
}

.stacked-bar span {
    display: block;
    height: 100%;
}

.fraction-summary-list {
    display: flex;
    flex-direction: column;
}

.fraction-summary-row {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    min-height: 42px;
    border-bottom: 1px solid var(--line);
}

.fraction-summary-row:last-child {
    border-bottom: 0;
}

.summary-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.summary-name {
    min-width: 0;
    font-weight: 700;
}

.summary-percent {
    min-width: 48px;
    color: var(--ink-soft);
    text-align: right;
    font-size: .82rem;
    font-variant-numeric: tabular-nums;
}

.summary-kg {
    min-width: 78px;
    text-align: right;
    font-weight: 850;
    font-variant-numeric: tabular-nums;
}

.summary-count {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 2px solid var(--ink);
}

.summary-count strong {
    color: var(--brand-navy);
    font-size: 1.2rem;
}

.record-log {
    max-height: 390px;
    overflow: auto;
    scrollbar-width: thin;
}

.record-row {
    display: grid;
    grid-template-columns: 52px 12px minmax(0, 1fr) auto 34px;
    gap: 8px;
    align-items: center;
    min-height: 50px;
    border-top: 1px solid var(--line);
}

.record-row:first-child {
    border-top: 0;
}

.record-time {
    color: var(--ink-soft);
    font-size: .78rem;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

.record-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.record-main {
    min-width: 0;
}

.record-main strong {
    display: block;
    font-size: .9rem;
}

.record-main small {
    display: block;
    overflow: hidden;
    color: var(--ink-soft);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.record-weight {
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.delete-record {
    width: 32px;
    height: 32px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 1.1rem;
}

.delete-record:hover {
    border-color: #e8bcbc;
    color: var(--danger);
}

.loading,
.no-records {
    padding: 22px 4px;
    color: var(--ink-soft);
    text-align: center;
}

.report-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 14px 0;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 90;
    max-width: calc(100vw - 32px);
    padding: 12px 18px;
    border-radius: 999px;
    background: #101a28;
    color: #fff;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(10, 25, 45, .25);
    transform: translate(-50%, 130%);
    opacity: 0;
    transition: transform .2s ease, opacity .2s ease;
    pointer-events: none;
}

.toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

.toast.error {
    background: #8e2f2f;
}

:focus-visible {
    outline: 3px solid rgba(22, 164, 184, .45);
    outline-offset: 2px;
}

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

    .work-layout {
        grid-template-columns: 1fr;
    }

    .summary-column {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .summary-card {
        grid-column: 1 / -1;
    }
}

@media (max-width: 640px) {
    .container {
        width: min(100% - 20px, 1180px);
    }

    .site-header .container {
        width: min(100% - 18px, 1180px);
    }

    .header-inner {
        min-height: 64px;
    }

    .brand-logo {
        width: 138px;
    }

    .header-action {
        padding: 8px 11px;
        font-size: .78rem;
    }

    .page {
        padding-top: 32px;
    }

    .machine-grid,
    .summary-column {
        grid-template-columns: 1fr;
    }

    .page-heading-row,
    .machine-title {
        align-items: stretch;
        flex-direction: column;
    }

    .page-heading-row .button {
        width: 100%;
    }

    .date-control {
        width: 100%;
    }

    .machine-page {
        padding-top: 18px;
    }

    .machine-title {
        margin-bottom: 14px;
        gap: 12px;
    }

    .machine-title-line strong {
        font-size: 1rem;
    }

    .readout {
        padding: 17px 16px;
    }

    .weight-display {
        min-height: 82px;
    }

    .weight-display strong {
        font-size: 4rem;
    }

    .fraction-button {
        min-height: 78px;
        padding: 13px;
    }

    .key {
        min-height: 58px;
    }

    .entry-meta,
    .report-dates {
        grid-template-columns: 1fr;
    }

    .record-log {
        max-height: none;
    }

    .summary-column {
        display: flex;
    }

    .settings-machine-main {
        flex-direction: column;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

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

@media (max-width: 380px) {
    .brand-logo {
        width: 122px;
    }

    .header-action {
        max-width: 132px;
        text-align: center;
    }

    .fraction-grid {
        gap: 7px;
    }

    .fraction-button span {
        font-size: .94rem;
    }

    .weight-display strong {
        font-size: 3.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}

/* ---------- seguridad / sesión ---------- */
.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.logout-form {
    margin: 0;
}

.header-action-button {
    cursor: pointer;
    font: inherit;
}

.login-body {
    min-height: 100vh;
}

.login-shell {
    min-height: calc(100vh - 5px);
    display: grid;
    place-items: center;
    padding: 28px 16px;
}

.login-card {
    width: min(460px, 100%);
    padding: clamp(24px, 6vw, 38px);
}

.login-brand {
    margin-bottom: 28px;
}

.login-logo {
    display: block;
    width: min(220px, 72%);
    max-height: 80px;
    object-fit: contain;
}

.login-copy h1,
.error-card h1 {
    margin-bottom: 12px;
    font-size: clamp(2rem, 8vw, 3rem);
}

.login-copy .muted {
    margin-bottom: 22px;
}

.login-form {
    display: grid;
    gap: 16px;
    margin-top: 18px;
}

.login-submit {
    margin-top: 2px;
}

.login-note {
    margin: 20px 0 0;
    color: var(--ink-soft);
    text-align: center;
    font-size: .78rem;
}

.error-card {
    text-align: left;
}

.error-card .login-logo {
    margin-bottom: 28px;
}

@media (max-width: 640px) {
    .header-actions {
        gap: 5px;
    }

    .header-actions .header-action {
        padding: 8px 9px;
        font-size: .72rem;
    }

    .login-shell {
        place-items: start center;
        padding-top: 34px;
    }

    .login-card {
        padding: 24px 20px;
    }
}

@media (max-width: 430px) {
    .header-inner {
        gap: 8px;
    }

    .header-actions .header-action {
        max-width: 108px;
        line-height: 1.15;
    }
}
