:root {
    --ink: #17211b;
    --muted: #657169;
    --paper: #f5f2ea;
    --panel: #fffdf8;
    --accent: #dc5a3d;
    --accent-hover: #c94e33;
    --line: #d8d3c8;
    --ok: #3d7b5c;
    --filter-bg: #f0ece2;
    --input-bg: #fffdf8;
    --card-bg: rgba(255, 255, 255, 0.45);
}

.dark-theme {
    --ink: #f2eee5;
    --muted: #b5b8b0;
    --paper: #171c19;
    --panel: #222923;
    --accent: #f07855;
    --accent-hover: #ff8968;
    --line: #3d463e;
    --ok: #76c49a;
    --filter-bg: #1d241f;
    --input-bg: #2a322c;
    --card-bg: rgba(255, 255, 255, 0.025);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-width: 0;
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: Georgia, "Times New Roman", serif;
}

button,
input,
select,
textarea {
    font-family: Arial, sans-serif;
}

button {
    cursor: pointer;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 28px;
    padding: 18px max(20px, calc((100% - 1040px) / 2));
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.topbar-actions form {
    margin: 0;
}

.brand {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    flex: 0 0 auto;
    line-height: 0.82;
    text-decoration: none;
    white-space: nowrap;
    font-size: 1.35rem;
    font-weight: 700;
}

.brand-passlock {
    color: var(--ink);
}

.brand-winner {
    color: var(--accent);
}

.theme-button {
    min-height: 40px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    padding: 9px 12px;
    font: 700 .78rem Arial, sans-serif;
    cursor: pointer;
}

.theme-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.link-button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 8px;
    font: .8rem Arial, sans-serif;
}

.link-button:hover {
    color: var(--accent);
    text-decoration: underline;
}

.shell {
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 52px 24px 64px;
}

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

.page-heading-copy {
    min-width: 0;
}

h1 {
    max-width: 720px;
    margin: 10px 0 18px;
    font-size: clamp(2.4rem, 6vw, 4.8rem);
    line-height: .95;
}

h2 {
    margin: 0 0 8px;
    font-size: 1.35rem;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font: 700 .75rem/1.2 Arial, sans-serif;
}

.muted {
    color: var(--muted);
    font: 1rem/1.5 Arial, sans-serif;
}

.primary,
.secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 12px 18px;
    border-radius: 4px;
    text-decoration: none;
    white-space: nowrap;
    font: 700 .9rem Arial, sans-serif;
}

.primary {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
}

.primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.heading-actions {
    display: flex;
    align-items: stretch;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    flex: 0 0 auto;
}

.secondary {
    gap: 8px;
    border: 1px solid var(--ink);
    background: var(--panel);
    color: var(--ink);
}

.secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--filter-bg);
}

.backup-button span {
    font-size: 1.1rem;
    line-height: 1;
}

.metrics {
    display: flex;
    gap: 16px;
    margin-bottom: 28px;
}

.metrics>div {
    min-width: 190px;
    padding: 20px 24px;
    background: var(--panel);
    border: 1px solid var(--line);
}

.metrics strong {
    display: block;
    font-size: 2rem;
}

.metrics span {
    color: var(--muted);
    font: .8rem Arial, sans-serif;
}

.metrics .warning strong {
    color: var(--accent);
}

.vault-table-panel {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
}

.table-filters {
    display: flex;
    gap: 18px;
    padding: 18px;
    background: var(--filter-bg);
}

.table-filters label {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 7px;
    color: var(--muted);
    font: 700 .75rem Arial, sans-serif;
}

.table-filters select {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    border: 1px solid var(--line);
    padding: 10px;
    background: var(--input-bg);
    color: var(--ink);
    font: .9rem Arial, sans-serif;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    padding: 22px 18px 18px;
}

.credentials-table {
    width: 100%;
    min-width: 780px;
    border-collapse: collapse;
    font: .88rem Arial, sans-serif;
}

.credentials-table th {
    padding: 15px 14px;
    background: var(--ink);
    color: var(--paper);
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .04em;
    white-space: nowrap;
}

.credentials-table td {
    padding: 18px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    vertical-align: middle;
}

.credentials-table td strong {
    color: var(--ink);
}

.password-cell {
    white-space: nowrap;
}

.secret-value {
    display: inline-block;
    min-width: 92px;
    color: var(--ink);
    font-family: monospace;
    letter-spacing: 1px;
}

.table-action {
    border: 0;
    background: transparent;
    color: var(--accent);
    padding: 5px 8px;
    font: 700 .78rem Arial, sans-serif;
}

.table-action:hover {
    text-decoration: underline;
}

.reveal-secret {
    min-width: 38px;
    min-height: 34px;
    padding: 5px 8px;
    font-size: 1rem;
    text-decoration: none !important;
}

.reveal-secret:hover {
    text-decoration: none !important;
}

.reveal-secret:disabled {
    opacity: .55;
    cursor: wait;
}

.actions-cell {
    white-space: nowrap;
}

.actions-cell form {
    display: inline;
    margin: 0;
}

.danger {
    color: var(--accent);
}

.badge {
    color: var(--ok);
    font: 700 .75rem Arial, sans-serif;
}

.badge.due {
    color: var(--accent);
}

.filter-empty {
    margin: 18px;
}

.credentials-table tbody tr:hover {
    background: var(--filter-bg);
}

.empty,
.auth-panel,
.form-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    padding: 36px;
}

.auth-panel,
.form-panel {
    max-width: 560px;
    margin: 0 auto;
}

