:root {
    /* Colors - Dark Mode Default */
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --secondary-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --text-muted: #a0a0a0;
    --primary-color: #3b82f6; /* Blue */
    --primary-hover: #2563eb;
    --danger-color: #ef4444; /* Red */
    --border-color: #333333;
    --input-bg: #141414;

    /* Derived colors */
    --secondary-hover-bg: #3a3a3a;
    --secondary-border: #555;
    --alert-danger-text: #fca5a5;
    --alert-warn-text: #fcd34d;
    --overlay-subtle: rgba(255, 255, 255, 0.04);
    --hover-overlay: rgba(255, 255, 255, 0.05);
    --connector-bg: #252525;
    --connector-border: #3a3a3a;
    --spinner-track: rgba(255, 255, 255, 0.1);
    --checkbox-disabled-bg: #143f7a;
    --pre-bg: rgba(0, 0, 0, 0.2);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 2rem;

    /* Layout */
    --sidebar-width: 250px;
    --border-radius: 4px;
}

/* Light theme variables — applied by explicit data-theme or system preference fallback. */
:root[data-theme="light"] {
    --bg-color: #eef0f4;
    --card-bg: #ffffff;
    --secondary-bg: #dde0e6;
    --text-color: #1a1d24;
    --text-muted: #4b5563;
    --border-color: #c9cdd5;
    --input-bg: #fafbfc;

    --secondary-hover-bg: #c9cdd5;
    --secondary-border: #8b919d;
    --alert-danger-text: #dc2626;
    --alert-warn-text: #b45309;
    --overlay-subtle: rgba(0, 0, 0, 0.06);
    --hover-overlay: rgba(0, 0, 0, 0.07);
    --connector-bg: #f5f6f8;
    --connector-border: #b4b9c4;
    --spinner-track: rgba(0, 0, 0, 0.12);
    --checkbox-disabled-bg: #93c5fd;
    --pre-bg: rgba(0, 0, 0, 0.05);
}

/* System default: apply light colors when no explicit theme is set and OS prefers light. */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-color: #eef0f4;
        --card-bg: #ffffff;
        --secondary-bg: #dde0e6;
        --text-color: #1a1d24;
        --text-muted: #4b5563;
        --border-color: #c9cdd5;
        --input-bg: #fafbfc;

        --secondary-hover-bg: #c9cdd5;
        --secondary-border: #8b919d;
        --alert-danger-text: #dc2626;
        --alert-warn-text: #b45309;
        --overlay-subtle: rgba(0, 0, 0, 0.06);
        --hover-overlay: rgba(0, 0, 0, 0.07);
        --connector-bg: #f5f6f8;
        --connector-border: #b4b9c4;
        --spinner-track: rgba(0, 0, 0, 0.12);
        --checkbox-disabled-bg: #93c5fd;
        --pre-bg: rgba(0, 0, 0, 0.05);
    }
}

/* App loading indicator - shown while Blazor WASM initializes. */
.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
}

.app-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color, #333);
    border-top-color: var(--primary-color, #3b82f6);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.app-loading-text {
    color: var(--text-muted, #a0a0a0);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 0.9rem;
    margin: 0;
}

/* Reset & Base */
* { box-sizing: border-box; }

/*
 * Prevent pull-to-refresh on both Chrome (Android) and Safari (iOS).
 * Must be on html *and* body — browsers differ on which element they consult
 * for the viewport's overscroll behaviour.
 */
html {
    overscroll-behavior-y: none;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    overscroll-behavior-y: none;
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    margin-bottom: var(--spacing-md);
    font-weight: 600;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }

a {
    color: var(--primary-color);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

/* Grid & Layout System */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-md);
}

.grid {
    display: grid;
    gap: var(--spacing-md);
}

/* App Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--card-bg);
    border-right: 1px solid var(--border-color);
    padding: var(--spacing-md);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.sidebar nav {
    flex-grow: 1;
}

.sidebar-version {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

/* ── Theme Selector ──────────────────────────────────────────────── */

.theme-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: var(--spacing-sm) var(--spacing-md);
}

.theme-selector-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: inline;
    margin-bottom: 0;
}

