/* ========================================
   Base64 Decoder — Styles
   Dark mode default, dev-tool aesthetic
   ======================================== */

:root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-input: #0d1117;
    --bg-nav: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-dim: #484f58;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --orange: #d29922;
    --purple: #bc8cff;
    --header-color: #58a6ff;
    --payload-color: #3fb950;
    --signature-color: #f85149;
    --radius: 8px;
    --radius-lg: 12px;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --nav-height: 64px;
    --header-height: 72px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    touch-action: manipulation;
}

/* Ensure all interactive elements respond to touch immediately */
button, a, [role="button"], .history-item, .file-drop-zone {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(88, 166, 255, 0.15);
}

/* ---- Header ---- */
header {
    height: var(--header-height);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 12px 16px 4px;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

header .subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---- Main ---- */
main {
    height: calc(100% - var(--header-height) - var(--nav-height));
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

/* ---- Views ---- */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Mode Toggle (Encode/Decode) ---- */
.mode-toggle {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--accent);
    color: #fff;
}

.mode-btn:hover:not(.active) {
    background: rgba(88, 166, 255, 0.1);
    color: var(--text);
}

.mode-btn:active:not(.active) {
    background: rgba(88, 166, 255, 0.2);
}

/* ---- Editor Area ---- */
.editor-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.textarea-wrap {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.textarea-wrap label {
    display: block;
    padding: 8px 12px 0;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.textarea-wrap textarea {
    width: 100%;
    min-height: 120px;
    padding: 8px 12px 12px;
    background: transparent;
    color: var(--text);
    border: none;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}

.textarea-wrap textarea::placeholder {
    color: var(--text-dim);
}

.textarea-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.textarea-actions {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    gap: 4px;
}

/* ---- Icon Buttons ---- */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-icon:hover {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent);
    border-color: var(--border);
}

.btn-icon:active {
    transform: scale(0.92);
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent);
}

/* ---- Swap Button ---- */
.swap-row {
    display: flex;
    justify-content: center;
    padding: 4px 0;
}

.btn-swap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-swap:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: rotate(180deg);
}

.btn-swap:active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: scale(0.9);
}

/* ---- File Drop Zone ---- */
.file-drop-zone {
    margin-top: 16px;
    padding: 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.file-drop-zone p {
    margin-top: 8px;
    font-size: 0.85rem;
}

.file-drop-zone:active {
    border-color: var(--accent);
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent);
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(88, 166, 255, 0.05);
    color: var(--accent);
}

/* ---- Info Bar ---- */
.info-bar {
    margin-top: 12px;
    padding: 0 4px;
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
    min-height: 18px;
}

/* ---- JWT Sections ---- */
.jwt-parts {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.jwt-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.jwt-label {
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.jwt-label.header-color { color: var(--header-color); }
.jwt-label.payload-color { color: var(--payload-color); }
.jwt-label.signature-color { color: var(--signature-color); }

.jwt-code {
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 40px;
}

/* ---- Hash Results ---- */
.hash-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.hash-row {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.hash-row .hash-name {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
    min-width: 60px;
    flex-shrink: 0;
}

.hash-row .hash-value {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text);
    word-break: break-all;
    flex: 1;
    user-select: all;
}

.hash-row .btn-icon {
    flex-shrink: 0;
}

/* ---- History ---- */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.history-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.btn-text {
    background: none;
    border: none;
    color: var(--red);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}

.btn-text:hover, .btn-text:active {
    background: rgba(248, 81, 73, 0.15);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.history-item:hover, .history-item:active {
    border-color: var(--accent);
    background: rgba(88, 166, 255, 0.05);
}

.history-item .history-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.history-item .history-type {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
}

.history-item .history-time {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.history-item .history-preview {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Placeholder ---- */
.view-placeholder {
    text-align: center;
    color: var(--text-dim);
    padding: 32px 16px;
    font-size: 0.9rem;
}

/* ---- Bottom Nav ---- */
.bottom-nav {
    height: var(--nav-height);
    display: flex;
    border-top: 1px solid var(--border);
    background: var(--bg-nav);
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    padding: 8px 4px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.nav-btn:hover {
    color: var(--text-muted);
}

.nav-btn:active {
    background: rgba(88, 166, 255, 0.1);
}

.nav-btn.active {
    color: var(--accent);
}

.nav-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--green);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
    z-index: 1000;
}

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

.toast.error {
    background: var(--red);
}

/* ---- Scrollbar ---- */
main::-webkit-scrollbar {
    width: 6px;
}

main::-webkit-scrollbar-track {
    background: transparent;
}

main::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

main::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ---- Responsive ---- */
@media (min-width: 640px) {
    main {
        max-width: 600px;
        margin: 0 auto;
    }

    header h1 {
        font-size: 1.5rem;
    }
}

@media (min-width: 1024px) {
    main {
        max-width: 720px;
    }
}