.stack-form p {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin: 22px 0;
    font: 700 .85rem Arial, sans-serif;
}

.stack-form input,
.stack-form textarea,
.stack-form select {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    padding: 12px;
    background: var(--input-bg);
    color: var(--ink);
    font: 1rem Arial, sans-serif;
}

.stack-form ul.errorlist {
    color: var(--accent);
    font: .8rem Arial, sans-serif;
}

.actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 20px;
    margin-top: 24px;
    font: .9rem Arial, sans-serif;
}

.actions a {
    color: var(--muted);
}

.password-field-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.password-field-wrap input {
    width: 100%;
    padding-right: 48px;
}

.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 1.05rem;
}

.password-toggle:hover {
    background: var(--filter-bg);
    color: var(--accent);
}

/* Ocultar el botón nativo de mostrar contraseña de Edge */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
    display: none;
}

.qr-dialog {
    width: min(90vw, 430px);
    max-width: 430px;
    padding: 28px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
}

.qr-dialog::backdrop {
    background: rgba(0, 0, 0, .55);
}

.qr-dialog img {
    display: block;
    width: min(100%, 280px);
    height: auto;
    margin: 20px auto;
}

.dialog-close {
    float: right;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    padding: 7px 10px;
}

@media (max-width: 700px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
        padding: 16px 18px;
    }

    .brand {
        align-self: flex-start;
        font-size: 1.25rem;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-actions .theme-button {
        flex: 1 1 auto;
    }

    .topbar-actions form {
        flex: 1 1 auto;
    }

    .topbar-actions .link-button {
        width: 100%;
        min-height: 40px;
    }

    .shell {
        padding: 32px 14px 56px;
    }

    .page-heading {
        display: block;
        margin-bottom: 24px;
    }

    .page-heading h1 {
        margin: 8px 0 14px;
        font-size: clamp(2.45rem, 11vw, 3.5rem);
        line-height: .96;
        overflow-wrap: anywhere;
    }

    .page-heading .muted {
        margin-bottom: 20px;
        font-size: .96rem;
    }

    .heading-actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
        gap: 9px;
    }

    .heading-actions .primary,
    .heading-actions .secondary {
        width: 100%;
        min-height: 48px;
    }

    .metrics {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
        margin-bottom: 16px;
    }

    .metrics>div {
        min-width: 0;
        padding: 15px 12px;
    }

    .metrics strong {
        font-size: 1.9rem;
    }

    .metrics span {
        display: block;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .vault-table-panel {
        padding: 0;
        overflow: hidden;
    }

    .table-filters {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 16px;
    }

    .table-filters label {
        width: 100%;
    }

    .table-filters select {
        min-height: 46px;
    }

    .table-scroll {
        padding: 16px 14px 14px;
        overflow: visible;
    }

    .credentials-table {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        font-size: .9rem;
    }

    .credentials-table thead {
        display: none;
    }

    .credentials-table tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .credentials-table tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        width: 100%;
        min-width: 0;
        margin: 0 0 12px;
        padding: 15px;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: var(--card-bg);
        overflow: hidden;
    }

    .credentials-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .credentials-table tbody td {
        display: flex;
        align-items: center;
        width: 100%;
        min-width: 0;
        padding: 6px 0;
        border: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .credentials-table tbody td::before {
        display: none;
    }

    .credentials-table tbody td:nth-child(1) {
        padding-top: 0;
        color: var(--muted);
        font-size: .78rem;
        line-height: 1.3;
    }

    .credentials-table tbody td:nth-child(2) {
        padding-top: 2px;
        font-size: 1.15rem;
    }

    .credentials-table tbody td:nth-child(2) strong {
        display: block;
        width: 100%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .credentials-table tbody td:nth-child(3) {
        padding-bottom: 11px;
        color: var(--muted);
        font-size: .92rem;
    }

    .credentials-table tbody td.password-cell {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        padding: 11px 0;
        border-top: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
        overflow: hidden;
    }

    .secret-value {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        max-width: calc(100% - 48px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .password-cell .reveal-secret {
        flex: 0 0 40px;
        width: 40px;
        min-width: 40px;
        max-width: 40px;
        min-height: 38px;
        padding: 6px;
    }

    .credentials-table tbody td:nth-child(5) {
        padding-top: 12px;
    }

    .credentials-table tbody td.actions-cell {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 12px;
    }

    .actions-cell form {
        display: inline-flex;
    }

    .actions-cell .table-action {
        min-height: 36px;
        padding: 6px 10px;
        white-space: nowrap;
    }
}

@media (max-width: 380px) {
    .shell {
        padding-left: 10px;
        padding-right: 10px;
    }

    .topbar {
        padding-left: 14px;
        padding-right: 14px;
    }

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

    .topbar-actions form {
        grid-column: 1 / -1;
    }

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

    .page-heading h1 {
        font-size: 2.3rem;
    }

    .vault-table-panel {
        width: 100%;
    }

    .table-scroll {
        padding-left: 10px;
        padding-right: 10px;
    }

    .credentials-table tbody tr {
        padding: 13px;
    }
}

.mobile-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
    color: var(--accent);
    font: 600 0.95rem Arial, sans-serif;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.mobile-back-link:hover {
    color: var(--ink);
}

.dark-theme .mobile-back-link {
    color: #f4f0e7;
}

.dark-theme .mobile-back-link:hover {
    color: #ffffff;
}

.mobile-back-link,
.mobile-back-link:visited {
    color: var(--accent);
}

.mobile-back-link:hover,
.mobile-back-link:active {
    color: var(--ink);
}