/* ═══════════════════════════════════════════════════════════
   REB TOKEN HELPER — app.css
   Mobile-first. Light & Dark themes. WCAG AA compliant.
═══════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────
   1. THEME VARIABLES
─────────────────────────────────────────────── */
[data-theme="light"] {
    --c-bg:              #F8FAFC;
    --c-surface:         #FFFFFF;
    --c-surface-2:       #F1F5F9;
    --c-border:          #E2E8F0;
    --c-text-primary:    #0F172A;
    --c-text-secondary:  #475569;
    --c-text-muted:      #94A3B8;
    --c-accent:          #0EA5E9;
    --c-accent-hover:    #0284C7;
    --c-accent-soft:     #E0F2FE;
    --c-accent-glow:     rgba(14, 165, 233, 0.18);
    --c-promo-bg:        #F0FDF4;
    --c-promo-border:    #BBF7D0;
    --c-promo-icon-bg:   #DCFCE7;
    --c-promo-icon:      #16A34A;
    --c-promo-btn:       #16A34A;
    --c-promo-btn-hover: #15803D;
    --c-danger:          #EF4444;
    --c-warning:         #F59E0B;
    --shadow-sm:         0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:         0 4px 12px rgba(0,0,0,.09), 0 2px 4px rgba(0,0,0,.06);
}

[data-theme="dark"] {
    --c-bg:              #020817;
    --c-surface:         #0F172A;
    --c-surface-2:       #1E293B;
    --c-border:          #334155;
    --c-text-primary:    #F8FAFC;
    --c-text-secondary:  #94A3B8;
    --c-text-muted:      #64748B;
    --c-accent:          #38BDF8;
    --c-accent-hover:    #7DD3FC;
    --c-accent-soft:     #0C4A6E;
    --c-accent-glow:     rgba(56, 189, 248, 0.18);
    --c-promo-bg:        #052E16;
    --c-promo-border:    #166534;
    --c-promo-icon-bg:   #14532D;
    --c-promo-icon:      #4ADE80;
    --c-promo-btn:       #22C55E;
    --c-promo-btn-hover: #16A34A;
    --c-danger:          #F87171;
    --c-warning:         #FBBF24;
    --shadow-sm:         0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.25);
    --shadow-md:         0 4px 12px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.30);
}

/* ───────────────────────────────────────────────
   2. BASE RESET & BODY
─────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background-color: var(--c-bg);
    color: var(--c-text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI',
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    transition: background-color .25s ease, color .25s ease;
}

/* ───────────────────────────────────────────────
   3. HEADER
─────────────────────────────────────────────── */
.app-header {
    background-color: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
    z-index: 1000;
    transition: background-color .25s ease, border-color .25s ease;
}

.brand-link {
    color: var(--c-text-primary);
    text-decoration: none;
}

.brand-link:hover {
    color: var(--c-accent);
}

.brand-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, #0EA5E9 0%, #0369A1 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(14,165,233,.35);
}

.brand-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.3px;
    color: var(--c-text-primary);
    transition: color .2s;
}

/* Control buttons (theme, lang, nav icons) */
.ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    background-color: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    color: var(--c-text-secondary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: background-color .2s, color .2s, border-color .2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.ctrl-btn:hover,
.ctrl-btn:focus-visible {
    background-color: var(--c-accent-soft);
    border-color: var(--c-accent);
    color: var(--c-accent);
    outline: none;
}

.ctrl-btn:focus-visible {
    box-shadow: 0 0 0 3px var(--c-accent-glow);
}

/* ───────────────────────────────────────────────
   4. MAIN LAYOUT
─────────────────────────────────────────────── */
.app-main {
    flex: 1;
}

.container {
    max-width: 600px !important;
}

.app-tagline {
    color: var(--c-text-secondary);
    font-size: 13px;
    margin-bottom: 0;
}

/* ───────────────────────────────────────────────
   5. STAT CARDS
─────────────────────────────────────────────── */
.stat-card {
    background-color: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 12px 6px;
    box-shadow: var(--shadow-sm);
    transition: background-color .25s ease, border-color .25s ease;
}

.stat-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--c-accent);
    line-height: 1.15;
    min-height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: -.5px;
}