.theme-selector-select {
    flex: 1;
    padding: 0.2rem 0.4rem;
    font-size: 0.85rem;
    margin-bottom: 0;
}

.main-content {
    flex-grow: 1;
    padding: var(--spacing-md);
    width: 100%;
}

/* Navigation */
.sidebar nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar nav li { margin-bottom: var(--spacing-sm); }
.sidebar nav a {
    display: block;
    padding: var(--spacing-sm);
    color: var(--text-muted);
    border-radius: var(--border-radius);
    transition: background-color 0.2s;
}
.sidebar nav span:not(.sidebar-badge) {
    display: block;
    padding: var(--spacing-sm);
    color: var(--text-muted);
    border-radius: var(--border-radius);
    opacity: 0.5;
}
.sidebar nav a:hover, .sidebar nav a.active {
    background-color: var(--bg-color);
    color: var(--primary-color);
    text-decoration: none;
}

/* Forms */
input[type="radio"] {
    vertical-align: middle;
    margin: 0;
    width: 0.95rem;
    height: 0.95rem;
}

/* Custom checkbox — native disabled+checked is invisible on some browsers */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 0.85rem;
    height: 0.85rem;
    border: 1.5px solid #888;
    border-radius: 2px;
    background: transparent;
    vertical-align: middle;
    margin: 0;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

input[type="checkbox"]:checked {
    background: #3b82f6;
    border-color: #3b82f6;
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    line-height: 1;
    color: #fff;
    content: '✓';
    font-weight: bold;
}

input[type="checkbox"]:disabled {
    cursor: not-allowed;
}

input[type="checkbox"]:disabled:checked {
    background: var(--checkbox-disabled-bg);
    border-color: var(--checkbox-disabled-bg);
}

input, select, textarea {
    display: block;
    width: 100%;
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Hide browser-native password reveal button. */
input::-ms-reveal,
input::-ms-clear {
    display: none;
}

.master-key-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.master-key-toggle:hover {
    color: var(--text-color);
    background: none;
}

.master-key-toggle:active {
    /* Prevent the global button:active translateY from displacing the absolutely-positioned toggle. */
    transform: translateY(-50%);
}

label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
    color: var(--text-muted);
}

/* Buttons */
button, .button, input[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    font-size: 1rem;
    line-height: 1.5;
}
button:hover, .button:hover { background-color: var(--primary-hover); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; pointer-events: none; }

/* Secondary Variant */
button.secondary, .button.secondary {
    background-color: var(--secondary-bg);
    border-color: var(--secondary-border);
    color: var(--text-color);
}
button.secondary:hover { background-color: var(--secondary-hover-bg); }

/* Small Variant */
button.small, .button.small {
    padding: var(--spacing-xs, 0.25rem) var(--spacing-sm);
    font-size: 0.85rem;
}

/* Danger Variant */
button.danger, .button.danger {
    background-color: var(--danger-color);
    color: white;
}

/* Icon-only Variant — sized to match text buttons (padding + line-height + border). */
.icon-button {
    width: calc(2.5rem + 2px);
    height: calc(2.5rem + 2px);
    padding: 0;
    line-height: 0;
    flex-shrink: 0;
}

/* Make icons white inside primary/danger buttons. */
.primary .themed-icon,
.danger .themed-icon,
:root[data-theme="light"] .primary .themed-icon,
:root[data-theme="light"] .danger .themed-icon {
    filter: brightness(0) invert(1);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}
.alert.danger {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--alert-danger-text);
}
.alert.warn, .alert.warning {
    background-color: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
    color: var(--alert-warn-text);
}

/* Text utilities */
.text-danger {
    color: var(--danger-color);
}
.text-success {
    color: #22c55e;
}
.text-muted {
    color: var(--text-muted);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--spacing-md);
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    overflow: hidden;
}
th, td {
    padding: var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
th { font-weight: 600; color: var(--text-muted); background-color: var(--overlay-subtle); }
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--hover-overlay); }

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.card-header {
    display: flex;
    flex-direction: column;
    background-color: var(--overlay-subtle);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.card-header.vault-header {
    flex-direction: row;
}

/* Mobile Toggle Bar */
.mobile-toggle-bar {
    display: none;
    align-items: center;
    padding: 0.3rem 1rem;
    background-color: var(--secondary-bg);
    border-bottom: 1px solid var(--border-color);
}

.hamburger-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
}

