/*
 * QR Code Scanner
 *
 * Deliberately does NOT redefine :root. The other tool plugins each paste a
 * copy of the dark palette into :root, which fights the theme's light mode and
 * means a palette change has to be made in nine places. This one reads the
 * theme's variables and only supplies fallbacks, so light and dark both work
 * with no extra rules.
 */

.qrscan {
    --qrs-card: var(--dark-gray, #1a1a1a);
    --qrs-text: var(--light, #f5f5f5);
    --qrs-accent: var(--primary, #00ff88);
    --qrs-link: var(--secondary, #0099ff);
    --qrs-border: rgba(128, 128, 128, 0.28);
    --qrs-inset: rgba(128, 128, 128, 0.12);
    --qrs-warn: #ffb020;
    --qrs-danger: #ff5252;
    --qrs-ok: #4caf50;

    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding-top: 20px;
    color: var(--qrs-text);
}

.qrscan .generator-card {
    background: var(--qrs-card);
    border: 1px solid var(--qrs-border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    margin-bottom: 30px;
}

.qrscan h3 {
    color: var(--qrs-text);
    margin: 0 0 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.qrscan h3 i { color: var(--qrs-accent); }

.qrscan .lead {
    opacity: 0.7;
    font-size: 0.9rem;
    margin-bottom: 22px;
}

/* ---------------------------------------------------------------- tabs */

.qrs-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.qrs-tab {
    flex: 1 1 140px;
    padding: 12px 18px;
    border-radius: 12px;
    border: 1px solid var(--qrs-border);
    background: var(--qrs-inset);
    color: var(--qrs-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
}

.qrs-tab:hover { border-color: var(--qrs-accent); }

.qrs-tab.active {
    background: var(--qrs-accent);
    border-color: var(--qrs-accent);
    color: #0a0a0a;
}

.qrs-panel { display: none; }
.qrs-panel.active { display: block; }

/* --------------------------------------------------------------- camera */

.qrs-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 420px;
    border-radius: 15px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--qrs-border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.qrs-stage video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.qrs-stage.live video { display: block; }
.qrs-stage.live .qrs-stage-idle { display: none; }
.qrs-stage.live .qrs-reticle { display: block; }

.qrs-stage-idle {
    text-align: center;
    padding: 24px;
    opacity: 0.65;
}

.qrs-stage-idle i {
    font-size: 2.4rem;
    color: var(--qrs-accent);
    margin-bottom: 12px;
    display: block;
}

.qrs-stage-idle p { margin: 0; font-size: 0.95rem; }

/* Four corner brackets marking where to hold the code. */
.qrs-reticle {
    display: none;
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(62%, 260px);
    aspect-ratio: 1;
    pointer-events: none;
}

.qrs-reticle span {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--qrs-accent);
}

.qrs-reticle span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.qrs-reticle span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.qrs-reticle span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.qrs-reticle span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

.qrs-stage.hit .qrs-reticle span { border-color: var(--qrs-ok); }

.qrs-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.qrs-select {
    flex: 1 1 180px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--qrs-border);
    background: var(--qrs-inset);
    color: var(--qrs-text);
    font: inherit;
}

.qrs-note {
    font-size: 0.85rem;
    opacity: 0.65;
    margin: 14px 0 0;
}

/* ---------------------------------------------------------------- image */

.qrs-drop {
    border: 2px dashed var(--qrs-border);
    border-radius: 15px;
    padding: 46px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    background: rgba(0, 0, 0, 0.12);
}

.qrs-drop:hover,
.qrs-drop:focus-visible,
.qrs-drop.over {
    border-color: var(--qrs-accent);
    background: rgba(0, 0, 0, 0.22);
}

.qrs-drop i {
    font-size: 2.2rem;
    color: var(--qrs-accent);
    display: block;
    margin-bottom: 14px;
}

.qrs-drop p { margin: 0 0 6px; }
.qrs-drop span { font-size: 0.85rem; opacity: 0.65; }

.qrs-preview {
    margin-top: 18px;
    text-align: center;
}

.qrs-preview img {
    max-width: 100%;
    max-height: 260px;
    border-radius: 12px;
    border: 1px solid var(--qrs-border);
}

/* --------------------------------------------------------------- status */

.qrs-status {
    margin-top: 18px;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 0.92rem;
    border: 1px solid;
}

.qrs-status.info   { background: rgba(0, 153, 255, 0.12);  border-color: rgba(0, 153, 255, 0.45); }
.qrs-status.error  { background: rgba(255, 82, 82, 0.12);  border-color: rgba(255, 82, 82, 0.45); }
.qrs-status.ok     { background: rgba(76, 175, 80, 0.12);  border-color: rgba(76, 175, 80, 0.45); }

/* --------------------------------------------------------------- result */

.qrs-type {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--qrs-accent);
    color: #0a0a0a;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    margin-bottom: 16px;
}

.qrs-warning {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(255, 176, 32, 0.12);
    border: 1px solid rgba(255, 176, 32, 0.45);
    margin-bottom: 18px;
    font-size: 0.9rem;
}

.qrs-warning i { color: var(--qrs-warn); margin-top: 2px; }
.qrs-warning ul { margin: 8px 0 0; padding-left: 18px; }
.qrs-warning li { margin: 4px 0; }

.qrscan .password-display {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--qrs-border);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
}

.qrscan .password-text {
    font-family: monospace;
    font-size: 0.95rem;
    word-break: break-all;
    white-space: pre-wrap;
    color: var(--qrs-text);
}

.qrs-fields {
    display: grid;
    gap: 10px;
    margin-bottom: 22px;
}

.qrs-fields:empty { display: none; }

.qrs-field {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--qrs-inset);
    font-size: 0.92rem;
}

.qrs-field dt {
    font-weight: 700;
    opacity: 0.75;
    margin: 0;
}

.qrs-field dd {
    margin: 0;
    word-break: break-word;
}

.qrs-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* -------------------------------------------------------------- buttons */

.qrscan .generate-btn {
    background: var(--qrs-accent);
    color: #0a0a0a;
    border: 1px solid var(--qrs-accent);
    padding: 13px 26px;
    border-radius: 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
}

.qrscan .generate-btn:hover { filter: brightness(1.1); }

.qrs-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--qrs-inset);
    color: var(--qrs-text);
    border: 1px solid var(--qrs-border);
    padding: 13px 22px;
    border-radius: 12px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.25s ease;
}

