:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --panel-soft: #f8faff;
    --border: #d8e2f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #15803d;
    --warning: #ca8a04;
    --danger: #dc2626;
    --text: #0f172a;
    --muted: #475569;
    --compact-token-height: 96px;
    --icon-button-size: 1.9rem;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
    background:
        radial-gradient(circle at 8% 0%, #dbeafe 0%, transparent 30%),
        radial-gradient(circle at 92% 0%, #dcfce7 0%, transparent 24%),
        linear-gradient(180deg, #eef3fb 0%, #f8fbff 100%);
    color: var(--text);
}

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 1rem;
}

.header,
.section,
.footer {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.main-content {
    display: grid;
    gap: 1rem;
}

.workspace-shell {
    display: grid;
    gap: 1rem;
}

.mode-rail {
    display: grid;
    gap: .55rem;
    align-content: start;
}

.mode-rail-btn {
    border: 1px solid #c7d6eb;
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
    color: var(--text);
    padding: .75rem .85rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .45rem;
    justify-content: flex-start;
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.08);
}

.mode-rail-btn:hover {
    border-color: #7aa3ec;
    box-shadow: 0 14px 26px rgba(37, 99, 235, 0.16);
}

.mode-rail-btn.active {
    background: #dbeafe;
    border-color: #7aa3ec;
    color: #1d4ed8;
}

.header h1 {
    margin: 0;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--muted);
    margin: .4rem 0 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    padding-bottom: .5rem;
    margin-bottom: .5rem;
}

.section-header-controls {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}

.section-status {
    border-radius: 999px;
    padding: .25rem .65rem;
    font-size: .8rem;
    font-weight: 600;
    background: #eef3ff;
    border: 1px solid #cad9f5;
}

.section-status.ok {
    background: #eaf8ef;
    color: var(--success);
}

.section-status.warn {
    background: #fef7df;
    color: var(--warning);
}

.section-toggle {
    min-width: 1.8rem;
    border: 1px solid #c5d4ea;
    border-radius: 8px;
    background: #f8fbff;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.section.collapsed .section-body {
    display: none;
}

.section.collapsed .section-header {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.input,
.token-input {
    width: 100%;
    border: 1px solid #c7d6eb;
    border-radius: 8px;
    padding: .5rem .6rem;
    font: inherit;
    background: #ffffff;
    color: var(--text);
}

.token-input { min-height: var(--compact-token-height); }

.form-group {
    margin-bottom: .6rem;
}

.form-group label {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-weight: 600;
    margin-bottom: .35rem;
}

.info-trigger {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: .95rem;
}

.form-group small {
    color: var(--muted);
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: .55rem;
}

.mode-switch {
    display: inline-flex;
    gap: .35rem;
    flex-wrap: wrap;
}

.mode-option {
    border: 1px solid #c7d6eb;
    border-radius: 999px;
    background: #f8fbff;
    color: var(--text);
    padding: .35rem .75rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.mode-option.active {
    background: #dbeafe;
    border-color: #7aa3ec;
    color: #1d4ed8;
}

#workspaceTabsSection {
    display: none;
}

.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: .55rem .85rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all .18s ease;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #d3deec;
}

.btn-success {
    background: #16a34a;
    color: #fff;
}

.btn-info {
    background: #0f766e;
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: .35rem .6rem;
    font-size: .9rem;
}

.subsection {
    margin-bottom: .75rem;
}

.identities-list,
.permissions-list,
.search-results {
    display: grid;
    gap: .45rem;
    max-height: 200px;
    overflow-y: auto;
}

.identities-list:focus-visible,
.permissions-list:focus-visible,
.search-results:focus-visible {
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

.identity-card,
.search-result-item,
.permission-item {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-soft);
    padding: .6rem;
    text-align: left;
    color: var(--text);
}

.identity-card {
    cursor: pointer;
}

.identity-card:hover,
.search-result-item:hover {
    border-color: #8eb2ea;
    background: #eff5ff;
}

.identity-card:focus-visible,
.search-result-item:focus-visible,
.permission-item button:focus-visible {
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

.identity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-bottom: .4rem;
}

.pill {
    font-size: .75rem;
    font-weight: 700;
    color: #1d4ed8;
    background: #dce9ff;
    border-radius: 999px;
    padding: .15rem .5rem;
}

.meta {
    color: var(--muted);
    font-size: .9rem;
    overflow-wrap: anywhere;
}

.meta span {
    font-weight: 600;
}

.permission-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    background: #f8fbff;
}

