:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --ink: #202124;
    --muted: #626b73;
    --line: #d8dde3;
    --accent: #00796b;
    --accent-strong: #005f56;
    --danger: #b3261e;
    --warning: #8a6d1f;
    --info: #2368a2;
    --ok: #2f7d32;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    overflow-x: hidden;
}

a {
    color: var(--accent-strong);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 24px;
    min-height: 64px;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    align-items: center;
    color: var(--ink);
    display: inline-flex;
    font-weight: 700;
    gap: 10px;
    text-decoration: none;
}

.brand-mark {
    align-items: center;
    background: var(--accent);
    border-radius: 6px;
    color: #ffffff;
    display: inline-flex;
    height: 32px;
    justify-content: center;
    width: 32px;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
}

.nav-form {
    margin: 0;
}

.language-switcher {
    align-items: center;
    display: inline-flex;
    gap: 4px;
}

.language-link {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    display: inline-flex;
    font-size: 13px;
    font-weight: 700;
    gap: 5px;
    padding: 6px 8px;
}

.topbar .language-switcher {
    margin-left: auto;
}

.login-panel > .language-switcher {
    justify-self: end;
}

.language-link__flag {
    border: 1px solid rgba(32, 33, 36, 0.22);
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
    display: inline-block;
    height: 12px;
    overflow: hidden;
    position: relative;
    width: 18px;
}

.language-link__flag--it {
    background: linear-gradient(90deg, #008c45 0 33.33%, #ffffff 33.33% 66.66%, #cd212a 66.66% 100%);
}

.language-link__flag--gb {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'%3E%3Crect width='60' height='40' fill='%23012169'/%3E%3Cpath d='M0 0 60 40M60 0 0 40' stroke='%23fff' stroke-width='8'/%3E%3Cpath d='M0 0 60 40M60 0 0 40' stroke='%23c8102e' stroke-width='4'/%3E%3Cpath d='M30 0v40M0 20h60' stroke='%23fff' stroke-width='13'/%3E%3Cpath d='M30 0v40M0 20h60' stroke='%23c8102e' stroke-width='7'/%3E%3C/svg%3E");
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

.language-link--active {
    background: #e8f3f0;
    border-color: var(--accent);
    color: var(--accent-strong);
}

.nav-link {
    border-radius: 6px;
    color: var(--muted);
    padding: 8px 10px;
}

.nav-link--button {
    background: transparent;
    border: 0;
    cursor: pointer;
    font: inherit;
}

.nav-link--active {
    background: #e8f3f0;
    color: var(--accent-strong);
}

.page {
    display: grid;
    gap: 18px;
    margin: 0 auto;
    max-width: 1280px;
    padding: 28px;
}

.page--narrow {
    max-width: 880px;
}

.auth-page {
    background: #f6f7f9;
}

.login-shell {
    align-items: center;
    display: grid;
    min-height: 100vh;
    padding: 28px;
}

.login-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 18px;
    margin: 0 auto;
    max-width: 440px;
    padding: 24px;
    width: 100%;
}

.login-brand {
    align-items: center;
    display: inline-flex;
    font-weight: 700;
    gap: 10px;
}

.login-panel h1 {
    margin: 0;
}

.setup-layout {
    align-items: start;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
}

.page-heading,
.panel-heading,
.toolbar,
.form-actions,
.filter-actions,
.pagination {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
}

.page-heading h1,
.panel-heading h2 {
    margin: 0;
}

.lede {
    color: var(--muted);
    margin: 6px 0 0;
}

.eyebrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin: 0 0 4px;
    text-transform: uppercase;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-width: 0;
    padding: 18px;
}

.trust-panel h2,
.side-info h2,
.mailbox-form h2 {
    margin: 0;
}

.trust-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
}

.trust-list,
.step-list,
.provider-help__list {
    margin: 10px 0 0;
    padding-left: 20px;
}