.qrs-secondary:hover {
    border-color: var(--qrs-accent);
    color: var(--qrs-text);
}

.qrs-secondary.danger {
    border-color: rgba(255, 82, 82, 0.5);
    color: var(--qrs-danger);
}

.qrs-clear {
    background: none;
    border: 1px solid var(--qrs-border);
    color: var(--qrs-text);
    border-radius: 10px;
    padding: 6px 14px;
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
}

.qrs-clear:hover { border-color: var(--qrs-danger); color: var(--qrs-danger); }

/* -------------------------------------------------------------- history */

.qrs-history { display: grid; gap: 10px; }

.qrs-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--qrs-inset);
    border: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.qrs-item:hover { border-color: var(--qrs-border); }

.qrs-item-text {
    font-family: monospace;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.qrs-item-meta {
    font-size: 0.72rem;
    opacity: 0.6;
    white-space: nowrap;
}

.qrs-item button {
    background: none;
    border: none;
    color: var(--qrs-accent);
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    padding: 4px 8px;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 600px) {
    .qrscan .generator-card { padding: 20px; border-radius: 16px; }
    .qrs-stage { aspect-ratio: 3 / 4; max-height: 380px; }
    .qrs-field { grid-template-columns: 1fr; gap: 4px; }
    .qrs-actions .generate-btn,
    .qrs-actions .qrs-secondary { flex: 1 1 100%; justify-content: center; }
    .qrs-drop { padding: 34px 16px; }
    .qrs-item-meta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .qrscan * { transition: none !important; }
}
