:root {
    --pm-bg: #f8f8f8;
    --pm-bg-accent: #edf0fd;
    --pm-surface: rgba(255, 255, 255, 0.96);
    --pm-surface-strong: #ffffff;
    --pm-ink: #1f2937;
    --pm-muted: #6b7280;
    --pm-border: rgba(31, 41, 55, 0.12);
    --pm-primary: #3a56e4;
    --pm-primary-strong: #3067db;
    --pm-secondary: #1f2937;
    --pm-secondary-strong: #3b454f;
    --pm-success: #2db7f5;
    --pm-danger: #1f2937;
    --pm-warning: #3067db;
    --pm-shadow: 0 18px 48px rgba(18, 22, 29, 0.08);
    --pm-radius-lg: 24px;
    --pm-radius-md: 16px;
    --pm-radius-sm: 12px;
    --pm-font-body: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --pm-font-display: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0 2.5vw;
    min-height: 100vh;
    overflow-x: hidden;
    color: var(--pm-ink);
    font-family: var(--pm-font-body);
    background:
        radial-gradient(circle at top left, rgba(58, 86, 228, 0.14), transparent 22%),
        radial-gradient(circle at 92% 12%, rgba(45, 183, 245, 0.1), transparent 18%),
        linear-gradient(180deg, #ffffff 0%, var(--pm-bg) 42%, var(--pm-bg-accent) 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(217, 217, 217, 0.28) 1px, transparent 1px),
        linear-gradient(90deg, rgba(217, 217, 217, 0.28) 1px, transparent 1px);
    background-size: 40px 40px;
    opacity: 0.14;
}

a {
    color: #1d2229;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

.pm-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: none;
    margin: 0 auto;
    padding: 28px 0 48px;
    animation: pm-rise 420ms ease;
}

.pm-auth-shell {
    max-width: 560px;
    padding-top: 72px;
}

.pm-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
    padding: 18px 22px;
    border: 1px solid rgba(24, 27, 32, 0.08);
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 248, 248, 0.94));
    box-shadow: var(--pm-shadow);
    backdrop-filter: blur(12px);
}

.pm-brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pm-brand h1,
.pm-brand h2 {
    margin: 0;
    font-family: var(--pm-font-display);
    font-size: clamp(1.5rem, 2vw, 2.1rem);
    letter-spacing: -0.03em;
    font-weight: 700;
}

.pm-brand p {
    margin: 0;
    color: var(--pm-muted);
    font-size: 0.96rem;
    max-width: 56ch;
}

.pm-topbar-actions,
.pm-actions,
.pm-inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.pm-form-stack {
    display: grid;
    gap: 16px;
}

.pm-inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.pm-inline-input {
    min-width: 220px;
}

.pm-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(31, 41, 55, 0.06);
    color: #1f2937;
    font-size: 0.88rem;
    font-weight: 700;
}

.pm-platform-badge {
    background: rgba(58, 86, 228, 0.12);
    color: #3067db;
    border: 1px solid rgba(58, 86, 228, 0.22);
}

.pm-banner {
    display: none;
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid transparent;
    box-shadow: 0 8px 30px rgba(60, 44, 19, 0.08);
}

.pm-banner.is-visible {
    display: block;
    animation: pm-fade 200ms ease;
}

.pm-banner[data-kind="success"] {
    background: rgba(45, 183, 245, 0.12);
    border-color: rgba(45, 183, 245, 0.2);
    color: #3067db;
}

.pm-banner[data-kind="error"] {
    background: rgba(31, 41, 55, 0.08);
    border-color: rgba(31, 41, 55, 0.14);
    color: #1f2937;
}

.pm-banner[data-kind="info"] {
    background: rgba(58, 86, 228, 0.08);
    border-color: rgba(58, 86, 228, 0.16);
    color: #3067db;
}

.pm-grid {
    display: grid;
    gap: 22px;
}

.pm-grid.two-col {
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr);
}

.pm-grid.dashboard {
    grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
}

.pm-card {
    background: var(--pm-surface);
    border: 1px solid rgba(24, 27, 32, 0.06);
    border-radius: var(--pm-radius-lg);
    box-shadow: var(--pm-shadow);
    backdrop-filter: blur(10px);
    overflow: hidden;
    min-width: 0;
}

.pm-card-inner {
    padding: 22px;
    min-width: 0;
    max-width: 100%;
}

.pm-card h3,
.pm-card h4 {
    margin: 0 0 10px;
    font-family: var(--pm-font-display);
    letter-spacing: -0.02em;
}

