/* ================================
   CSS Base & Design Tokens
================================ */
:root {
    --app-max-width: 1400px;

    /* Colors */
    --page-bg: radial-gradient(circle at 15% 15%, #fff 0%, #f4f6fb 46%, #e2e8f0 85%);
    --surface: #fff;
    --surface-muted: #f8fafc;
    --border-soft: rgba(15, 23, 42, 0.06);
    --border-subtle: rgba(15, 23, 42, 0.025);
    --border-faint: rgba(15, 23, 42, 0.02);
    --primary: #2563eb;
    --primary-soft: rgba(37, 99, 235, 0.13);
    --text: #0f172a;
    --text-muted: #64748b;

    /* Typography */
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

    /* Effects */
    --radius-lg: 22px;
    --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.07);
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.11);

    /* Buttons */
    --copy-btn-bg: #eef2ff;
    --copy-btn-bg-hover: #b2c7f9;
}

/* ================================
   Base Reset & Typography
================================ */
*,
*::before,
*::after { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 1.7rem;
    font-family: var(--font-sans);
    background: var(--page-bg);
    color: var(--text);
}

code { font-family: var(--font-mono); font-size: 0.6rem; }

/* Shared content width */
.app-warning,
.topbar,
.container,
footer,
.footer-notice {
    width: min(var(--app-max-width), 96vw);
    margin: 0 auto;
}

/* ================================
   Header / Top Bar
================================ */
.topbar {
    margin: 1.35rem auto 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.topbar-title {
    display: flex;
    gap: 0.65rem;
    align-items: center;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.3rem, 3.3vw, 1.7rem);
}

.topbar small {
    color: var(--text-muted);
    font-size: 0.68rem;
}

.topbar-nav { display: flex; gap: 0.4rem; }

.topbar-link {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.28rem 0.7rem 0.33rem;
    font-size: 0.68rem;
    color: var(--text);
    text-decoration: none;
    transition: background 0.1s, border 0.1s, box-shadow 0.1s;
}

.topbar-link:hover { background: rgba(255, 255, 255, 0.3); }

.topbar-link.is-active {
    border-color: rgba(15, 23, 42, 0.05);
    background: #fff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
}

/* ================================
   Notices / Footer
================================ */
.app-warning {
    margin-top: 0.7rem;
    padding: 0.4rem 0.65rem 0.45rem;
    background: #fff5f5;
    border: 1px solid #ffe4e6;
    border-radius: 14px;
    color: #b91c1c;
    font-size: 0.63rem;
    line-height: 1.4;
    text-align: center;
}

.footer-notice {
    margin-top: 1rem;
    text-align: center;
}

footer {
    margin-top: 1.15rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ================================
   App Shell
================================ */
.container {
    position: relative;
    margin-top: 0.5rem;
    padding: 1.3rem clamp(1rem, 2.1vw, 1.6rem) 1.6rem;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.page-desc {
    margin: 0 0 1.1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ================================
   Layout Helpers
================================ */
.grid { display: grid; gap: 1.05rem; }
.margin-small-top { margin-top: 0.2rem; }
.full-span { grid-column: 1 / -1; }

/* ================================
   Forms & Fields
================================ */
.field {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.8rem 0.85rem 0.9rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-faint);
    border-radius: 16px;
}

.field label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.78rem;
}

.field small { color: var(--text-muted); line-height: 1.4; }
.field-body { position: relative; display: flex; flex-direction: column; }

textarea,
input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"] {
    width: 100%;
    padding: 0.55rem 0.65rem 0.6rem;
    font-size: 0.82rem;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 13px;
    outline: none;
    transition: border 0.12s, box-shadow 0.12s, background 0.12s;
}

textarea {
    min-height: 120px;
    max-height: 240px;
    resize: vertical;
    font-family: var(--font-mono);
}

textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="search"]:focus {
    border-color: rgba(37, 99, 235, 0.85);
    box-shadow: var(--focus-ring);
    background: #fff;
}

/* Inline options */
.options-inline {
    display: flex;
    gap: 0.55rem;
}

.options-inline.wrap { flex-wrap: wrap; }

.options-inline .small-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 30%;
    flex: 1;
}

.label-small { font-size: 0.68rem; font-weight: 600; }

