:root {
    color-scheme: light;
    --bg: #f3f6fa;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --ink: #101828;
    --muted: #667085;
    --line: #d8e0ea;
    --line-soft: #edf2f7;
    --brand: #0f766e;
    --brand-dark: #0b5f59;
    --brand-soft: #e6f4f1;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --ok: #087443;
    --ok-bg: #e9f7ef;
    --warn: #b45309;
    --warn-bg: #fff7ed;
    --off-bg: #eef2f6;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 14px 36px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.10);
    --sidebar: 284px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top left, #ffffff 0, var(--bg) 38%, #eef3f8 100%);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; opacity: .55; }
.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; }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #f5f7fb;
}
.login-panel {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    padding: 34px;
}
.login-panel h1 { margin: 18px 0 4px; font-size: 34px; line-height: 1.1; }
.login-panel p { margin: 0 0 24px; color: var(--muted); }
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    background: rgba(255, 255, 255, 0.96);
    border-right: 1px solid var(--line);
    padding: 22px;
    box-shadow: 8px 0 28px rgba(16, 24, 40, 0.04);
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; font-size: 19px; }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 750;
    border: 1px solid transparent;
}
.sidebar nav a .icon, .user-box a .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.sidebar nav a.active, .sidebar nav a:hover { color: var(--brand); background: var(--brand-soft); border-color: #cfe8e3; }
.sidebar nav a.active { box-shadow: inset 3px 0 0 var(--brand); }
.user-box {
    margin-top: auto;
    color: var(--muted);
    font-size: 14px;
    padding-top: 18px;
    border-top: 1px solid var(--line-soft);
}
.user-menu summary { list-style: none; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu-button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-weight: 800;
    cursor: pointer;
}
.user-menu-icon {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: var(--brand-soft);
    border: 1px solid #cfe8e3;
    position: relative;
    flex: 0 0 26px;
}
.user-menu-icon::before {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--brand);
    top: 5px;
    left: 8px;
}
.user-menu-icon::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 7px;
    border-radius: 999px 999px 0 0;
    background: var(--brand);
    left: 5px;
    bottom: 5px;
}
.user-menu-panel { display: none; gap: 8px; padding: 10px 2px 0; }
.user-menu[open] .user-menu-panel { display: grid; }
.user-menu-panel small { color: var(--muted); line-height: 1.35; padding: 0 8px; }
.user-box a { display: inline-flex; align-items: center; gap: 8px; color: var(--brand); font-weight: 750; padding: 5px 8px; border-radius: 7px; }
.user-box a:hover { background: var(--brand-soft); }

.app-shell {
    margin-left: var(--sidebar);
    padding: 30px;
    max-width: 1480px;
}
.page-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.page-header h1 { margin: 0; font-size: 30px; line-height: 1.16; }
.page-header p { margin: 6px 0 0; color: var(--muted); }
.back-link { display: inline-flex; color: var(--brand); font-weight: 750; margin-bottom: 8px; }