.entry-choice-grid {
    display: grid;
    gap: .75rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.entry-choice-btn {
    border: 1px solid #c7d6eb;
    border-radius: 14px;
    background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
    padding: 1rem;
    min-height: 120px;
    text-align: left;
    color: var(--text);
    cursor: pointer;
    display: grid;
    gap: .45rem;
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.08);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.entry-choice-btn strong {
    font-size: 1.06rem;
}

.entry-choice-btn span {
    color: var(--muted);
}

.entry-choice-btn:hover {
    transform: translateY(-2px);
    border-color: #7aa3ec;
    box-shadow: 0 14px 26px rgba(37, 99, 235, 0.16);
}

.entry-choice-btn:focus-visible {
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

.wizard-progress {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: .8rem;
}

.wizard-indicator {
    font-size: .82rem;
    font-weight: 600;
    border: 1px solid #cad9f5;
    background: #eef3ff;
    color: #334155;
    border-radius: 999px;
    padding: .25rem .6rem;
}

.wizard-indicator.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.wizard-step {
    border: 1px solid #d8e2f0;
    border-radius: 10px;
    padding: .75rem;
    background: #fafcff;
    margin-bottom: .7rem;
}

.wizard-step:last-of-type {
    margin-bottom: .5rem;
}

.manual-method-row,
.manual-endpoint-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .45rem;
    margin-bottom: .55rem;
}

.endpoint-inline {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: .9rem;
    color: #0f172a;
    overflow-wrap: anywhere;
}

.permission-summary {
    color: var(--muted);
    font-size: .9rem;
}

.permission-summary strong {
    color: var(--text);
}

.permission-item p,
.search-result-item p,
.search-result-description,
.description {
    margin: .35rem 0;
    color: var(--muted);
    line-height: 1.45;
}

.search-result-description {
    display: block;
}

.info-box,
.error-box,
.preview-box {
    border-radius: 10px;
    padding: .75rem;
    margin-top: .5rem;
}

.info-box {
    background: #f1f7ff;
    border: 1px solid #c8dbf8;
}

.error-box {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #7f1d1d;
}

.preview-box {
    background: #effaf3;
    border: 1px solid #b8e7c7;
}

.loading {
    color: var(--muted);
    font-style: italic;
    display: none;
}

.info-grid {
    display: grid;
    gap: .5rem;
}

.info-item {
    display: flex;
    gap: .5rem;
    overflow-wrap: anywhere;
}

.info-item-scopes {
    align-items: flex-start;
}

.info-item .label {
    font-weight: 700;
}

.token-scope-status {
    display: grid;
    gap: .2rem;
}

.token-scope-entry {
    display: flex;
    align-items: baseline;
    gap: .35rem;
}

.token-scope-icon {
    font-weight: 700;
    min-width: 1rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.empty-state {
    color: var(--muted);
    border: 1px dashed #b6c8e4;
    border-radius: 8px;
    padding: .6rem;
    text-align: center;
}

.footer {
    color: var(--muted);
    text-align: center;
    font-size: .9rem;
}

.footer p {
    margin: .25rem 0;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 1000;
}

.modal-card {
    width: min(680px, 100%);
    background: #ffffff;
    border: 1px solid #dbe5f3;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.modal-header h3 {
    margin: 0;
}

.modal-steps {
    margin: .8rem 0 0;
    padding-left: 1.2rem;
    color: var(--text);
}

.modal-steps li {
    margin-bottom: .5rem;
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-top: .6rem;
}

.modal-status {
    color: var(--muted);
    font-size: .9rem;
}

.scope-status-ok {
    color: var(--success);
    font-weight: 600;
}

.scope-status-missing {
    color: #92400e;
    font-weight: 600;
}

.code-field {
    margin-top: .65rem;
}

.code-block-wrap {
    position: relative;
}

.inline-copy-btn {
    position: absolute;
    top: .4rem;
    right: .4rem;
    min-width: var(--icon-button-size);
    height: var(--icon-button-size);
    padding: 0;
    border: 1px solid #c7d6eb;
    border-radius: 6px;
    background: #ffffff;
    cursor: pointer;
    z-index: 2;
}

.icon-copy-btn {
    min-width: var(--icon-button-size);
    width: var(--icon-button-size);
    padding: 0;
}

.learn-step-summary h4 {
    margin-top: 0;
}

.code-block {
    margin: 0;
    border: 1px solid #c7d6eb;
    border-radius: 8px;
    background: #0f172a;
    color: #e2e8f0;
    padding: .7rem .75rem .75rem;
    min-height: 120px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: .88rem;
    line-height: 1.45;
}

.endpoint-code {
    color: #bfdbfe;
    white-space: pre-wrap;
    word-break: break-word;
}

.json-code .json-key {
    color: #93c5fd;
}

.json-code .json-string {
    color: #86efac;
}

.json-code .json-punctuation {
    color: #e2e8f0;
}

@media (min-width: 768px) {
    .workspace-shell.with-rail {
        grid-template-columns: 220px minmax(0, 1fr);
    }

    .info-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .info-grid.token-info-grid {
        grid-template-columns: 1fr;
    }
}
