:root {
    --color-background: #F8FAFC;
    --color-card: #FFFFFF;
    --color-foreground: #0F172A;
    --color-muted-foreground: #475569;
    --color-border: #E2E8F0;
    --color-muted: #F1F5F9;
    --color-accent: #15803D;
    --color-on-accent: #FFFFFF;
    --color-accent-soft: #DCFCE7;
    --color-warning: #B45309;
    --color-warning-soft: #FEF3C7;
    --color-danger: #B91C1C;
    --color-danger-soft: #FEE2E2;
    --color-info: #1D4ED8;
    --color-info-soft: #DBEAFE;
    --color-highlight: #BE185D;
    --color-ring: #0F172A;

    --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --radius: 12px;
    --tab-bar-height: 64px;
    --transition: 150ms ease-out;

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-background: #0F172A;
        --color-card: #1B2336;
        --color-foreground: #F8FAFC;
        --color-muted-foreground: #94A3B8;
        --color-border: #334155;
        --color-muted: #272F42;
        --color-accent: #22C55E;
        --color-on-accent: #0F172A;
        --color-accent-soft: #14532D;
        --color-warning: #FBBF24;
        --color-warning-soft: #451A03;
        --color-danger: #F87171;
        --color-danger-soft: #450A0A;
        --color-info: #60A5FA;
        --color-info-soft: #172554;
        --color-highlight: #F472B6;
        --color-ring: #F8FAFC;
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--color-background);
    color: var(--color-foreground);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2 {
    margin: 0;
    line-height: 1.25;
}

h2 {
    font-size: 1.0625rem;
    font-weight: 600;
}

p {
    margin: 0;
}

code, pre {
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

a {
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--color-ring);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.muted {
    color: var(--color-muted-foreground);
}

.small {
    font-size: 0.875rem;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Layout */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: calc(env(safe-area-inset-top) + var(--space-3)) var(--space-4) var(--space-3);
    background: color-mix(in srgb, var(--color-background) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
}

.app-header__title {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
}

.app-header__icon {
    border-radius: 6px;
    outline: 1px solid var(--color-border);
    outline-offset: -1px;
}

.page {
    max-width: 640px;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4) calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + var(--space-5));
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.page:has(.toast:not([hidden])) {
    padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + var(--space-6) + 56px);
}

.page__title {
    font-size: 1.75rem;
    font-weight: 600;
}

.page__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.section-title {
    margin-top: var(--space-3);
}

.tab-bar {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--color-card);
    border-top: 1px solid var(--color-border);
}

.tab-bar__item {
    flex: 1;
    max-width: 160px;
    min-height: var(--tab-bar-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--color-muted-foreground);
    font-size: 0.75rem;
    font-weight: 500;
    text-decoration: none;
    transition: color var(--transition);
}

.tab-bar__item[aria-current="page"] {
    color: var(--color-accent);
}

/* Components */

.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-4);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.stack--tight {
    gap: var(--space-1);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-card);
    color: var(--color-foreground);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--transition), opacity var(--transition);
}

@media (hover: hover) {
    .button:hover {
        background: var(--color-muted);
    }
}

