@font-face {
    font-family: "Newsreader";
    font-style: normal;
    font-display: swap;
    font-weight: 200 800;
    src: url("../fonts/newsreader-latin-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Newsreader";
    font-style: italic;
    font-display: swap;
    font-weight: 200 800;
    src: url("../fonts/newsreader-latin-wght-italic.woff2") format("woff2-variations");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Newsreader";
    font-style: normal;
    font-display: swap;
    font-weight: 200 800;
    src: url("../fonts/newsreader-latin-ext-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-display: swap;
    font-weight: 100 700;
    src: url("../fonts/ibm-plex-sans-latin-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-display: swap;
    font-weight: 100 700;
    src: url("../fonts/ibm-plex-sans-latin-ext-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
    color-scheme: light;
    --ink: #1f2937;
    --ink-soft: #374151;
    --muted: #6b7280;
    --line: #e5e7eb;
    --paper: #f4f5f7;
    --card: #ffffff;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #e0e7ff;
    --danger: #b91c1c;
    --warn: #b45309;
    --ok: #047857;
    --sidebar: #2f3136;
    --sidebar-inner: #393c43;
    --sidebar-text: #d1d5db;
    --sidebar-active: #ffffff;
    --radius: 0.5rem;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--paper);
    color: var(--ink);
    line-height: 1.45;
}
a { color: var(--accent); }
img, svg { max-width: 100%; }

.app-shell {
    display: grid;
    grid-template-columns: 16rem 1fr;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
}
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    min-height: 0;
    overflow: hidden;
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
    text-decoration: none;
    padding: 0 1rem;
    height: 4rem;
    border-bottom: 1px solid #4b5563;
    flex: 0 0 auto;
}
.brand-mark {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    letter-spacing: -0.04em;
    flex: 0 0 auto;
}
.brand strong { font-size: 0.95rem; color: #fff; font-weight: 600; letter-spacing: 0.02em; }
.brand-copy { min-width: 0; }
.brand-copy span {
    display: block;
    font-size: 0.72rem;
    color: #9ca3af;
    font-weight: 500;
}

.company-switch {
    background: transparent;
    border-radius: 0;
    padding: 1rem;
    border-bottom: 1px solid #4b5563;
}
.company-switch label {
    margin: 0 0 0.5rem;
    color: #6b7280;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.company-switch select {
    width: 100%;
    margin: 0;
    background: var(--sidebar-inner);
    color: #fff;
    border: 1px solid #4b5563;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    padding-right: 2rem;
}
.company-switch .row-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
    align-items: center;
}
.company-switch button {
    margin: 0;
    padding: 0.35rem 0.6rem;
    background: var(--accent);
    font-size: 0.85rem;
}
.company-switch a {
    color: #a5b4fc;
    font-size: 0.85rem;
    text-decoration: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem 0.5rem;
}
.sidebar-nav a,
.sidebar-nav .nav-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #9ca3af;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
}
.sidebar-nav a:hover,
.sidebar-nav .nav-btn:hover { background: var(--sidebar-inner); color: #fff; }
.sidebar-nav a.active {
    background: var(--sidebar-inner);
    color: var(--sidebar-active);
}
.sidebar-nav a.active svg { color: #818cf8; }
.sidebar-nav svg { flex: 0 0 1.15rem; color: #6b7280; }
.sidebar-nav a:hover svg { color: #d1d5db; }
.sidebar-foot {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid #4b5563;
}
.logout-form button.nav-btn {
    width: 100%;
    margin: 0;
    background: transparent;
    color: #9ca3af;
    text-align: left;
    border: 0;
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0;
}
.logout-form button.nav-btn:hover { color: #fff; }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.workspace-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    height: 4rem;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--line);
    background: var(--card);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    flex: 0 0 auto;
    z-index: 2;
}
.workspace-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0;
    color: #1f2937;
}
.workspace-bar strong { display: block; font-size: 0.92rem; }
.workspace-bar .muted { font-size: 0.82rem; }
.workspace-user { text-align: right; }
.workspace-main {
    padding: 1.5rem;
    max-width: 78rem;
    width: 100%;
    overflow-y: auto;
    flex: 1 1 auto;
}
.workspace-main--wide { max-width: none; }

.doc-split {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}
.doc-split-main { min-width: 0; }
.doc-preview {
    position: sticky;
    top: 0.75rem;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: calc(100vh - 1.5rem);
    height: calc(100vh - 1.5rem);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.doc-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    flex: 0 0 auto;
}
.doc-preview-bar strong { font-size: 0.9rem; }
.doc-preview-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.28rem;
    min-width: 0;
}
.doc-preview-tabs a {
    padding: 0.28rem 0.55rem;
    border-radius: 0.4rem;
    text-decoration: none;
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-weight: 600;
    background: #e2e8f0;
}
.doc-preview-tabs a.is-active {
    background: var(--accent);
    color: #fff;
}
.doc-preview-open {
    margin-left: auto;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.doc-preview-frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 0;
    background: #d6d3d1;
}
.doc-preview-empty {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    color: var(--muted);
    text-align: center;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.lede { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.95rem; }
.page-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.page-actions .btn,
.page-actions button { margin: 0; }

h1 { font-size: 1.45rem; margin: 0 0 0.75rem; letter-spacing: -0.03em; }
h2 { font-size: 1.02rem; margin: 0 0 0.65rem; }
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
.kpi {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.kpi-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}
.kpi-icon svg { width: 1.5rem; height: 1.5rem; }
.kpi-icon--draft { background: #e0e7ff; color: #4f46e5; }
.kpi-icon--open { background: #dbeafe; color: #2563eb; }
.kpi-icon--warn { background: #fef3c7; color: #d97706; }
.kpi-icon--ok { background: #d1fae5; color: #059669; }
.kpi-icon--xml { background: #e0e7ff; color: #4338ca; }
.kpi-icon--mail { background: #ede9fe; color: #6d28d9; }
.kpi-icon--quarantine { background: #fef3c7; color: #b45309; }
.kpi-grid--xml {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.kpi .label { color: var(--muted); font-size: 0.875rem; font-weight: 500; text-transform: none; letter-spacing: 0; margin: 0; }
.kpi .value { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; margin-top: 0.1rem; color: #111827; }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

label { display: block; font-weight: 600; margin: 0.75rem 0 0.25rem; color: var(--ink-soft); }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    padding: 0.5rem 0.7rem;
    background: #fff;
}
input[type=checkbox] { width: auto; display: inline; margin-right: 0.4rem; }
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 1rem;
    padding: 0.5rem 0.9rem;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 0.5rem;
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
}
button:hover, .btn:hover { background: var(--accent-hover); color: #fff; }
button.secondary, a.btn.secondary {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    margin-left: 0;
}
button.secondary:hover, a.btn.secondary:hover { background: #f9fafb; color: var(--ink); }
button.danger { background: var(--danger); }
.card form > button:first-of-type,
.card .page-actions { margin-top: 0.25rem; }

.errors, .flash-error { color: var(--danger); }
.flash-ok, .flash {
    background: #ecfdf5;
    color: var(--ok);
    border: 1px solid #a7f3d0;
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    margin: 0 0 1rem;
}
.errors.card { background: #fef2f2; border-color: #fecaca; }
.pill {
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    background: #e2e8f0;
    color: var(--ink-soft);
    margin-right: 0.25rem;
}
.pill-draft { background: #e2e8f0; }
.pill-ok { background: #d1fae5; color: #065f46; }
.pill-warn { background: #ffedd5; color: #9a3412; }
.pill-danger { background: #fee2e2; color: #991b1b; }
.pill-muted { background: #f1f5f9; color: var(--muted); }

table.checks, table.data, table.lines { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.checks th, table.checks td,
table.data th, table.data td,
table.lines th, table.lines td {
    text-align: left;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.data thead th {
    background: #f9fafb;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    white-space: nowrap;
}
table.data tbody tr:hover { background: #f9fafb; }
table.data tbody td { color: #374151; }
table.lines input, table.lines select { width: 100%; margin: 0; }
.ok { color: var(--ok); }
.fail { color: var(--danger); }
.status-ok { color: var(--ok); font-weight: 700; }
.status-fail { color: var(--danger); font-weight: 700; }
.status-warn { color: var(--warn); font-weight: 700; }
.check-group {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin: 1rem 0 0.35rem;
}
.muted { color: var(--muted); }
.note { font-size: 0.92rem; color: var(--muted); }
code { font-family: ui-monospace, monospace; font-size: 0.9em; }
details.card > summary { cursor: pointer; font-weight: 700; margin-bottom: 0.5rem; }
details.card[open] > summary { margin-bottom: 0.75rem; }

.guest-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, #a5b4fc 0, transparent 28%),
        linear-gradient(180deg, #2f3136 0 38%, var(--paper) 38%);
    display: grid;
    place-items: start center;
    padding: 3rem 1rem 2rem;
}
.guest-shell { width: min(32rem, 100%); }
.guest-shell.wide { width: min(46rem, 100%); }
.guest-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: #fff;
    margin-bottom: 1.25rem;
}
.guest-brand .brand-mark { width: 2.3rem; height: 2.3rem; }
.guest-brand strong { font-size: 1.2rem; }
.guest-brand span { display: block; font-size: 0.82rem; color: #c7d2fe; }

.settings-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 0 1rem;
}
.settings-nav a {
    display: inline-flex;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: #e2e8f0;
    color: var(--ink-soft);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}
.settings-nav a.active,
.settings-nav a:hover { background: var(--accent); color: #fff; }

@media (max-width: 1100px) {
    .doc-split { grid-template-columns: 1fr; }
    .doc-preview {
        position: static;
        height: 72vh;
        min-height: 28rem;
    }
}
@media (max-width: 960px) {
    .kpi-grid,
    .kpi-grid--xml { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
    .app-shell { grid-template-columns: 1fr; height: auto; overflow: visible; }
    .sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.6rem;
        padding: 0;
        overflow: visible;
    }
    .brand { height: auto; padding: 0.7rem 0.8rem; border-bottom: 0; }
    .company-switch { border-bottom: 0; flex: 1 1 14rem; }
    .sidebar-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        flex: 1 1 100%;
        order: 3;
        padding: 0.4rem 0.5rem 0.7rem;
    }
    .sidebar-nav a, .logout-form button.nav-btn { white-space: nowrap; }
    .sidebar-foot {
        margin: 0;
        margin-left: auto;
        padding: 0.7rem 0.8rem;
        border-top: 0;
    }
    .workspace { height: auto; }
    .workspace-main { padding: 1rem; overflow: visible; }
}
@media (max-width: 640px) {
    .row { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}

.guest-body.is-login {
    padding: 0;
    display: block;
    background-color: #1e1b4b;
    background-image:
        radial-gradient(ellipse 90% 70% at 18% -8%, rgba(99, 102, 241, 0.55), transparent 58%),
        radial-gradient(ellipse 80% 60% at 98% 108%, rgba(67, 56, 202, 0.5), transparent 52%),
        linear-gradient(165deg, #1e1b4b 0%, #312e81 48%, #1e1b4b 100%);
    font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}
.skip-login {
    position: absolute;
    left: -999px;
    top: 0.75rem;
    z-index: 20;
    background: #fff;
    color: var(--ink);
    padding: 0.45rem 0.75rem;
    border-radius: 0.4rem;
    font-weight: 600;
}
.skip-login:focus {
    left: 0.75rem;
}
.login-stage {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.4rem;
    padding: 2rem 1rem;
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: #fff;
}
.login-brand .brand-mark {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 0.95rem;
    box-shadow: 0 0 0 7px rgba(99, 102, 241, 0.18);
}
.login-brand strong {
    font-size: 1.35rem;
    letter-spacing: -0.03em;
    color: #fff;
}
.login-card {
    width: min(24.5rem, 100%);
    margin: 0;
    background: #fff;
    border: 0;
    border-radius: 1.1rem;
    padding: 1.55rem 1.45rem 1.45rem;
    box-shadow: 0 24px 60px rgba(2, 12, 16, 0.38);
}
.login-card h1 {
    margin: 0 0 1.1rem;
    font-family: "Newsreader", Georgia, serif;
    font-size: 1.85rem;
    font-weight: 550;
    letter-spacing: -0.03em;
}
.login-alert {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: 0.65rem;
    padding: 0.7rem 0.85rem;
    margin: 0 0 1rem;
    font-weight: 600;
}
.login-card label { margin-top: 0.85rem; }
.login-card label:first-of-type { margin-top: 0; }
.login-card input[type="text"],
.login-card input[type="password"] {
    padding: 0.72rem 0.85rem;
    background: #fff;
    border-color: #d5dbe3;
}
.login-card input:focus {
    background: #fff;
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}
.login-check {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 1rem 0 0;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
}
.login-check input {
    width: 1.05rem;
    height: 1.05rem;
    margin: 0;
    accent-color: var(--accent);
}
.login-card button[type="submit"] {
    width: 100%;
    margin-top: 1.2rem;
    padding: 0.78rem 1rem;
    border-radius: 0.7rem;
    font-size: 1rem;
    box-shadow: 0 10px 22px rgba(79, 70, 229, 0.28);
}
.login-brand, .login-card {
    animation: login-rise 0.5s ease both;
}
.login-card { animation-delay: 0.06s; }
@keyframes login-rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .login-brand, .login-card { animation: none; }
}