.pm-card p {
    margin: 0;
    color: var(--pm-muted);
    line-height: 1.55;
}

.pm-section-title {
    margin: 0 0 16px;
    font-size: 1.14rem;
    font-family: var(--pm-font-display);
}

.pm-form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pm-form-grid.full-width {
    grid-template-columns: 1fr;
}

.pm-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pm-field-span-full {
    grid-column: 1 / -1;
}

.pm-field label {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1f2937;
}

.pm-field small {
    color: var(--pm-muted);
}

.pm-input,
input[type="text"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--pm-border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    color: var(--pm-ink);
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

textarea {
    min-height: 150px;
    resize: vertical;
}

.pm-input:focus,
input[type="text"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(58, 86, 228, 0.45);
    box-shadow: 0 0 0 4px rgba(58, 86, 228, 0.12);
    transform: translateY(-1px);
}

.pm-button,
input[type="submit"],
input[type="button"],
button {
    appearance: none;
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    background: linear-gradient(180deg, var(--pm-primary), var(--pm-primary-strong));
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, opacity 160ms ease;
    box-shadow: 0 14px 22px rgba(58, 86, 228, 0.2);
}

.pm-button:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
button:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 28px rgba(58, 86, 228, 0.28);
    background: linear-gradient(180deg, var(--pm-primary-strong), #3257ec);
}

.pm-button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled,
button:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
    box-shadow: none;
}

.pm-button.secondary {
    background: linear-gradient(180deg, var(--pm-secondary), var(--pm-secondary-strong));
    color: #fff;
    box-shadow: 0 14px 22px rgba(24, 27, 32, 0.12);
}

.pm-button.secondary:hover {
    background: linear-gradient(180deg, var(--pm-secondary-strong), #3d444d);
}

.pm-button.ghost,
.link-button {
    background: rgba(255, 255, 255, 0.82);
    color: #1f2329;
    box-shadow: inset 0 0 0 1px rgba(24, 27, 32, 0.08);
}

.pm-button.ghost:hover,
.link-button:hover {
    background: rgba(31, 41, 55, 0.05);
}

.pm-button.danger {
    background: linear-gradient(180deg, var(--pm-danger), var(--pm-secondary-strong));
}

.pm-button.warning {
    background: linear-gradient(180deg, var(--pm-warning), var(--pm-primary));
}

.pm-button.success {
    background: linear-gradient(180deg, var(--pm-success), var(--pm-primary-strong));
}

.pm-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(58, 86, 228, 0.1);
    color: #3067db;
    font-size: 0.85rem;
    font-weight: 700;
}

.pm-user-pill {
    margin-left: 10px;
}

.pm-grid.two-col.pm-user-admin-grid {
    grid-template-columns: minmax(320px, 0.82fr) minmax(0, 1.28fr);
}

.pm-user-table-wrap {
    overflow-x: auto;
}

.pm-user-table {
    table-layout: auto;
    min-width: 980px;
}

.pm-user-table th:nth-child(1),
.pm-user-table td:nth-child(1) {
    width: 16%;
}

.pm-user-table th:nth-child(2),
.pm-user-table td:nth-child(2) {
    width: 28%;
}

.pm-user-table th:nth-child(3),
.pm-user-table td:nth-child(3) {
    width: 14%;
}

.pm-user-table th:nth-child(4),
.pm-user-table td:nth-child(4) {
    width: 10%;
}

.pm-user-table th:nth-child(5),
.pm-user-table td:nth-child(5) {
    width: 14%;
}

.pm-user-table th:nth-child(6),
.pm-user-table td:nth-child(6) {
    width: 18%;
}

.pm-user-name-cell,
.pm-user-email-cell,
.pm-user-status-cell,
.pm-user-actions-cell {
    min-width: 0;
}

.pm-user-name {
    font-weight: 700;
    color: #1f2937;
}

.pm-user-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.pm-user-badges .pm-user-pill {
    margin-left: 0;
}

.pm-user-email-form {
    display: grid;
    gap: 10px;
    align-items: stretch;
}

.pm-user-email-input {
    min-width: 0;
}

.pm-user-email-save {
    justify-self: start;
}

.pm-user-failed-cell,
.pm-user-login-cell {
    white-space: nowrap;
}

.pm-user-status-cell {
    line-height: 1.45;
}

.pm-user-actions {
    min-width: 150px;
}

.pm-user-actions form {
    width: 100%;
}

.pm-user-actions .pm-button {
    white-space: normal;
    line-height: 1.3;
}