.close-sidebar-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 900;
}

.connector-card {
    border: 1px solid var(--connector-border);
    background-color: var(--connector-bg);
    padding: 1rem;
    margin: 0.3rem 0 1rem 0;
    border-radius: 8px;
}

.connector-settings {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.connector-settings .form-group {
    margin-bottom: 0;
}

.connector-settings .form-group input,
.connector-settings .form-group select,
.connector-settings .form-group textarea {
    margin-bottom: 0;
}

.form-description {
    display: block;
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 0.25rem;
    white-space: pre-line;
}

.form-error {
    display: block;
    font-size: 0.8em;
    color: var(--error, #e74c3c);
    margin-top: 0.25rem;
}

.input-error {
    border-color: var(--error, #e74c3c);
}

/* Vault item name with inline icon */
.vault-card {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 2rem);
    margin-bottom: 0;
    overflow: hidden;
}

.vault-scroll-area {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    min-height: 0;
}

.vault-item-name {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.legacy-indicator {
    cursor: help;
    margin-right: 4px;
}

.vault-icon-key {
    color: #f59e0b;
    flex-shrink: 0;
}

/* Vault display filter dropdown */
.vault-filter-select {
    display: inline-block;
    width: auto;
    margin-bottom: 0;
    padding: 0.35rem 0.5rem;
}

.vault-item-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.vault-item-action-btn {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── Page Layouts ────────────────────────────────────────────────── */

.page-centered {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    flex-direction: column;
}

.page-container {
    max-width: 800px;
    margin: 0 auto;
}

/* ── Legal Pages (Privacy Policy, Terms of Service) ─────────────── */

.legal-page {
    display: flex;
    justify-content: center;
    padding: var(--spacing-lg);
    min-height: 100vh;
    background: var(--bg-color);
    color: var(--text-color);
}

.legal-container {
    max-width: 720px;
    width: 100%;
}

.legal-container h1 {
    margin-bottom: var(--spacing-xs);
}

.legal-container h2 {
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--spacing-xs);
}

.legal-container p,
.legal-container ul {
    line-height: 1.7;
    color: var(--text-muted);
}

.legal-container ul {
    padding-left: 1.5rem;
}

.legal-container li {
    margin-bottom: var(--spacing-sm);
}

.legal-container a {
    color: var(--primary-color);
    text-decoration: none;
}

.legal-container a:hover {
    text-decoration: underline;
}

.legal-container code {
    background: var(--pre-bg);
    padding: 0.15rem 0.4rem;
    border-radius: var(--border-radius);
    font-size: 0.9em;
}

.legal-effective-date {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: var(--spacing-lg);
}

.legal-back {
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.card-body {
    padding: 1rem;
}

/* ── Headings ────────────────────────────────────────────────────── */

.heading-flush {
    margin: 0;
}

/* ── Section Dividers ────────────────────────────────────────────── */

.section-divider {
    margin: 1.5rem 0;
    border: 0;
    border-top: 1px solid var(--border-color);
}

.section-divider-dashed {
    border: 0;
    border-top: 1px dashed var(--border-color);
    margin: 0.5rem 0 1rem 0;
}

/* ── Buttons ─────────────────────────────────────────────────────── */

.button-row {
    display: flex;
    gap: 1rem;
}

.icon-btn {
    width: 2.5rem;
    height: 2.5rem;
    aspect-ratio: 1;
    padding: 0;
    flex-shrink: 0;
}

/* ── Forms ────────────────────────────────────────────────────────── */

.form-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
}

.ml-auto {
    margin-left: auto;
}

.form-actions-spread {
    justify-content: space-between;
    align-items: center;
}

.section-label {
    font-weight: 600;
    margin-bottom: 0;
}

.input-with-action {
    display: flex;
    gap: 0.5rem;
    align-items: start;
}

.input-with-action .input,
.input-with-action textarea.input {
    flex: 1;
    margin-bottom: 0;
    min-height: 2.5rem;
}

.input-with-action .button {
    padding: var(--spacing-md) var(--spacing-md);
}

/* ── Alerts ──────────────────────────────────────────────────────── */

.alert-inline {
    margin-top: 1rem;
}

.alert-inline-sm {
    margin-top: 0.5rem;
}

.alert-inline-warning {
    color: var(--warning-color, #e6a817);
    font-size: 0.85em;
}

.alphabet-warning {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.input-warning {
    border-color: var(--warning-color, #e6a817) !important;
}

.alert .button {
    margin-top: 0.5rem;
}

/* ── Text Alignment ──────────────────────────────────────────────── */

.vault-table th.text-right,
th.text-right,
td.text-right,
.text-right {
    text-align: right;
}

/* ── Grids ───────────────────────────────────────────────────────── */

.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.grid-3col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

/* ── Details / Summary ───────────────────────────────────────────── */

.static-key-advanced {
    margin-top: 0.6rem;
}

.details-summary {
    cursor: pointer;
    user-select: none;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.connector-card .details-summary {
    font-size: 0.9em;
    margin-bottom: 0.5rem;
}

/* ── Timestamps ──────────────────────────────────────────────────── */

.timestamp {
    font-size: 0.8rem;
}

/* ── Master Key Page ─────────────────────────────────────────────── */

.master-key-overlay {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    flex-direction: column;
    cursor: default;
}

.master-key-panel {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.master-key-panel h2 {
    margin-bottom: 2rem;
}

.master-key-panel .form-group {
    text-align: left;
}

.master-key-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.master-key-input-wrapper {
    position: relative;
    flex: 1;
}

.master-key-input {
    margin-bottom: 0;
    padding-right: 2.5rem;
}

.char-count {
    color: var(--text-muted);
    font-size: 0.9em;
    min-width: 1.5em;
    text-align: right;
}

.char-count-too-short {
    color: var(--danger-color, #dc3545);
}

.master-key-submit {
    width: 100%;
    margin-top: 1rem;
}

.master-key-warning {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-bottom: 1.5rem;
    line-height: 1.4;
}

.master-key-version {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    margin-top: 1.5rem;
    text-align: center;
}

.confirmation-match {
    border-color: var(--success-color, #28a745) !important;
    box-shadow: 0 0 0 1px var(--success-color, #28a745);
}

.confirmation-mismatch {
    border-color: var(--danger-color, #dc3545) !important;
    box-shadow: 0 0 0 1px var(--danger-color, #dc3545);
}

.master-key-confirm-details {
    margin-top: 0.25rem;
}

.master-key-confirm-toggle {
    all: unset;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9em;
    color: var(--text-muted);
    user-select: none;
    padding: 0.25rem 0.4rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: background-color 0.15s ease;
}

.master-key-confirm-toggle:hover {
    color: var(--text-color);
    background-color: rgba(0, 0, 0, 0.06);
}

.master-key-confirm-arrow {
    display: inline-block;
    font-size: 0.65em;
    transition: transform 0.15s ease;
}

.master-key-confirm-arrow.expanded {
    transform: rotate(90deg);
}

.master-key-confirm-details .form-group {
    margin-top: 0.5rem;
}

.diceware-hint {
    color: var(--text-muted);
    font-size: 0.82em;
    margin-top: 0.4rem;
    margin-bottom: 0;
    padding-left: 0.4rem;
}

.auto-protect-message {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.85em;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */

.mobile-title {
    font-weight: bold;
    margin-left: 1rem;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin-top: 5px;
}

/* ── Vault Page (loading / error states) ─────────────────────────── */

.loading-message {
    margin-top: 1rem;
    color: var(--text-muted);
}

.loading-cancel {
    margin-top: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
}

.loading-cancel:hover {
    color: var(--text-primary);
}

.vault-error {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    flex-direction: column;
    padding: 2rem;
    text-align: center;
}

.vault-error h3 {
    color: var(--danger-color);
}

.vault-error p {
    margin: 1rem 0;
}

/* ── Vault Table ─────────────────────────────────────────────────── */

.vault-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.vault-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
    margin-left: 1rem;
}

.vault-unload-btn {
    margin-left: 0.5rem;
}

.vault-search {
    margin: 0.25rem;
    flex-shrink: 0;
}

.vault-search-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.vault-search-input {
    flex: 1;
    margin-bottom: 0;
}

.vault-search-mode {
    width: auto;
    min-width: 7rem;
    margin-bottom: 0;
}

.vault-search .input {
    margin-bottom: 0;
}

/* Search highlighting */
.search-highlight {
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 2px;
}

/* Metadata match sub-panels */
.vault-metadata-matches {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    margin-top: 0.25rem;
    margin-left: 0.5rem;
}

.vault-metadata-tag {
    font-size: 0.8em;
    color: var(--text-muted);
    background: var(--tag-bg, rgba(128, 128, 128, 0.1));
    border-radius: 3px;
    padding: 0.1rem 0.4rem;
}

.vault-table {
    width: 100%;
    border-collapse: collapse;
}

.vault-table thead {
    display: none;
}

.vault-table th,
.vault-table td {
    padding: 0.75rem;
}

.vault-table th {
    text-align: left;
    border-bottom: 2px solid var(--border-color);
}

.vault-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}

/* Keep the name column flexible and the actions column pinned to its content width. */
.vault-table td:first-child {
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}

.vault-table th:last-child,
.vault-table td:last-child {
    width: 1%;
    white-space: nowrap;
}

.vault-actions-group {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
}

.vault-empty-row {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

/* ── Action Segments (clickable name parts: links & copy) ────────── */

.action-segment {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    cursor: pointer;
    border-radius: 3px;
    padding: 0.05rem 0.15rem;
    color: inherit;
    text-decoration: none;
    font: inherit;
    border: none;
    background: none;
}

.action-segment:hover {
    background-color: rgba(128, 128, 128, 0.12);
}

.action-segment-icon {
    flex-shrink: 0;
    opacity: 0.4;
}

.action-segment:hover .action-segment-icon {
    opacity: 0.8;
}

.action-segment-flash-success {
    background-color: transparent;
    animation: action-flash-success 100ms linear infinite alternate;
}

.action-segment-flash-error {
    background-color: transparent;
    animation: action-flash-error 100ms linear infinite alternate;
}

@keyframes action-flash-success {
    from { background-color: transparent; }
    to { background-color: rgba(34, 197, 94, 0.35); }
}

@keyframes action-flash-error {
    from { background-color: transparent; }
    to { background-color: rgba(239, 68, 68, 0.35); }
}

/* ── Settings Page ───────────────────────────────────────────────── */

.settings-alert {
    max-width: 800px;
    margin: 0 auto 1rem auto;
}

.connector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.connector-role-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge.active {
    background-color: var(--success-color, #28a745);
    color: #fff;
    padding: 0.2rem 0.6rem;
    border-radius: 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.connector-description {
    margin-top: 0;
}

.connector-test {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.test-result {
    margin-left: 1rem;
    white-space: pre-line;
}

.settings-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* ── Static Key Generator Page ───────────────────────────────────── */

.options-panel {
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 1rem;
    background-color: var(--connector-bg);
}

.result-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.result-input {
    font-family: monospace;
    font-size: 1.1em;
    letter-spacing: 0.05em;
    flex-grow: 1;
    margin-bottom: 0;
    min-height: 2.5rem;
}

.static-key-top-grid {
    grid-template-columns: 1fr;
}

/* ── SecretEditor ────────────────────────────────────────────────── */

.editor-column {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.symbol-input-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.symbol-input-group .input {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.symbol-reset-btn {
    flex-shrink: 0;
    padding: 0.35rem 0.5rem;
    line-height: normal;
}

.secret-textarea {
    flex: 1;
    font-family: monospace;
    resize: vertical;
    margin-bottom: 0;
    min-height: 2.5rem;
}

/* ── Label-style dropdown selector ───────────────────────────────── */

.label-select {
    appearance: auto;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.15rem 0.3rem;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    width: auto;
    margin-bottom: 0.25rem;
}

.label-select:hover,
.label-select:focus {
    border-color: var(--secondary-border);
    outline: none;
}

.secret-label-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.secret-byte-count {
    font-size: 0.8rem;
    white-space: nowrap;
}

.secret-header-row {
    grid-column: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.secret-plaintext-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.1rem 0.5rem;
    align-items: start;
}

.secret-plaintext-grid .secret-textarea {
    grid-column: 1;
    grid-row: 2;
    margin-bottom: 0;
    min-height: 2.5rem;
}

.secret-plaintext-grid > .button {
    grid-column: 2;
    grid-row: 2;
    padding: var(--spacing-md);
}

/* ── TOTP Display ────────────────────────────────────────────────── */

.totp-display {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.totp-code-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.totp-code {
    font-family: monospace;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--text-color);
}

.totp-timer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.totp-timer-bar {
    flex: 1;
    height: 6px;
    background-color: var(--secondary-bg);
    border-radius: 3px;
    overflow: hidden;
}

.totp-timer-fill {
    width: 100%;
    height: 100%;
    background-color: var(--primary-color);
    border-radius: 3px;
    transition: width 1s linear;
}

.totp-timer-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 2.5rem;
    text-align: right;
}

/* ── QR Code Display ─────────────────────────────────────────────── */

.qrcode-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0;
}

.qrcode-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    justify-content: center;
}

.qrcode-size-label {
    font-size: 0.85rem;
    line-height: 1;
    color: var(--text-muted);
    display: inline;
    margin-bottom: 0;
}

.qrcode-slider {
    flex: 0 1 60%;
    min-width: 80px;
    cursor: pointer;
    vertical-align: middle;
    padding: 0;
    margin-bottom: 0;
}

.qrcode-svg-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: 200px;
    aspect-ratio: 1;
}

.qrcode-svg-wrapper svg {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

/* ── MetadataEditor ──────────────────────────────────────────────── */

.metadata-editor {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.metadata-row {
    display: flex;
    gap: 0.5rem;
    align-items: start;
}

.metadata-key {
    flex: 1;
    margin-bottom: 0;
    min-height: 2.5rem;
}

.metadata-value {
    flex: 2;
    margin-bottom: 0;
    min-height: 2.5rem;
}

.metadata-add-btn {
    align-self: flex-start;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .options-panel {
        padding: 0.5rem;
    }

    .grid-2col {
        gap: 0.75rem;
    }

    .grid-2col .form-group label {
        font-size: smaller;
    }

    .static-key-advanced .grid-2col {
        display: flex;
        flex-wrap: wrap;
    }

    .static-key-advanced .grid-2col > * {
        flex: 0 0 calc(50% - 0.375rem);
    }

    .static-key-advanced .grid-2col > :nth-child(1) {
        flex-basis: calc(70% - 0.375rem);
    }

    .static-key-advanced .grid-2col > :nth-child(2) {
        flex-basis: calc(30% - 0.375rem);
    }

    .grid-3col {
        gap: 0.5rem;
    }

    .app-layout {
        flex-direction: column;
    }

    .mobile-toggle-bar {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);
        width: 85%;
        max-width: 300px;
        border-right: 1px solid var(--border-color);
    }

        .sidebar.open {
            transform: translateX(0);
        }

    .app-layout {
        height: 100vh;
        height: 100dvh;
    }

    .main-content {
        padding: 0;
        width: 100%;
        margin-top: 0;
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .page-container {
        flex: 1;
        min-height: 0;
        max-width: 100%;
        margin: 0;
        display: flex;
        flex-direction: column;
    }

    .card-body {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .vault-card {
        flex: 1;
        min-height: 0;
        height: auto;
    }

    .close-sidebar-btn {
        display: block;
    }

    /* Sidebar overlay is conditionally rendered via @if (sidebarOpen), so no display toggle needed. */

    .card-header.vault-header {
        padding: 0.25rem var(--spacing-sm);
    }

    .vault-header-actions {
        gap: 0.3rem;
        margin-left: 0.5rem;
    }

    .card-header {
        padding: var(--spacing-sm);
    }

    /* Scale the root font size — all rem-based sizes (nav, labels, badges, etc.) scale proportionally. */
    :root {
        font-size: 1.2rem;
    }

    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        min-height: 2.75rem;
        padding: 0.65rem var(--spacing-sm);
    }

    button, .button, select, input[type="submit"] {
        min-height: 2.75rem;
        padding: 0.65rem var(--spacing-md);
    }

    .symbol-input-group {
        align-items: stretch;
    }

    .symbol-reset-btn {
        min-height: auto;
        height: auto;
        padding: 0.45rem 0.65rem;
    }

    .icon-button,
    .icon-btn {
        width: 2.75rem;
        height: 2.75rem;
    }

    .vault-header-actions button,
    .vault-header-actions .button,
    .vault-header-actions select,
    .vault-header-actions .icon-button {
        min-height: 2.25rem;
        padding: 0.35rem 0.45rem;
    }

    .vault-header-actions .icon-button,
    .vault-header-actions .icon-btn {
        width: 2.25rem;
        height: 2.25rem;
    }

    .vault-header-actions .vault-item-count {
        font-size: 0.9rem;
    }

    .vault-search {
        margin-bottom: 0.5rem;
    }

    .vault-search-row {
        gap: 0.35rem;
    }

    .vault-search-row input:not([type="checkbox"]):not([type="radio"]),
    .vault-search-row select {
        min-height: 2.25rem;
        padding: 0.35rem 0.45rem;
    }

    .vault-item-action-btn {
        width: 2.25rem;
        height: 2.25rem;
        min-height: auto;
        padding: 0;
    }

    .vault-actions-group {
        flex-direction: column;
        gap: 0.25rem;
    }

    .vault-table th,
    .vault-table td {
        padding: 0.5rem 0.5rem;
    }

    .vault-table th:last-child,
    .vault-table td:last-child {
        white-space: normal;
        padding-left: 0.15rem;
        padding-right: 0.15rem;
    }

    .vault-table thead th:last-child {
        font-size: 0;
    }

    .vault-table thead th {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    .vault-filter-select {
        min-height: 2.75rem;
        padding: 0.65rem 0.5rem;
    }

    .grid-3col {
        display: flex;
        flex-wrap: wrap;
    }

    .grid-3col .form-group label {
        font-size: smaller;
    }

    .grid-3col > * {
        flex: 0 0 calc(50% - 0.25rem);
    }

    .grid-3col > :nth-child(3) {
        order: 1;
    }

    .grid-3col > :nth-child(4) {
        flex-basis: calc(35% - 0.25rem);
    }

    .grid-3col > :nth-child(5) {
        flex-basis: calc(65% - 0.25rem);
    }

    .grid-3col > :nth-child(6) {
        order: 2;
    }

    .card-body:has(.raw-vault-json) {
        display: flex;
        flex-direction: column;
        overflow-y: hidden;
    }

    .raw-vault-json {
        margin: 0;
        flex: 1;
        min-height: 0;
        max-height: none;
    }

    .form-actions {
        margin-top: 0.5rem;
    }

    .master-key-overlay {
        margin: 0 0.5rem;
    }

    .master-key-panel {
        font-size: 1.2em;
    }

    .master-key-panel h2 {
        font-size: 1.5rem;
    }

    .master-key-version {
        font-size: 1rem;
    }
}


/* Loading Spinner */
.loading-spinner {
    border: 4px solid var(--spinner-track);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

/* Themed icons — adapts gray icons for light/dark mode via CSS filter. */
.themed-icon {
    filter: none;
}

:root[data-theme="light"] .themed-icon {
    filter: brightness(0) saturate(100%) opacity(0.6);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) .themed-icon {
        filter: brightness(0) saturate(100%) opacity(0.6);
    }

    :root:not([data-theme]) .primary .themed-icon,
    :root:not([data-theme]) .danger .themed-icon {
        filter: brightness(0) invert(1);
    }
}

.loading-spinner-sm {
    border: 3px solid var(--spinner-track);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

.inline-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Blazor error UI - hidden by default, shown by the framework on unhandled exceptions. */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #333;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ── Raw Vault JSON ──────────────────────────────────────────────── */

.raw-vault-json {
    background: var(--pre-bg);
    border-radius: 6px;
    padding: 1rem;
    overflow: auto;
    max-height: 70vh;
    font-size: 0.85em;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.4;
}

/* ── Empty Page ──────────────────────────────────────────────────── */

.empty-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    text-align: center;
    color: var(--text-muted);
}

.empty-description {
    max-width: 400px;
    margin-top: 0.5rem;
    font-style: italic;
}

/* ── Error Log Page ──────────────────────────────────────────────── */

.error-log-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.error-log-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 0;
}

.error-log-entry {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color, #eee);
}

.error-log-entry-header {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.error-log-source {
    font-weight: 600;
}

.error-log-message {
    margin-top: 0.25rem;
    font-size: 0.9rem;
}

.error-log-details {
    margin-top: 0.4rem;
}

.error-log-details summary {
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: 0.15rem;
}

.error-log-details pre {
    font-size: 0.75rem;
    overflow-x: auto;
    max-height: 200px;
    background: var(--overlay-subtle, rgba(0, 0, 0, 0.06));
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0.5rem;
    border-radius: 0.25rem;
}

/* ── Sidebar Debug Section ────────────────────────────────────────── */

.sidebar-debug-section {
    margin-top: 0.25rem;
}

.sidebar nav .sidebar-debug-section ul {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 2rem;
}

.sidebar-debug-section li {
    margin-bottom: var(--spacing-sm);
}

.sidebar-debug-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: var(--spacing-sm);
    font-size: 0.85em;
    color: var(--text-muted);
    border-radius: var(--border-radius);
    transition: background-color 0.2s;
    list-style: none;
}

.sidebar-debug-toggle::marker,
.sidebar-debug-toggle::-webkit-details-marker {
    display: none;
}

.sidebar-debug-toggle:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Sidebar action — behaves like a nav link but triggers an action instead of navigating. */
.sidebar-action-link {
    all: unset;
    display: block;
    padding: var(--spacing-sm);
    color: var(--text-muted);
    background: none;
    border-radius: var(--border-radius);
    transition: background-color 0.2s;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
}

.sidebar-action-link:hover {
    background-color: var(--bg-color);
    color: var(--primary-color);
}

/* ── Sidebar Badge ───────────────────────────────────────────────── */

.sidebar-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.3rem;
    padding: 0 0.35rem;
    margin-left: 0.4rem;
    border-radius: 1rem;
    background: var(--danger, #dc3545);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    vertical-align: middle;
}

/* ── Toast Notifications ──────────────────────────────────────────── */

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    pointer-events: none;
}

.toast-message {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius, 6px);
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-size: 0.85rem;
    max-width: min(90vw, 28rem);
    white-space: pre-line;
    animation: toast-slide-in 0.25s ease-out;
}

.toast-message.toast-hiding {
    animation: toast-slide-out 0.25s ease-in forwards;
}

.toast-dismiss {
    all: unset;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
}

.toast-dismiss:hover {
    color: var(--text-color);
    background: var(--overlay-subtle);
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateY(0.5rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-slide-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(0.5rem);
    }
}

/* ─── Confirmation Modal ─── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: modal-fade-in 0.15s ease-out;
}

.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: modal-slide-in 0.15s ease-out;
}

.modal-header {
    padding: var(--spacing-md) var(--spacing-md) 0;
}

.modal-header h3 {
    margin: 0;
}

.modal-body {
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-color);
    line-height: 1.5;
}

.modal-body p {
    margin: 0 0 var(--spacing-sm);
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
}

.modal-action-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    text-align: left;
    padding: var(--spacing-sm) var(--spacing-md);
}

.modal-action-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.modal-action-label {
    font-weight: 600;
    font-size: 1.1rem;
}

.modal-action-desc {
    font-size: 0.85rem;
    opacity: 0.85;
    font-weight: normal;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-slide-in {
    from {
        opacity: 0;
        transform: translateY(-1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
