:root {
    --navy: #183153;
    --blue: #2d6ca8;
    --ink: #243044;
    --muted: #5c6b80;
    --line: #d5dde6;
    --paper: #f4f7fb;
    --white: #fff;
    --ok: #e5f6e8;
    --ok-ink: #146c2e;
    --bad: #fde8e8;
    --bad-ink: #9f1d1d;
    --warn: #fff4d6;
    --warn-ink: #7a5b00;
    --shadow: 0 16px 40px rgba(24, 49, 83, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

body.gate-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top, #2a527f 0%, #183153 42%, #101c2e 100%);
}

a { color: var(--blue); }

h1, h2 { color: var(--navy); }

h1 {
    margin: 0 0 28px;
    font-size: 1.6rem;
    text-align: center;
}

h1 img {
    display: inline-block;
    vertical-align: -6px;
    margin-right: 6px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.gate {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.gate-card {
    width: min(560px, 100%);
    background: var(--white);
    border-radius: 16px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
}

.gate-card h1 {
    font-size: 1.7rem;
    line-height: 1.25;
}

.gate-card p { color: var(--muted); }

.gate-row {
    display: flex;
    gap: 10px;
}

.gate-row input { flex: 1; }

label {
    display: block;
    margin: 16px 0 6px;
    font-weight: 700;
    color: var(--navy);
}

.sub, .hint, .contact {
    color: var(--muted);
    font-size: 0.92rem;
}

.hint { margin: 14px 0 0; }

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

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="date"],
input:not([type]),
textarea,
select {
    width: 100%;
    border: 1px solid #b7c3d1;
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--white);
    color: var(--ink);
}

input:focus, textarea:focus, select:focus {
    outline: 2px solid rgba(45, 108, 168, 0.35);
    border-color: var(--blue);
}

input.invalid, textarea.invalid { border-color: var(--bad-ink); }

button, .button {
    display: inline-block;
    border: 0;
    border-radius: 8px;
    background: var(--navy);
    color: white;
    padding: 10px 16px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 650;
}

button:hover, .button:hover { background: var(--blue); }

.button.ghost {
    background: transparent;
    color: var(--navy);
    border: 1px solid var(--line);
}

.sheet {
    width: min(640px, 100%);
    margin: 32px auto 64px;
    padding: 28px 22px 40px;
    background: var(--white);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.fact {
    margin: 0 0 18px;
    padding-bottom: 8px;
}

.fact h2 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.fact p { margin: 0; }

.field-error {
    margin: 6px 0 0;
    color: var(--bad-ink);
    font-size: 0.9rem;
}

.message {
    padding: 12px 14px;
    border-radius: 8px;
    margin: 0 0 16px;
}

.message.success { background: var(--ok); color: var(--ok-ink); }
.message.failed { background: var(--bad); color: var(--bad-ink); }
.message.warning { background: var(--warn); color: var(--warn-ink); }

.preview img,
.admin-photo img {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 480px;
    margin: 8px 0;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: white;
}

.admin-photo {
    margin: 0 0 24px;
}

.admin.mask {
    width: calc(100% - 32px);
    max-width: none;
    margin-top: 16px;
}

.mask .hint { margin: 8px 0 16px; }

.mask-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.mask-grid section {
    background: white;
    border-radius: 12px;
    padding: 8px 16px 18px;
}

.mask-grid h2 {
    margin: 8px 0 0;
    font-size: 1.05rem;
}

.mask label { margin-top: 12px; }

.mask label.review { color: var(--warn-ink); }

.mask input.review,
.mask textarea.review {
    background: var(--warn);
    border-color: #e2c56a;
}

.mask .admin-photo img { max-height: 280px; }

.mask .admin-head button { margin-top: 0; }

@media (max-width: 1100px) {
    .mask-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
    .mask-grid { grid-template-columns: 1fr; }
}

.admin-photo.review {
    margin: 0 0 24px;
    padding: 12px 14px 8px;
    background: var(--warn);
    border-radius: 12px;
}

.admin-photo figcaption,
.history .muted {
    color: var(--muted);
    font-size: 0.85rem;
}

.thumb {
    display: block;
    width: 112px;
    height: 84px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: white;
}

.photo-cell { width: 128px; }

form button[type="submit"] { margin-top: 22px; }

.contact {
    margin-top: 36px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.legal {
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 12px 20px;
    background: var(--navy);
    color: white;
}

.topbar a, .topbar button { color: white; }

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    text-decoration: none;
    margin-right: auto;
}

.topbar nav { display: flex; gap: 14px; }

.topbar nav a { text-decoration: none; }
.topbar nav a.active { text-decoration: underline; text-underline-offset: 4px; }

.linkish {
    background: transparent;
    padding: 6px 0;
}

.admin {
    width: min(1280px, calc(100% - 32px));
    margin: 28px auto 48px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 18px 0;
}

.stat {
    display: block;
    background: white;
    border-radius: 12px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--muted);
    border: 2px solid transparent;
}

.stat strong {
    display: block;
    font-size: 1.7rem;
    color: var(--navy);
}

.stat.active { border-color: var(--navy); }

.pill {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.pill.wait { background: var(--warn); color: var(--warn-ink); }
.pill.ok { background: var(--ok); color: var(--ok-ink); }
.pill.none { background: #eef2f6; color: var(--muted); }

.muted { color: var(--muted); font-size: 0.85rem; }

td.wrap { white-space: normal; }

.admin th { white-space: nowrap; }

.admin td {
    white-space: normal;
    vertical-align: top;
}

.row-actions { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-actions form { margin: 0; }
.row-actions button {
    margin: 0;
    padding: 6px 10px;
    font-size: 0.85rem;
    background: white;
    color: var(--navy);
    border: 1px solid var(--line);
}

.admin-head, .actions, .filters {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.admin-head { justify-content: space-between; }
.admin-head h1 { margin: 0; text-align: left; }
.letter-note { margin: 8px 0 0; }

.filters { margin: 18px 0; }
.filters input, .filters select { width: auto; flex: 1; }
.filters button { margin-top: 0; }

.table-wrap { overflow-x: auto; background: white; border-radius: 12px; }

table { width: 100%; border-collapse: collapse; background: white; }

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

th { color: var(--navy); font-size: 0.85rem; }

.import, .history {
    margin-top: 28px;
    padding: 16px;
    background: white;
    border-radius: 12px;
}

.import .actions { margin-top: 12px; }

.admin-sheet { margin-top: 24px; }

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
}

.check input { width: auto; }

.danger { margin-top: 28px; }
.danger button { background: var(--bad-ink); }

.system h1 { text-align: left; }
.system textarea { min-height: 8rem; }
.system .danger {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 0;
}
.system .danger button { margin-top: 0; }
a.button.danger-button { background: var(--bad-ink); color: white; border: 0; }
a.button.danger-button:hover { background: #7a1515; }

.history ul { padding-left: 18px; }
.history li { margin-bottom: 8px; }

@media (max-width: 800px) {
    .stats { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
    .gate-row, .topbar, .filters { flex-direction: column; align-items: stretch; }
    .topbar nav { flex-wrap: wrap; }
    .sheet { margin: 0; border-radius: 0; min-height: 100vh; }
}