.trust-callout {
    background: #f4f5f6;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.trust-callout h3,
.side-info h3,
.notice h3 {
    margin: 8px 0 6px;
}

.trust-callout p,
.side-info p,
.notice p {
    margin: 0;
}

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

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

.dashboard-card {
    color: inherit;
    display: grid;
    gap: 8px;
}

.dashboard-card:hover {
    text-decoration: none;
}

.dashboard-card__value {
    font-size: 30px;
    line-height: 1;
}

.attention-list {
    display: grid;
    gap: 12px;
}

.attention-item {
    align-items: start;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: inherit;
    display: grid;
    gap: 8px;
    padding: 12px;
}

.attention-item:hover {
    text-decoration: none;
}

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

table {
    border-collapse: collapse;
    min-width: 920px;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

.actions-cell {
    text-align: right;
}

.button {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    min-height: 38px;
    padding: 8px 12px;
    text-decoration: none;
    white-space: nowrap;
}

.button:hover {
    text-decoration: none;
}

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

.button--primary:hover {
    background: var(--accent-strong);
}

.button--ghost {
    background: var(--surface);
    color: var(--ink);
}

.button--danger {
    background: #ffffff;
    border-color: #efb7b0;
    color: var(--danger);
}

.button--danger:hover {
    background: #fae6e3;
}

.button--disabled {
    background: #eef0f2;
    color: var(--muted);
    cursor: not-allowed;
}

.button:disabled {
    background: #eef0f2;
    border-color: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

.button--compact {
    min-height: 32px;
    padding: 5px 9px;
}

.badge {
    background: #eef0f2;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--ink);
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 7px;
    white-space: nowrap;
}

.badge-link {
    text-decoration: none;
}

.badge--active,
.badge--completed,
.badge--parsed,
.badge--idle,
.badge--resolved {
    background: #e4f2e5;
    border-color: #b9dfbd;
    color: var(--ok);
}

.badge--configured,
.badge--queued,
.badge--running,
.badge--pending_parse,
.badge--detected,
.badge--received,
.badge--open,
.badge--sync_failed {
    background: #e7f0f7;
    border-color: #bfd8eb;
    color: var(--info);
}

.badge--warning,
.badge--acknowledged,
.badge--review_required,
.badge--unsupported,
.badge--cancelled,
.badge--sdi_critical_event {
    background: #f6efd0;
    border-color: #e1cc78;
    color: var(--warning);
}

.badge--error,
.badge--critical,
.badge--failed,
.badge--parse_failed,
.badge--connection_failed,
.badge--document_parse_failed,
.badge--mailbox_connection_failed {
    background: #fae6e3;
    border-color: #efb7b0;
    color: var(--danger);
}

.badge--disabled {
    background: #eceff1;
    border-color: #c8d0d6;
    color: var(--muted);
}

.empty-state,
.notice {
    border-radius: 8px;
    padding: 14px;
}

.empty-state {
    background: #f4f5f6;
    color: var(--muted);
}

.notice--success {
    background: #e4f2e5;
    color: var(--ok);
}

.notice--completed {
    background: #e4f2e5;
    color: var(--ok);
}

.notice--error {
    background: #fae6e3;
    color: var(--danger);
}

.notice--critical {
    background: #fae6e3;
    color: var(--danger);
}

.notice--warning {
    background: #f6efd0;
    color: var(--warning);
}

.notice--info {
    background: #e7f0f7;
    color: var(--info);
}

.notice--configured {
    background: #e7f0f7;
    color: var(--info);
}

.notice--hidden {
    display: none;
}

.quick-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-filter {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font-weight: 700;
    padding: 8px 10px;
}

.quick-filter--active {
    background: #e8f3f0;
    border-color: var(--accent);
    color: var(--accent-strong);
}

.facts {
    display: grid;
    gap: 10px 18px;
    grid-template-columns: minmax(140px, 220px) minmax(0, 1fr);
    margin: 0;
}

.facts dt {
    color: var(--muted);
    font-weight: 700;
}

.facts dd {
    margin: 0;
}

.filters,
.form-grid {
    display: grid;
    gap: 14px;
}

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

.form-grid {
    align-items: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.form-grid--nested {
    margin-top: 14px;
}

.form-wide {
    grid-column: 1 / -1;
}

.advanced-settings {
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.advanced-settings summary {
    color: var(--accent-strong);
    cursor: pointer;
    font-weight: 700;
}

.advanced-settings__hint {
    margin: 8px 0 0;
}

.mailbox-action-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mailbox-action {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 12px;
    padding: 16px;
}

.mailbox-action__confirm {
    color: var(--ink);
}

.mailbox-action__advanced {
    margin-top: -2px;
}

.provider-help {
    background: #f4f5f6;
    border-radius: 8px;
    color: var(--muted);
    padding: 12px;
}

.provider-help p {
    margin: 6px 0 0;
}

.provider-help__links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.side-info {
    position: sticky;
    top: 82px;
}

.side-info hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 18px 0;
}

label {
    align-content: start;
    color: var(--muted);
    display: grid;
    font-weight: 700;
    gap: 6px;
    min-width: 0;
}

input,
select {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font: inherit;
    min-height: 38px;
    padding: 8px 10px;
    width: 100%;
}

.password-field {
    display: block;
    position: relative;
}

.password-field input {
    padding-right: 46px;
}

.password-toggle {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    height: 30px;
    justify-content: center;
    padding: 0;
    position: absolute;
    right: 5px;
    top: 4px;
    width: 34px;
}

.password-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.password-toggle__icon {
    border: 2px solid var(--muted);
    border-radius: 50% / 65%;
    display: inline-block;
    height: 13px;
    position: relative;
    width: 20px;
}

.password-toggle__icon::after {
    background: var(--muted);
    border-radius: 50%;
    content: "";
    height: 6px;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
}

.password-toggle--visible .password-toggle__icon {
    border-color: var(--accent-strong);
}

.password-toggle--visible .password-toggle__icon::after {
    background: var(--accent-strong);
}

.checkbox-row {
    align-items: center;
    display: flex;
    gap: 10px;
}

.checkbox-row--filter {
    align-self: end;
    min-height: 38px;
}

.checkbox-row input {
    min-height: 0;
    width: auto;
}

.form-actions,
.filter-actions,
.notice {
    grid-column: 1 / -1;
}

.form-actions {
    justify-content: flex-start;
}

.field-error {
    color: var(--danger);
    font-weight: 400;
}

.field-help {
    color: var(--muted);
    font-weight: 400;
}

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

.breakable {
    overflow-wrap: anywhere;
}

.pagination {
    align-items: end;
    justify-content: flex-start;
}

.pagination__page {
    align-self: center;
    color: var(--muted);
    font-weight: 700;
    margin-left: auto;
    min-height: 38px;
    padding: 8px 0;
}

.page-jump {
    align-items: end;
    display: flex;
    gap: 8px;
    margin: 0;
}

.page-jump label {
    min-width: 120px;
}

.page-jump input {
    width: 120px;
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.timeline {
    display: grid;
    gap: 14px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline li {
    display: grid;
    gap: 10px;
    grid-template-columns: 14px minmax(0, 1fr);
}

.timeline-dot {
    background: var(--accent);
    border-radius: 50%;
    height: 10px;
    margin-top: 6px;
    width: 10px;
}

pre {
    background: #f4f5f6;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 0;
    max-width: 100%;
    overflow: auto;
    overflow-wrap: anywhere;
    padding: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 860px) {
    .topbar,
    .page-heading,
    .panel-heading,
    .toolbar,
    .form-actions,
    .filter-actions,
    .pagination {
        align-items: stretch;
        flex-direction: column;
    }

    .page {
        padding: 18px;
    }

    .summary-grid,
    .dashboard-grid,
    .setup-layout,
    .trust-grid,
    .filters,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .side-info {
        position: static;
    }

    .facts {
        grid-template-columns: 1fr;
    }

    .button {
        justify-content: center;
        width: 100%;
    }

    .page-jump {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .page-jump input,
    .page-jump label,
    .pagination__page {
        margin-left: 0;
        width: 100%;
    }
}