/* Password hint */
.password-hint { font-size: 0.65rem; color: var(--text-muted); }

/* ================================
   Buttons
================================ */
.buttons-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1rem;
    align-items: center;
}

.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.52rem 1.2rem 0.58rem;
    border: none;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.25);
    transition: transform 0.085s, box-shadow 0.085s, background 0.1s;
}

.full-width-100 { width: 100%; }

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(37, 99, 235, 0.25);
}

.btn.secondary {
    background: var(--copy-btn-bg);
    color: var(--text);
    border: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: none;
}

.btn.secondary:hover {
    background: var(--copy-btn-bg-hover);
    transform: translateY(-1px);
    box-shadow: none;
}

/* Copy buttons */
.copy-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.7rem;
    background: var(--copy-btn-bg);
    color: var(--text);
    font-size: 0.7rem;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
}

.copy-btn:hover { background: var(--copy-btn-bg-hover); transform: translateY(-1px); }

/* Generic small icon button (e.g., password hint) */
.icon-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    background: var(--copy-btn-bg);
    color: var(--text);
    font-weight: 700;
    font-size: 0.8rem;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
}
.icon-btn:hover { background: var(--copy-btn-bg-hover); transform: translateY(-1px); }

/* ================================
   Cards / Docs
================================ */
.doc-card {
    margin-top: 1.25rem;
    padding: 0.85rem 0.85rem 0.7rem;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.045);
    border-radius: 16px;
}

.doc-card h2 {
    margin: 0 0 0.35rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.doc-text {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    line-height: 1.45;
    color: var(--text-muted);
}

/* ================================
   Payload info helpers
================================ */
.payload-info .pi-row { margin: 0.25rem 0; }
.pi-sep {
    border: none;
    border-top: 1px dashed var(--border-soft);
    margin: 0.5rem 0;
}
.pi-description {
    margin-top: 0.35rem;
    padding: 0.5rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-faint);
    border-radius: 10px;
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.76rem;
}

/* ================================
   Toast
================================ */
.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: 280px;
    padding: 0.5rem 0.85rem 0.45rem;
    background: #fff;
    color: var(--text);
    font-size: 0.72rem;
    border: 1px solid rgba(15, 23, 42, 0.05);
    border-radius: 14px;
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.1);
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.22s, opacity 0.22s;
    z-index: 200;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ================================
   Modal
================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.1rem;
    background: rgba(15, 23, 42, 0.25);
    backdrop-filter: blur(2px);
    z-index: 400;
}

.modal {
    width: min(430px, 100%);
    padding: 1rem 1rem 0.6rem;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.05);
    border-radius: 18px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
}

.modal h3 { margin: 0 0 0.5rem; font-size: 0.9rem; }

.modal p {
    margin: 0 0 0.8rem;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.4rem;
    margin-bottom: 0.35rem;
}

/* ================================
   Loading Overlay
================================ */
#loadingOverlay {
    position: absolute;
    inset: 0;
    display: none;
    gap: 0.65rem;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: rgba(243, 244, 246, 0.85);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(1px);
    z-index: 20;
}

.loading-text {
    font-size: 0.78rem;
    color: var(--text);
    opacity: 0.8;
}

.spinner {
    width: 46px;
    height: 46px;
    border: 3.5px solid rgba(37, 99, 235, 0.15);
    border-top-color: rgba(37, 99, 235, 1);
    border-radius: 999px;
    animation: spin 0.55s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ================================
   Utilities
================================ */
.is-hidden { display: none !important; }

/* ================================
   Segmented Control
================================ */
.segmented-control {
    display: inline-flex;
    gap: 0.35rem;
    padding: 0.25rem 0.3rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-faint);
    border-radius: 999px;
    margin-bottom: 1rem;
}

.segmented-btn {
    appearance: none;
    padding: 0.35rem 0.85rem;
    background: transparent;
    border: none;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.segmented-btn.is-active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

/* ================================
   Responsive
================================ */
@media (min-width: 951px) {
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 950px) {
    .grid { grid-template-columns: 1fr; }
    .buttons-row { flex-direction: column; align-items: flex-start; }
    .btn { justify-content: center; }
    .options-inline { flex-direction: column; }
    .topbar { flex-wrap: wrap; }
}