.pm-grid.two-col.pm-api-admin-grid {
    grid-template-columns: minmax(320px, 0.82fr) minmax(0, 1.28fr);
}

.pm-checkbox-row {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pm-checkbox-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(24, 27, 32, 0.06);
}

.pm-checkbox-card input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--pm-primary);
}

.pm-checkbox-copy {
    display: grid;
    gap: 4px;
}

.pm-checkbox-copy strong {
    color: #1f2937;
}

.pm-checkbox-copy small {
    color: var(--pm-muted);
    line-height: 1.45;
}

.pm-code-block {
    padding: 14px 16px;
    border-radius: 16px;
    background: linear-gradient(180deg, #1f2937, #3b454f);
    color: #ffffff;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.92rem;
    line-height: 1.5;
    overflow-x: auto;
    word-break: break-all;
}

.pm-api-note-title {
    display: block;
    margin-bottom: 6px;
    color: var(--pm-muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.pm-api-key-card {
    display: grid;
    gap: 0;
}

.pm-api-key-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.pm-api-key-meta {
    display: grid;
    gap: 6px;
}

.pm-api-key-meta .pm-section-title {
    margin-bottom: 0;
}

.pm-api-key-card form + form,
.pm-api-key-card form + .pm-api-key-subsection {
    margin-top: 16px;
}

.pm-api-key-subsection {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.pm-api-key-subsection h4 {
    margin: 0;
    font-size: 1rem;
}

.pm-api-key-table-wrap {
    margin-top: 4px;
}

.pm-api-permission-table {
    min-width: 980px;
    table-layout: auto;
}

.pm-api-permission-table th:last-child,
.pm-api-permission-table td:last-child {
    width: 190px;
}

.pm-api-permission-actions {
    min-width: 176px;
}

.pm-api-permission-actions form {
    width: 100%;
}

.pm-api-empty-state {
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px dashed rgba(58, 86, 228, 0.22);
    color: var(--pm-muted);
    line-height: 1.55;
}

.pm-grid.two-col.pm-emergency-admin-grid {
    grid-template-columns: minmax(320px, 0.86fr) minmax(0, 1.14fr);
}

.pm-selection-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.pm-selection-card {
    min-height: 100%;
}

.pm-emergency-stack {
    display: grid;
    gap: 16px;
}

.pm-emergency-card,
.pm-emergency-script-card {
    display: grid;
    gap: 16px;
}

.pm-admin-disclosure {
    border: 1px solid rgba(24, 27, 32, 0.06);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.9);
    overflow: hidden;
}

.pm-admin-disclosure summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    cursor: pointer;
    list-style: none;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 248, 248, 0.94));
}

.pm-admin-disclosure summary::-webkit-details-marker {
    display: none;
}

.pm-admin-disclosure summary span:first-child {
    font-weight: 700;
    color: #1f2937;
}

.pm-admin-disclosure-body {
    display: grid;
    gap: 16px;
    padding: 18px;
    border-top: 1px solid rgba(24, 27, 32, 0.06);
}

.pm-textarea-code {
    min-height: 180px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.88rem;
    white-space: pre;
}

.pm-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.pm-metric {
    padding: 16px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(237, 240, 253, 0.88));
    border: 1px solid rgba(24, 27, 32, 0.05);
}

.pm-metric strong {
    display: block;
    margin-top: 6px;
    font-size: 1.5rem;
    font-family: var(--pm-font-display);
}

.pm-runtime-list,
.pm-tip-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pm-runtime-list li,
.pm-tip-list li {
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(24, 27, 32, 0.05);
}

.pm-runtime-list span {
    display: block;
    color: var(--pm-muted);
    font-size: 0.82rem;
}

.pm-script-grid {
    display: grid;
    gap: 14px;
}

.pm-layer-group {
    display: grid;
    gap: 12px;
}

.pm-layer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 2px;
}

.pm-layer-header h4 {
    margin: 0 0 4px;
    font-size: 1.02rem;
}

.pm-layer-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.pm-script-card {
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(24, 27, 32, 0.05);
    animation: pm-fade 220ms ease;
}

.pm-script-card header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.pm-script-card h4 {
    margin: 0;
    font-size: 1rem;
}