.stat-label {
    font-size: 9px;
    color: var(--c-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-top: 3px;
    line-height: 1.3;
}

/* Skeleton shimmer */
.stat-skeleton {
    display: inline-block;
    width: 44px;
    height: 20px;
    border-radius: 4px;
    background: linear-gradient(
        90deg,
        var(--c-surface-2) 25%,
        var(--c-border)    50%,
        var(--c-surface-2) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0%   { background-position:  200% 0; }
    100% { background-position: -200% 0; }
}

/* ───────────────────────────────────────────────
   6. PASTE CARD
─────────────────────────────────────────────── */
.paste-card {
    background-color: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
    transition: background-color .25s ease, border-color .25s ease;
}

.paste-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--c-text-primary);
}

.sms-textarea {
    width: 100%;
    background-color: var(--c-surface-2);
    border: 1.5px solid var(--c-border);
    border-radius: 10px;
    color: var(--c-text-primary);
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 10px 12px;
    resize: vertical;
    min-height: 140px;
    display: block;
    transition: border-color .2s, box-shadow .2s, background-color .25s;
    -webkit-appearance: none;
    appearance: none;
}

.sms-textarea:focus {
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px var(--c-accent-glow);
    outline: none;
    background-color: var(--c-surface);
}

.sms-textarea::placeholder {
    color: var(--c-text-muted);
}

/* Character counter */
.char-counter {
    font-size: 11px;
    color: var(--c-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    transition: color .2s;
}

.char-counter.near-limit { color: var(--c-warning); }
.char-counter.at-limit   { color: var(--c-danger);  }

/* Extract button */
.btn-extract {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #0EA5E9 0%, #0369A1 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .1px;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(14, 165, 233, .35);
    transition: opacity .2s, transform .15s, box-shadow .2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-extract:hover:not(:disabled) {
    opacity: .9;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(14, 165, 233, .45);
}

.btn-extract:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(14, 165, 233, .3);
}

.btn-extract:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--c-accent-glow);
}

.btn-extract:disabled {
    background: var(--c-surface-2);
    color: var(--c-text-muted);
    box-shadow: none;
    cursor: not-allowed;
    opacity: 1;
}

/* ───────────────────────────────────────────────
   7. PROMO CARD
─────────────────────────────────────────────── */
.promo-card {
    background-color: var(--c-promo-bg);
    border: 1px solid var(--c-promo-border);
    border-radius: 16px;
    padding: 16px;
    transition: background-color .25s ease, border-color .25s ease;
}

.promo-icon {
    width: 42px;
    height: 42px;
    background-color: var(--c-promo-icon-bg);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--c-promo-icon);
    font-size: 20px;
    flex-shrink: 0;
}

.promo-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--c-text-primary);
    margin-bottom: 4px;
}

.promo-text {
    font-size: 13px;
    color: var(--c-text-secondary);
    line-height: 1.5;
    margin-bottom: 0;
}

.btn-promo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background-color: var(--c-promo-btn);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .2s, transform .15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-promo:hover {
    background-color: var(--c-promo-btn-hover);
    color: #fff;
    transform: translateY(-1px);
}

.btn-promo:active {
    transform: translateY(0);
}

/* ───────────────────────────────────────────────
   8. FOOTER
─────────────────────────────────────────────── */
.app-footer {
    background-color: var(--c-surface);
    border-top: 1px solid var(--c-border);
    margin-top: auto;
    transition: background-color .25s ease, border-color .25s ease;
}

.footer-text {
    font-size: 13px;
    color: var(--c-text-secondary);
    margin-bottom: 0;
}

.footer-brand {
    color: var(--c-accent);
    font-weight: 700;
    text-decoration: none;
}

.footer-brand:hover {
    color: var(--c-accent-hover);
    text-decoration: underline;
}

