*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f4f6f9;
    color: #222;
    min-height: 100vh;
}

/* ---- Loading overlay ---- */
#overlay {
    position: fixed; inset: 0;
    background: #fff;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 1rem; z-index: 9999;
    transition: opacity 0.8s ease;
}
#overlay.fade-out { opacity: 0; pointer-events: none; }
.spinner {
    width: 44px; height: 44px;
    border: 4px solid #e0e0e0;
    border-top-color: #003087;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#overlay p { font-size: 0.9rem; color: #666; }

/* ---- Layout ---- */
.page {
    max-width: 680px;
    margin: 2.5rem auto;
    padding: 0 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* ---- Header ---- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.logo     { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.5px; color: #003087; }
.logo-sub { font-size: 0.78rem; color: #666; margin-top: 2px; }
.site-badge {
    font-size: 0.72rem; font-weight: 700;
    padding: 0.28rem 0.75rem;
    border-radius: 999px; color: #fff;
    letter-spacing: 0.04em; text-transform: uppercase;
}
.badge-01 { background: #003087; }
.badge-02 { background: #0078d4; }
.badge-03 { background: #7c3aed; }

/* ---- Panels ---- */
.panel {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.panel-title {
    font-size: 0.72rem; font-weight: 700;
    color: #888; text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---- Session rows ---- */
.info-row {
    display: flex; align-items: center;
    gap: 0.5rem; font-size: 0.875rem;
}
.info-label { color: #666; min-width: 94px; flex-shrink: 0; }
.mono {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem; color: #003087; font-weight: 600;
    word-break: break-all;
}
.mono.dim  { color: #bbb; font-weight: 400; font-style: italic; }
.mono.live { color: #16a34a; }

.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #e5e7eb; flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}
.status-dot.live { background: #16a34a; box-shadow: 0 0 0 3px #bbf7d0; }

.api-row {
    display: none;
    font-size: 0.76rem; color: #9ca3af;
    padding: 0.35rem 0.6rem;
    background: #f8fafc;
    border: 1px solid #e5e7eb; border-radius: 6px;
    word-break: break-all; line-height: 1.5;
}
.api-row a { color: #0078d4; }

/* ---- Navigation ---- */
.nav-panel {
    background: #fff; border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.nav-desc {
    font-size: 0.85rem; color: #555; line-height: 1.55;
    margin-bottom: 1rem;
}
.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.btn-nav {
    display: inline-flex; align-items: center; gap: 0.35rem;
    color: #fff; text-decoration: none; cursor: pointer;
    padding: 0.5rem 1.1rem; border-radius: 8px;
    font-size: 0.875rem; font-weight: 600;
    border: none; transition: filter 0.15s;
}
.btn-nav:hover { filter: brightness(0.88); }
.btn-nav-01 { background: #003087; }
.btn-nav-02 { background: #0078d4; }
.btn-nav-03 { background: #7c3aed; }
.btn-nav-04 { background: #f59e0b; }
.btn-nav-05 { background: #ef4444; }
.btn-nav-06 { background: #10b981; }    

/* ---- Environment / Cross-Domain Pill ---- */
.env-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 9999px;
    padding: 4px 12px 4px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, border-color 0.15s;
}
.env-pill:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}
.env-pill-arrow {
    font-size: 0.7rem;
    color: #64748b;
}
.env-popover {
    position: absolute;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    padding: 6px;
    min-width: 220px;
    z-index: 100;
    font-size: 0.85rem;
}
.env-popover .env-option {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
}
.env-popover .env-option:hover {
    background: #f1f5f9;
}
.env-popover .env-option.current {
    background: #e0f2fe;
    font-weight: 600;
}
.env-popover .env-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    padding: 4px 12px 2px;
    font-weight: 600;
}

/* ---- Token ---- */
.token-row { display: flex; align-items: center; gap: 0.5rem; }
.field-input {
    flex: 1; min-width: 0;
    border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 0.42rem 0.65rem;
    font-size: 0.8rem; font-family: 'Courier New', monospace;
    outline: none; background: #fafafa; color: #333;
}
.field-input:focus { border-color: #0078d4; background: #fff; }
.btn-icon {
    background: none; border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 0.38rem 0.55rem; cursor: pointer;
    font-size: 0.85rem; color: #666; flex-shrink: 0;
}
.btn-icon:hover { background: #f3f4f6; }
.token-badge {
    font-size: 0.72rem; font-weight: 600;
    padding: 0.2rem 0.5rem; border-radius: 4px;
    white-space: nowrap; flex-shrink: 0;
}
.token-badge.empty   { background: #f3f4f6; color: #9ca3af; }
.token-badge.valid   { background: #dcfce7; color: #166534; }
.token-badge.warning { background: #fef9c3; color: #854d0e; }
.token-badge.expired { background: #fee2e2; color: #991b1b; }

/* ---- Inject ---- */
.msg-textarea {
    width: 100%; min-height: 64px;
    border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 0.5rem 0.65rem;
    font-size: 0.875rem; font-family: inherit;
    resize: vertical; outline: none; background: #fafafa;
}
.msg-textarea:focus { border-color: #0078d4; background: #fff; }
.inject-footer {
    display: flex; align-items: center;
    justify-content: space-between; gap: 0.5rem;
}
.inject-hint { font-size: 0.76rem; color: #9ca3af; }
.btn-primary {
    background: #0078d4; color: #fff; border: none;
    border-radius: 8px; padding: 0.5rem 1.1rem;
    font-size: 0.875rem; font-weight: 600; cursor: pointer;
    transition: filter 0.15s; flex-shrink: 0;
}
.btn-primary:hover:not(:disabled) { filter: brightness(0.88); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Custom fields table ---- */
.cf-table {
    width: 100%; border-collapse: collapse;
    font-family: 'Courier New', monospace; font-size: 0.8rem;
}
.cf-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #f0f0f0; vertical-align: top;
}
.cf-table td:first-child { color: #888; white-space: nowrap; width: 150px; }
.cf-table td:last-child  { color: #003087; word-break: break-all; }

/* ---- Toast ---- */
#toastContainer {
    position: fixed; top: 1rem; right: 1rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    z-index: 10000; pointer-events: none;
}
.toast {
    padding: 0.6rem 1rem; border-radius: 8px;
    font-size: 0.82rem; color: #fff; background: #374151;
    opacity: 0; transform: translateY(-6px);
    transition: opacity 0.2s, transform 0.2s;
    max-width: 300px;
}
.toast.show    { opacity: 1; transform: translateY(0); }
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }

.footnote {
    font-size: 0.73rem; color: #aaa;
    text-align: center; line-height: 1.6;
}

/* ---- Serviceability ---- */
.btn-svc {
    background: #003087; color: #fff; border: none;
    border-radius: 8px; padding: 0.5rem 1.1rem;
    font-size: 0.875rem; font-weight: 600; cursor: pointer;
    transition: filter 0.15s, background 0.25s; align-self: flex-start;
}
.btn-svc:hover { filter: brightness(0.88); }
.btn-svc.has-data { background: #16a34a; }

.svc-note {
    display: none;
    font-size: 0.78rem; color: #166534; line-height: 1.5;
    padding: 0.4rem 0.65rem;
    background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px;
}

/* ---- Modal ---- */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    display: none; align-items: center; justify-content: center;
    z-index: 10001;
}
.modal-box {
    background: #fff; border-radius: 14px;
    padding: 1.75rem; width: 100%; max-width: 440px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    margin: 1rem;
}
.modal-box h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; }
.modal-sub { font-size: 0.82rem; color: #666; margin-bottom: 1.1rem; line-height: 1.5; }
.modal-target {
    font-size: 0.78rem; color: #555; margin-bottom: 1.1rem;
    padding: 0.35rem 0.6rem; background: #f8f9fa; border-radius: 6px;
}
.modal-target strong { color: #003087; font-family: 'Courier New', monospace; }
.form-group { margin-bottom: 0.9rem; }
.form-group label { display: block; font-size: 0.78rem; font-weight: 600; color: #444; margin-bottom: 0.28rem; }
.form-group input {
    width: 100%; border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 0.48rem 0.65rem; font-size: 0.875rem; outline: none;
    background: #fafafa;
}
.form-group input:focus { border-color: #0078d4; background: #fff; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
.btn-secondary {
    background: none; color: #555; border: 1px solid #e5e7eb;
    border-radius: 8px; padding: 0.5rem 1.1rem;
    font-size: 0.875rem; font-weight: 600; cursor: pointer;
}
.btn-secondary:hover { background: #f3f4f6; }

/* ---- Cross-Device Transfer Panel ---- */
.xd-status-row {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.82rem;
}
.xd-badge {
    font-size: 0.72rem; font-weight: 700;
    padding: 0.2rem 0.55rem; border-radius: 4px;
    white-space: nowrap;
}
.xd-badge.no-session  { background: #f3f4f6; color: #9ca3af; }
.xd-badge.has-session { background: #dbeafe; color: #1e40af; }
.xd-badge.incoming    { background: #dcfce7; color: #166534; }

.transfer-url-box {
    display: none;
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
    color: #374151;
    word-break: break-all;
    padding: 0.5rem 0.65rem;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    line-height: 1.55;
}

.xd-actions {
    display: none;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.qr-wrap {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
}
.qr-label {
    font-size: 0.72rem; color: #888; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
}
#qrCanvas {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 6px;
    background: #fff;
}

.account-row {
    display: flex; align-items: center; gap: 0.5rem;
}
.account-badge {
    font-size: 0.72rem; font-weight: 600;
    padding: 0.2rem 0.5rem; border-radius: 4px;
    white-space: nowrap; flex-shrink: 0;
}
.account-badge.unset { background: #f3f4f6; color: #9ca3af; }
.account-badge.set   { background: #ede9fe; color: #5b21b6; }

.xd-note {
    font-size: 0.76rem; color: #6b7280; line-height: 1.55;
    padding: 0.4rem 0.65rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
}