.button:active {
    background: var(--color-muted);
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button--primary {
    border-color: var(--color-accent);
    background: var(--color-accent);
    color: var(--color-on-accent);
}

@media (hover: hover) {
    .button--primary:hover {
        background: color-mix(in srgb, var(--color-accent) 88%, var(--color-foreground));
    }
}

.button--primary:active {
    background: color-mix(in srgb, var(--color-accent) 88%, var(--color-foreground));
}

.button--block {
    width: 100%;
}

.button--icon {
    width: 44px;
    padding: 0;
}

.button--danger {
    border-color: color-mix(in srgb, var(--color-danger) 45%, var(--color-border));
    color: var(--color-danger);
}

.button--danger:active {
    background: var(--color-danger-soft);
}

@media (hover: hover) {
    .button--danger:hover {
        background: var(--color-danger-soft);
    }
}

/* Copy buttons turn into a tick for a moment once they've copied. */

.button--copy {
    border-color: transparent;
    background: var(--color-info-soft);
    color: var(--color-info);
}

.button--copy[data-copied] {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.button--copy__done,
.button--copy[data-copied] .button--copy__idle {
    display: none;
}

.button--copy[data-copied] .button--copy__done {
    display: block;
}

.button--quiet {
    border-color: transparent;
    background: transparent;
    color: var(--color-muted-foreground);
}

.badge {
    display: inline-block;
    padding: 1px var(--space-2);
    border-radius: 999px;
    background: var(--color-muted);
    color: var(--color-muted-foreground);
    font-size: 0.75rem;
    font-weight: 500;
    vertical-align: middle;
    white-space: nowrap;
}

.badge--accent {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.badge--priority-1 {
    background: var(--color-warning-soft);
    color: var(--color-warning);
}

.badge--priority-2 {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.flash {
    padding: var(--space-3) var(--space-4);
    border-radius: 10px;
    background: var(--color-muted);
}

.flash--success {
    background: var(--color-accent-soft);
}

.flash--error {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.status {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
}

.status--ok {
    color: var(--color-accent);
}

.status--warning {
    color: var(--color-warning);
}

/* Forms */

.form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.field label {
    font-weight: 500;
}

.field input {
    min-height: 44px;
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-background);
    color: var(--color-foreground);
    font: inherit;
}

.field input[aria-invalid="true"] {
    border-color: var(--color-danger);
}

.field__error {
    color: var(--color-danger);
    font-size: 0.875rem;
}

.field__help {
    color: var(--color-muted-foreground);
    font-size: 0.875rem;
}

/* Login */

.login {
    max-width: 400px;
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 12vh) var(--space-4) var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.login__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    text-align: center;
}

.login__brand img {
    border-radius: 14px;
}

/* Inbox */

.message-list,
.device-list,
.plain-list,
.steps {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.inbox,
.inbox__messages {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-width: 0;
}

.page__heading {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.app-filter__toggle {
    margin-left: calc(-1 * var(--space-2));
}

/* The app filter: a menu that slides in from the side on phones. */

.app-filter {
    inset: 0 auto 0 0;
    width: min(320px, 85vw);
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: calc(env(safe-area-inset-top) + var(--space-3)) var(--space-3) calc(env(safe-area-inset-bottom) + var(--space-3)) calc(env(safe-area-inset-left) + var(--space-3));
    overflow-y: auto;
    border: 0;
    border-right: 1px solid var(--color-border);
    background: var(--color-card);
    color: var(--color-foreground);
    transition: translate 200ms ease-out, overlay 200ms allow-discrete, display 200ms allow-discrete;
}

.app-filter:not(:popover-open) {
    translate: -100% 0;
}

@starting-style {
    .app-filter:popover-open {
        translate: -100% 0;
    }
}

.app-filter::backdrop {
    background: rgb(15 23 42 / 0.5);
}

body:has(.app-filter:popover-open) {
    overflow: hidden;
}

.app-filter__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 var(--space-2) var(--space-2);
}

.app-filter__list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-filter__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 48px;
    padding: var(--space-2);
    border-radius: 8px;
    color: var(--color-foreground);
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color var(--transition);
}

.app-filter__item:active {
    background: var(--color-muted);
}

@media (hover: hover) {
    .app-filter__item:not([aria-current="page"]):hover {
        background: var(--color-muted);
    }
}

.app-filter__item[aria-current="page"] {
    background: var(--color-accent-soft);
    font-weight: 600;
}

.app-filter__name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.app-filter__count {
    flex-shrink: 0;
    min-width: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--color-accent);
    color: var(--color-on-accent);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* The one chip on phones: what the inbox shows, and the way to change it. */

.app-filter__selection {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 100%;
    min-height: 44px;
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-4);
    border: 1px solid var(--color-accent);
    border-radius: 999px;
    background: var(--color-accent-soft);
    color: var(--color-foreground);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.app-filter__selection .app-filter__name {
    flex: 0 1 auto;
}

.app-filter__selection .icon {
    width: 18px;
    height: 18px;
}

/* The first letter of an app on its own colour; each pairs with white text at 4.5:1 or more. */

.avatar {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: #FFFFFF;
    font-size: 0.875rem;
    font-weight: 600;
}

.avatar .icon {
    width: 18px;
    height: 18px;
}

.avatar--all {
    background: var(--color-muted);
    color: var(--color-foreground);
}

.avatar--0 {
    background: #1D4ED8;
}

.avatar--1 {
    background: #7E22CE;
}

.avatar--2 {
    background: #BE185D;
}

.avatar--3 {
    background: #0F766E;
}

.avatar--4 {
    background: #C2410C;
}

.avatar--5 {
    background: #4338CA;
}

.avatar--6 {
    background: #A21CAF;
}

.avatar--7 {
    background: #0369A1;
}

/* An uploaded icon; the faint inner line keeps white icons visible on a white card. */

.avatar--image {
    object-fit: cover;
    background: var(--color-card);
    outline: 1px solid var(--color-border);
    outline-offset: -1px;
}

.avatar--large {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1rem;
}

/* On wider screens the app filter is always there, as a sidebar beside the messages. */

@media (min-width: 768px) {
    .page:has(.inbox--with-apps) {
        max-width: 1040px;
        padding-inline: var(--space-5);
    }

    .inbox--with-apps {
        display: grid;
        grid-template-columns: 260px minmax(0, 1fr);
        align-items: start;
        gap: var(--space-5);
    }

    .app-filter,
    .app-filter:not(:popover-open) {
        position: sticky;
        inset: auto;
        top: calc(env(safe-area-inset-top) + 72px);
        z-index: auto;
        display: block;
        width: auto;
        height: auto;
        max-height: calc(100dvh - env(safe-area-inset-top) - var(--tab-bar-height) - env(safe-area-inset-bottom) - 96px);
        padding: var(--space-2);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        translate: none;
        transition: none;
    }

    .app-filter__header,
    .app-filter__toggle,
    .app-filter__selection {
        display: none;
    }
}


.message {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding-right: var(--space-2);
    border-left-width: 4px;
}

.message__avatar {
    margin-top: 2px;
}

.message__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.message__delete {
    margin-top: calc(var(--space-2) * -1);
    color: var(--color-danger);
}

.message__delete:active {
    background: var(--color-danger-soft);
}

@media (hover: hover) {
    .message__delete:hover {
        background: var(--color-danger-soft);
    }
}

.message__unread-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    vertical-align: middle;
}

.message--priority-1 {
    border-left-color: var(--color-warning);
}

.message--priority-2 {
    border-left-color: var(--color-danger);
}

.message--priority--1,
.message--priority--2 {
    opacity: 0.85;
}

.message__meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    color: var(--color-muted-foreground);
    font-size: 0.8125rem;
}

.message__app {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    font-weight: 500;
    overflow-wrap: anywhere;
}

.message__meta time {
    flex-shrink: 0;
    white-space: nowrap;
}

.message__title {
    font-size: 1rem;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.message--unread .message__app,
.message--unread .message__title {
    color: var(--color-foreground);
    font-weight: 600;
}

.message__body {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.message__link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 44px;
    color: var(--color-accent);
    font-weight: 500;
    overflow-wrap: anywhere;
}

.message__link .icon {
    width: 16px;
    height: 16px;
}

.toast {
    position: fixed;
    inset: auto var(--space-4) calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + var(--space-3));
    z-index: 20;
    max-width: 608px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
    border-radius: 10px;
    background: var(--color-foreground);
    color: var(--color-background);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}

.toast__action {
    min-height: 44px;
    padding: 0 var(--space-3);
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-6) var(--space-4);
    text-align: center;
}