.footer-privacy {
    font-size: 12px;
    color: var(--c-text-muted);
    margin-bottom: 0;
}

/* ───────────────────────────────────────────────
   9. RESPONSIVE — TABLET & UP
─────────────────────────────────────────────── */
@media (min-width: 480px) {
    .stat-value { font-size: 22px; }
    .stat-label { font-size: 10px; }
}

@media (min-width: 576px) {
    .stat-card  { padding: 14px 10px; }
    .stat-value { font-size: 24px; }
    .stat-label { font-size: 11px; }
    .paste-card { padding: 20px; }
    .promo-card { padding: 20px; }
    .app-tagline { font-size: 14px; }
}

@media (min-width: 768px) {
    body { font-size: 16px; }
    .brand-name { font-size: 16px; }
}

/* ───────────────────────────────────────────────
   10. ACCESSIBILITY
─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* Focus ring for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
}

/* ───────────────────────────────────────────────
   11. TOKEN VIEWER
─────────────────────────────────────────────── */
.token-card {
    background-color: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 16px;
    padding: 20px 16px;
    box-shadow: var(--shadow-md);
    transition: background-color .25s ease, border-color .25s ease;
}

.token-counter {
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-muted);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 14px;
}

/* Normal + Zoom display */
.token-display-wrap {
    background-color: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 18px 12px;
    margin-bottom: 18px;
    text-align: center;
    transition: background-color .25s ease;
}

.token-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(20px, 5.5vw, 34px);
    font-weight: 700;
    color: var(--c-accent);
    letter-spacing: .06em;
    line-height: 1.3;
    word-break: break-all;
    transition: font-size .2s ease;
}

.token-display.zoom-mode {
    font-size: clamp(48px, 15vw, 96px);
    letter-spacing: .12em;
    line-height: 1.15;
}

/* Guided mode display */
#guidedDisplay {
    text-align: center;
    margin-bottom: 4px;
}

.guided-block {
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(64px, 20vw, 120px);
    font-weight: 800;
    color: var(--c-accent);
    letter-spacing: .18em;
    line-height: 1;
    padding: 12px 8px;
}

.guided-progress {
    font-size: 12px;
    color: var(--c-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 16px;
}

/* Token navigation row */
.token-nav-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.token-nav-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    background-color: var(--c-surface-2);
    border: 1.5px solid var(--c-border);
    border-radius: 10px;
    color: var(--c-text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .2s, border-color .2s, color .2s;
    -webkit-tap-highlight-color: transparent;
}

.token-nav-btn:hover:not(:disabled) {
    background-color: var(--c-accent-soft);
    border-color: var(--c-accent);
    color: var(--c-accent);
}

.token-nav-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

/* Action buttons (Copy, Guided, Zoom, Read) */
.token-action-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.token-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    background-color: var(--c-surface-2);
    border: 1.5px solid var(--c-border);
    border-radius: 10px;
    color: var(--c-text-secondary);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .3px;
    cursor: pointer;
    transition: background-color .2s, border-color .2s, color .2s;
    -webkit-tap-highlight-color: transparent;
}

.token-action-btn i {
    font-size: 20px;
    line-height: 1;
}

.token-action-btn:hover {
    background-color: var(--c-accent-soft);
    border-color: var(--c-accent);
    color: var(--c-accent);
}

.token-action-btn.active {
    background-color: var(--c-accent);
    border-color: var(--c-accent);
    color: #fff;
}

/* "Extract New SMS" back link */
.btn-link-soft {
    background: none;
    border: none;
    color: var(--c-text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 8px;
    transition: color .2s, background-color .2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-link-soft:hover {
    color: var(--c-accent);
    background-color: var(--c-accent-soft);
}

/* Error state */
.token-error-icon {
    font-size: 40px;
    color: var(--c-warning);
}

@media (min-width: 576px) {
    .token-card    { padding: 24px 20px; }
    .token-nav-btn { padding: 11px 18px; }
    .token-action-btn { padding: 12px 8px; font-size: 11px; }
    .token-action-btn i { font-size: 22px; }
}