.pm-script-card .pm-counter {
    color: var(--pm-muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.pm-wait-break {
    display: grid;
    gap: 12px;
    padding: 16px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(237, 240, 253, 0.88), rgba(255, 255, 255, 0.92));
    border: 1px dashed rgba(58, 86, 228, 0.24);
    animation: pm-fade 220ms ease;
}

.pm-wait-break-copy h5 {
    margin: 0 0 4px;
    font-size: 0.98rem;
}

.pm-wait-break-copy p {
    margin: 0;
    color: var(--pm-muted);
}

.pm-preview-panel audio {
    width: 100%;
    margin-top: 12px;
}

.pm-preview-text {
    margin-top: 12px;
    padding: 14px;
    border-radius: 14px;
    background: rgba(249, 250, 251, 0.96);
    border: 1px dashed rgba(58, 86, 228, 0.24);
    white-space: pre-wrap;
    color: #3b454f;
}

.pm-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 18px;
    border: 1px solid rgba(24, 27, 32, 0.05);
    background: rgba(255, 255, 255, 0.88);
}

table,
.pm-record-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

thead th {
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, #1f2937, #3b454f);
    color: #ffffff;
    z-index: 1;
    font-family: var(--pm-font-display);
    font-size: 0.86rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(95, 103, 119, 0.08);
    vertical-align: top;
    text-align: left;
    overflow-wrap: anywhere;
    word-break: break-word;
}

tbody tr:nth-child(even) {
    background: rgba(248, 248, 248, 0.95);
}

tbody tr:hover {
    background: rgba(237, 240, 253, 0.85);
}

.pm-actions-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-width: 148px;
}

.pm-actions-stack .pm-button,
.pm-actions-stack button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    font-size: 0.82rem;
    width: 100%;
    min-height: 40px;
    justify-content: center;
}

.pm-record-table th:last-child,
.pm-record-table td:last-child {
    width: 170px;
}

.pm-table-script {
    white-space: normal;
}

.pm-record-token {
    display: inline-block;
    max-width: 100%;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.82rem;
    line-height: 1.45;
    color: #1f2937;
    overflow-wrap: anywhere;
}

.pm-script-preview {
    display: inline-flex;
    align-items: flex-start;
    max-width: 100%;
    cursor: help;
    color: inherit;
    text-decoration: underline dotted rgba(59, 69, 79, 0.45);
    text-underline-offset: 3px;
}

.pm-script-preview:focus-visible {
    outline: 2px solid rgba(58, 86, 228, 0.45);
    outline-offset: 3px;
    border-radius: 6px;
}

.pm-script-tooltip-panel {
    position: fixed;
    top: 0;
    left: 0;
    max-width: min(520px, calc(100vw - 32px));
    max-height: min(60vh, 420px);
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(31, 41, 55, 0.96);
    color: #f9fafb;
    border: 1px solid rgba(148, 163, 184, 0.24);
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
    white-space: pre-wrap;
    overflow-y: auto;
    line-height: 1.45;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
}

.pm-script-tooltip-panel.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.pm-highlight {
    background: rgba(45, 183, 245, 0.28);
    border-radius: 4px;
    padding: 0 2px;
}

.pm-inline-note {
    color: var(--pm-muted);
    font-size: 0.88rem;
}

.pm-hidden {
    display: none !important;
}

.pm-spacer {
    height: 8px;
}

#sidebar {
    margin: 20px;
    padding: 18px 20px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 248, 248, 0.94));
    box-shadow: var(--pm-shadow);
}

@keyframes pm-rise {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pm-fade {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@media (max-width: 1080px) {
    .pm-grid.two-col,
    .pm-grid.dashboard {
        grid-template-columns: 1fr;
    }

    .pm-api-admin-grid {
        grid-template-columns: 1fr;
    }

    .pm-emergency-admin-grid {
        grid-template-columns: 1fr;
    }

    .pm-user-table {
        min-width: 840px;
    }

    .pm-form-grid {
        grid-template-columns: 1fr;
    }

    .pm-metrics {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    body {
        padding: 0 8px;
    }

    .pm-shell {
        width: 100%;
        padding-top: 16px;
    }

    .pm-topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .pm-card-inner {
        padding: 18px;
    }

    .pm-actions,
    .pm-inline-actions,
    .pm-topbar-actions {
        width: 100%;
    }

    .pm-actions .pm-button,
    .pm-inline-actions .pm-button,
    .pm-topbar-actions .pm-button,
    .pm-actions button,
    .pm-inline-actions button,
    .pm-topbar-actions button,
    input[type="submit"],
    input[type="button"] {
        width: 100%;
        justify-content: center;
    }

    .pm-user-email-save {
        justify-self: stretch;
    }

    .pm-checkbox-row {
        grid-template-columns: 1fr;
    }

    .pm-admin-disclosure summary {
        flex-direction: column;
        align-items: flex-start;
    }
}