.empty__icon {
    width: 40px;
    height: 40px;
    color: var(--color-muted-foreground);
}

/* Devices */

.push-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.push-panel > div {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.steps {
    counter-reset: step;
    gap: var(--space-2);
}

.steps li {
    counter-increment: step;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.steps li::before {
    content: counter(step);
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-muted);
    font-size: 0.8125rem;
    font-weight: 600;
}

.device {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
}

.device__info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.device__name {
    font-weight: 500;
    overflow-wrap: anywhere;
}

.device__actions {
    display: flex;
    gap: var(--space-2);
}

/* Apps */

.application {
    justify-content: flex-start;
}

.application .device__info {
    flex: 1;
}

/* The app's icon is the button that picks a new one, with a pencil to say so. */

.icon-picker__label {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    cursor: pointer;
    transition: opacity 150ms ease-out;
}

.icon-picker__input:focus-visible + .icon-picker__label {
    outline: 2px solid var(--color-ring);
    outline-offset: 2px;
}

.icon-picker[aria-busy="true"] .icon-picker__label {
    opacity: 0.5;
    pointer-events: none;
}

.icon-picker__badge {
    position: absolute;
    right: -2px;
    bottom: -2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-card);
    border-radius: 50%;
    background: var(--color-foreground);
    color: var(--color-card);
}

.icon-picker__badge .icon {
    width: 11px;
    height: 11px;
}

.application .field__error {
    margin-top: var(--space-1);
}

.issued-token {
    border: 1px solid var(--color-warning);
}

.device--inactive .device__name {
    color: var(--color-muted-foreground);
}

/* Account */

.copy-field {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.copy-field code {
    flex: 1;
    min-width: 0;
    padding: var(--space-3);
    border-radius: 10px;
    background: var(--color-muted);
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
}

.code {
    margin: 0;
    padding: var(--space-3);
    border-radius: 10px;
    background: var(--color-muted);
    overflow-x: auto;
}

/* Hand-applied highlighting; each colour keeps 4.5:1 on the code background in both themes. */

.code__command {
    color: var(--color-accent);
    font-weight: 600;
}

.code__url,
.code__value {
    color: var(--color-info);
}

.code__flag {
    color: var(--color-warning);
}

.code__placeholder {
    color: var(--color-highlight);
    font-family: var(--font-mono);
    font-weight: 600;
}

.code__header {
    color: var(--color-foreground);
}

.integration__heading {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.integration__logo {
    width: 32px;
    height: auto;
    flex-shrink: 0;
}

.plain-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