.form-card, .table-card, .info-card, .validation-card {
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    margin-bottom: 22px;
}
.form-card { padding: 22px; }
.form-card h2 { margin: 0 0 18px; font-size: 18px; }
.stack-form, .grid-form { display: grid; gap: 14px; }
.grid-form { grid-template-columns: repeat(4, minmax(180px, 1fr)); align-items: end; }
.report-filter .grid-form { grid-template-columns: minmax(220px, 1fr) 180px auto auto; }
label { display: grid; gap: 7px; color: #344054; font-weight: 700; font-size: 13px; }
input, select {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus { outline: 3px solid #c7ebe7; border-color: var(--brand); }
label.is-muted { opacity: .62; }

.primary, button.danger, .icon-btn, .plain-link {
    min-height: 40px;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 9px 13px;
    font-weight: 800;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.primary:hover { background: var(--brand-dark); transform: translateY(-1px); }
button.danger { background: var(--danger-bg); color: var(--danger); border-color: #ffd1cc; }
button.danger:hover { background: #ffe7e3; border-color: #ffb4aa; }
.icon-btn, .plain-link { background: #f8fafc; border-color: var(--line); color: #344054; }
.icon-btn:hover, .plain-link:hover { border-color: var(--brand); color: var(--brand); background: #fff; transform: translateY(-1px); }
.primary .icon, button.danger .icon, .icon-btn .icon, .plain-link .icon, .back-link .icon {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    stroke-width: 2.2;
}
.grid-form > .primary, .grid-form > button.primary {
    justify-self: start;
    min-width: 150px;
}

.settings-card form { display: block; }
.settings-tab-input { position: absolute; opacity: 0; pointer-events: none; }
.settings-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 20px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel-soft);
}
.settings-tab {
    min-height: 36px;
    padding: 8px 14px;
    border-radius: 7px;
    color: var(--muted);
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}
#settings-tab-smtp:checked ~ .settings-tabs label[for="settings-tab-smtp"],
#settings-tab-connection:checked ~ .settings-tabs label[for="settings-tab-connection"] {
    color: var(--brand);
    background: #fff;
    box-shadow: var(--shadow-sm);
}
.settings-panel { display: none; }
#settings-tab-smtp:checked ~ .settings-panel-smtp,
#settings-tab-connection:checked ~ .settings-panel-connection { display: block; }
.settings-panel h2 { margin: 0 0 18px; font-size: 18px; }
.compact-settings-form { grid-template-columns: repeat(2, minmax(180px, 260px)); }
.settings-actions { margin-top: 18px; }

.password-field { position: relative; display: block; }
.password-field input { width: 100%; padding-right: 46px; }
.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}
.password-toggle:hover { color: var(--brand); background: #f8fafc; transform: translateY(-50%); }
.password-toggle .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.primary, button.danger, .icon-btn, .plain-link, .sidebar nav a, .user-box a { transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease; }
.primary:focus-visible, button.danger:focus-visible, .icon-btn:focus-visible, .plain-link:focus-visible, .sidebar nav a:focus-visible, .user-box a:focus-visible { outline: 3px solid #c7ebe7; outline-offset: 2px; }
.icon-only {
    width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    position: relative;
}
.icon-only .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.icon-only:hover::after, .icon-only:focus-visible::after {
    content: attr(aria-label);
    position: absolute;
    z-index: 5;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%);
    background: #101828;
    color: #fff;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
}

.table-card { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:hover { background: #fbfcfe; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #fbfcfe; letter-spacing: .02em; }
th a { color: var(--muted); }
th a:hover { color: var(--brand); }
td { font-size: 14px; }
th:last-child, td:last-child { min-width: 180px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 150px; }
.actions form { margin: 0; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 800; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.off { background: var(--off-bg); color: #475467; }
.empty-state { color: var(--muted); text-align: center; padding: 28px; }
.alert {
    border-radius: 10px;
    padding: 13px 15px;
    margin-bottom: 16px;
    border: 1px solid #bae6fd;
    background: #eef9ff;
    color: #075985;
    font-weight: 700;
}
.alert.danger { border-color: #fecaca; background: #fff1f0; color: var(--danger); }

.info-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.info-grid.compact { grid-template-columns: repeat(2, minmax(180px, 260px)); }
.info-card { padding: 18px; }
.info-card span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; margin-bottom: 8px; }
.info-card strong { display: block; color: var(--ink); font-size: 22px; }
.brand strong { letter-spacing: 0; }
.user-box a { display: inline-flex; align-items: center; gap: 8px; color: var(--brand); font-weight: 750; }

.validation-card { border-left: 6px solid var(--brand); padding: 24px; }
.validation-card h2 { margin: 0 0 8px; font-size: 26px; }
.validation-card p { margin: 0 0 20px; color: var(--muted); font-weight: 700; }
.validation-card.ok { border-left-color: #16a34a; }
.validation-card.used { border-left-color: #f59e0b; }
.validation-card.danger { border-left-color: var(--danger); }
.validation-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 14px; }
.validation-grid div { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #fbfcfe; }
.validation-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; margin-bottom: 6px; }
.validation-grid strong { color: var(--ink); font-size: 16px; }

@media (max-width: 1100px) {
    .grid-form { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    .report-filter .grid-form { grid-template-columns: 1fr 180px auto auto; }
}

@media (max-width: 920px) {
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 10;
        width: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 12px 16px;
        gap: 12px;
    }
    .brand { justify-content: space-between; }
    .sidebar nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
    .sidebar nav a { flex: 0 0 auto; min-height: 38px; padding: 8px 10px; }
    .user-box { margin-top: 0; padding-top: 10px; }
    .user-menu-panel small { padding: 0 8px; }
    .app-shell { margin-left: 0; padding: 18px; }
    .page-header { align-items: flex-start; }
}

@media (max-width: 740px) {
    body { background: #fff; }
    .login-panel { padding: 24px; }
    .page-header { display: grid; gap: 12px; }
    .page-header h1 { font-size: 25px; }
    .grid-form, .report-filter .grid-form, .info-grid, .info-grid.compact, .validation-grid { grid-template-columns: 1fr; }
    .settings-tabs { display: flex; width: 100%; }
    .settings-tab { flex: 1; justify-content: center; }
    .group-suggestions { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
    .group-suggestions button { flex: 0 0 auto; }

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

    .grid-form > .primary, .grid-form > button.primary { justify-self: stretch; width: 100%; }
    .form-card, .table-card, .info-card, .validation-card { border-radius: 8px; box-shadow: none; }
    .table-card { overflow: visible; border: 0; background: transparent; }
    table { min-width: 0; border-collapse: separate; border-spacing: 0 12px; }
    thead { display: none; }
    tbody, tr, td { display: block; width: 100%; }
    tr { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-sm); padding: 10px 0; }
    td { border-bottom: 0; padding: 9px 14px; display: grid; grid-template-columns: minmax(118px, 38%) 1fr; gap: 10px; align-items: center; }
    .invitations-table tr { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; }
    .invitations-table td { display: block; padding: 8px 14px; }
    .invitations-table td::before { display: block; margin-bottom: 3px; }
    .invitations-table td:nth-child(1) { grid-column: 1; }
    .invitations-table td:nth-child(2) { grid-column: 2; text-align: right; }
    .invitations-table td:nth-child(3) { grid-column: 1 / -1; }
    .invitations-table td:nth-child(4) { grid-column: 1; }
    .invitations-table td:nth-child(5) { grid-column: 2; text-align: right; }
    .invitations-table td:last-child { grid-column: 1 / -1; }
    .invitations-table .actions { justify-content: flex-start; }
    .bar-row { grid-template-columns: 1fr auto; }
    .bar-track { grid-column: 1 / -1; }
    td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
    td:last-child { min-width: 0; }
    .actions { min-width: 0; justify-content: flex-end; }
    .empty-state { display: block; text-align: center; }
    .empty-state::before { content: none; }
    .icon-only:hover::after, .icon-only:focus-visible::after { display: none; }
}

@media (max-width: 480px) {
    .sidebar { padding: 12px; }
    .app-shell { padding: 14px; }
    .user-box { width: 100%; }
    td { grid-template-columns: 1fr; gap: 4px; }
    .actions { justify-content: flex-start; }
}

.token-input {
    display: flex;
    align-items: center;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 4px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.token-input:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}
.token-input input {
    border: 0;
    box-shadow: none;
    min-height: 34px;
    padding: 6px 8px;
    width: 100%;
}
.token-input input:focus { outline: 0; }

.group-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.group-suggestions button {
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: #344054;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 800;
}
.group-suggestions button:hover,
.group-suggestions button:focus-visible {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-soft);
}
.group-suggestions button[hidden] { display: none; }


.report-card { display: block; color: inherit; text-decoration: none; cursor: pointer; }
.report-card:hover { border-color: var(--brand); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.chart-card { padding: 20px; }
.bar-chart { display: grid; gap: 12px; margin-bottom: 22px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr 54px; gap: 12px; align-items: center; }
.bar-label { font-weight: 800; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 16px; border-radius: 999px; background: #eef2f6; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), #14b8a6); }
.invitations-table table { min-width: 760px; }
.invitation-filter { margin-bottom: 16px; }

.mobile-toggle { display: inline-flex; }
.invitation-form-card:not(.is-editing):not(.is-open) { display: none; }
.sort-link { display: inline-flex; align-items: center; gap: 6px; }
.sort-link::after { content: "-"; font-size: 12px; color: #98a2b3; }
.sort-link.active.asc::after { content: "^"; color: var(--brand); }
.sort-link.active.desc::after { content: "v"; color: var(--brand); }


@media (max-width: 740px) {
    .invitations-table { width: 100%; max-width: 100%; overflow: visible; }
    .invitations-table table { min-width: 0; width: 100%; table-layout: fixed; }
    .invitations-table tbody { width: 100%; }
    .invitations-table tr {
        width: 100%;
        box-sizing: border-box;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        align-items: center;
        gap: 0 7px;
        padding: 6px 8px;
    }
    .invitations-table td {
        display: block;
        width: auto;
        min-width: 0;
        padding: 2px 0;
        font-size: 12px;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }
    .invitations-table td::before { font-size: 9px; line-height: 1; margin-bottom: 2px; }
    .invitations-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .invitations-table td:nth-child(2) { grid-column: 2 / 4; grid-row: 1; text-align: right; }
    .invitations-table td:nth-child(3) { display: none; }
    .invitations-table td:nth-child(4) { grid-column: 1; grid-row: 2; font-weight: 800; }
    .invitations-table td:nth-child(4)::before,
    .invitations-table td:nth-child(5)::before,
    .invitations-table td:last-child::before { display: none; }
    .invitations-table td:nth-child(5) { grid-column: 2; grid-row: 2; text-align: left; }
    .invitations-table td:last-child { grid-column: 3; grid-row: 2; padding-top: 0; justify-self: end; }
    .invitations-table .actions { gap: 4px; justify-content: flex-end; flex-wrap: nowrap; min-width: 0; }
    .invitations-table .icon-only { width: 30px; height: 30px; min-height: 30px; border-radius: 7px; }
    .invitations-table .icon-only .icon { width: 15px; height: 15px; }
    .invitations-table .pill { padding: 2px 7px; font-size: 11px; line-height: 1.2; }
}

.checkin-shell {
    margin-left: 0;
    max-width: 1240px;
    padding: 24px;
}
.checkin-shell .page-header {
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
    margin-bottom: 18px;
}
.checkin-summary {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
}
.checkin-summary .info-card {
    border: 1px solid var(--line);
    background: linear-gradient(180deg, #fff, #f8fbfb);
}
.checkin-summary .info-card strong {
    font-size: 30px;
}
.checkin-report table {
    min-width: 860px;
}
.checkin-report tbody tr {
    transition: background .16s ease, transform .16s ease;
}
.checkin-report tbody tr:hover {
    background: #f7fbfa;
}
.checkin-action {
    min-height: 34px;
    padding: 7px 12px;
    white-space: nowrap;
}
.checkin-report td:nth-child(4) strong {
    font-size: 15px;
    letter-spacing: .04em;
}

@media (max-width: 740px) {
    .checkin-shell {
        padding: 14px;
    }
    .checkin-shell .page-header {
        padding-bottom: 12px;
        margin-bottom: 14px;
    }
    .checkin-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }
    .checkin-summary .info-card {
        padding: 12px 10px;
    }
    .checkin-summary .info-card span {
        font-size: 10px;
        margin-bottom: 4px;
    }
    .checkin-summary .info-card strong {
        font-size: 22px;
    }
    .checkin-report table {
        min-width: 0;
    }
    .checkin-report tr {
        padding: 8px 10px;
    }
    .checkin-report td {
        padding: 5px 0;
        font-size: 13px;
    }
    .checkin-report .actions {
        justify-content: flex-start;
    }
    .checkin-action {
        width: 100%;
        justify-content: center;
    }
}
