:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dbe4ef;
    --border-strong: #b8c7d9;
    --text: #17202a;
    --muted: #617386;
    --brand: #0f3f4a;
    --brand-dark: #0a2d36;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --success-dark: #15803d;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --warning-bg: #fff7ed;
    --shadow: 0 18px 45px rgba(15, 63, 74, 0.09);
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 0;
}

body {
    margin: 0;
    overflow-x: hidden;
    background:
        linear-gradient(180deg, rgba(15, 63, 74, 0.08), transparent 260px),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(15, 63, 74, 0.96);
    color: #fff;
    padding: 14px 0;
    box-shadow: 0 10px 30px rgba(15, 63, 74, 0.18);
}

.topbar__inner,
.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.brand {
    max-width: 360px;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0;
}

.brand-context {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    margin-left: 8px;
    padding: 3px 8px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 12px;
    font-weight: 750;
    vertical-align: middle;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
}

.nav a {
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.92);
    padding: 8px 10px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.nav a:hover,
.nav a:focus {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.page {
    padding: 30px 0 56px;
}

.page--narrow {
    width: min(880px, calc(100% - 32px));
}

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

.panel {
    width: 100%;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

h1,
h2 {
    margin: 0 0 18px;
    line-height: 1.18;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(28px, 3vw, 38px);
    font-weight: 850;
}

h2 {
    font-size: 20px;
    font-weight: 800;
}

.field {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 6px;
    color: #253342;
    font-size: 14px;
    font-weight: 800;
}

input[type='text'],
input[type='date'],
input[type='password'],
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
    padding: 10px 12px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea {
    min-height: 98px;
    resize: vertical;
}

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

.login-panel {
    width: min(430px, 100%);
}

.login-brand {
    margin: 0 0 8px;
    color: var(--brand);
    font-size: 15px;
    font-weight: 800;
}

.checkboxes {
    display: grid;
    gap: 9px;
    margin: 18px 0;
}

.tag-options {
    display: grid;
    gap: 9px;
    margin-bottom: 10px;
}

.tag-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
    margin: 0;
    padding: 0;
    color: #24415f;
    font-size: 14px;
    font-weight: 800;
}

.tag-option label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin: 0;
    padding: 10px 12px;
}

.tag-option input {
    width: 18px;
    height: 18px;
}

.tag-delete {
    width: 30px;
    min-height: 30px;
    border: 1px solid #fecdd3;
    border-radius: 8px;
    background: #fff1f2;
    color: var(--danger);
    margin-right: 9px;
    padding: 0;
    font-size: 17px;
    line-height: 1;
}

.tag-delete:hover {
    background: #ffe4e6;
    color: var(--danger-dark);
}

.hidden-form {
    display: none;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 10px 12px;
    font-weight: 750;
}

.checkbox input {
    width: 18px;
    height: 18px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    padding: 8px 14px;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.button:hover,
button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.14);
}

.button--secondary {
    border: 1px solid var(--border);
    background: #fff;
    color: #405166;
    box-shadow: none;
}

.button--secondary:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
    color: #243244;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

.button--success {
    background: #18a957;
}

.button--success:hover {
    background: #158f49;
    box-shadow: 0 6px 14px rgba(22, 163, 74, 0.14);
}

.button--danger {
    background: #e11d48;
}

.button--danger:hover {
    background: #be123c;
    box-shadow: 0 6px 14px rgba(225, 29, 72, 0.14);
}

.button--small {
    min-height: 32px;
    padding: 6px 11px;
    font-size: 13px;
    border-radius: 8px;
}

.button--edit {
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
    box-shadow: none;
}

.button--edit:hover {
    border-color: #a5b4fc;
    background: #e0e7ff;
    color: #312e81;
    box-shadow: 0 8px 16px rgba(79, 70, 229, 0.12);
}

.row-actions .button--danger {
    border: 1px solid #fecaca;
    background: #fee2e2;
    color: #b91c1c;
    box-shadow: none;
}

.row-actions .button--danger:hover {
    border-color: #fca5a5;
    background: #fecaca;
    color: #991b1b;
    box-shadow: 0 6px 14px rgba(220, 38, 38, 0.1);
}

.form-actions,
.row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.row-actions {
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 9px;
}

.alert {
    border-radius: 9px;
    margin-bottom: 18px;
    padding: 12px 14px;
    font-weight: 650;
}

.alert--success {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #14532d;
}

.alert--error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #7f1d1d;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 760px;
}

.visitors-table {
    min-width: 720px;
    table-layout: fixed;
}

.visitors-table th:nth-child(1) {
    width: 29%;
}

.visitors-table th:nth-child(2) {
    width: 128px;
}

.visitors-table th:nth-child(3) {
    width: 100px;
}

.visitors-table th:nth-child(4) {
    width: 82px;
}

.visitors-table th:nth-child(5) {
    width: 160px;
}

.visitors-table th:nth-child(6) {
    width: 124px;
    text-align: center;
}

.visitors-table td:nth-child(6) {
    text-align: center;
}

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

th {
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

tbody tr:hover td {
    background: #f8fbff;
}

.visitors-table td {
    vertical-align: middle;
}

.visitors-table td:first-child {
    vertical-align: top;
}

.visitors-table .row-actions {
    justify-content: center;
}

td strong {
    display: inline-block;
    margin-bottom: 4px;
    color: #243244;
    font-size: 15px;
    font-weight: 650;
    line-height: 1.28;
}

td small {
    color: var(--muted);
}

.date-cell {
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    border-radius: 8px;
    background: #e8f0fb;
    color: #24415f;
    margin: 3px 5px 3px 0;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 760;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: break-word;
    text-wrap: balance;
}

.badge--custom {
    background: #eaf8ef;
    color: #146c2e;
}

.empty {
    color: var(--muted);
    margin: 0;
}

.registration-panel {
    padding: 22px;
}

.registration-header,
.report-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.date-form,
.report-filter {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.date-form input[type='date'],
.report-filter input[type='date'] {
    width: 160px;
}

.date-form button,
.icon-search {
    min-width: 42px;
}

.icon-search {
    font-size: 19px;
    padding: 0;
}

.visit-stats {
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-soft);
    margin-top: 36px;
    padding: 9px 12px;
    white-space: nowrap;
}

.visit-list {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.visit-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    min-height: 58px;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

.visit-row:last-child {
    border-bottom: 0;
}

.visit-person {
    color: #243244;
    font-weight: 650;
}

.visit-person span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.visit-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-form {
    margin: 0;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    width: 32px;
    max-width: 32px;
    height: 32px;
    min-height: 32px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 0;
    aspect-ratio: 1;
    font-size: 16px;
    font-weight: 900;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.icon-button:hover {
    background: var(--surface-soft);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

.icon-button--success,
.icon-button--success:hover,
.icon-button--success:disabled {
    border-color: #86efac;
    background: #dcfce7;
    color: #166534;
    box-shadow: none;
    opacity: 1;
    cursor: default;
}

.icon-button--success:hover,
.icon-button--success:disabled {
    transform: none;
}

.icon-button--link {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 15px;
}

.icon-button--link:hover {
    border-color: #93c5fd;
    background: #dbeafe;
}

.icon-button--danger {
    border-color: #fecaca;
    background: #fff1f2;
    color: #be123c;
}

.icon-button--danger:hover {
    border-color: #fda4af;
    background: #ffe4e6;
}

.visit-empty {
    padding: 18px;
}

.visit-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    margin-top: 18px;
}

.list-search {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto auto;
    gap: 8px;
    margin: 0 0 16px;
}

.link-visitor-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 8px;
}

.linked-names {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 7px;
}

.linked-names span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #405166;
    padding: 4px 7px 4px 9px;
    font-size: 12px;
    font-weight: 650;
}

.linked-name-remove {
    width: 18px;
    min-height: 18px;
    border-radius: 999px;
    background: #fee2e2;
    color: #b91c1c;
    padding: 0;
    font-size: 13px;
    line-height: 1;
    box-shadow: none;
}

.linked-names--daily {
    margin-left: 20px;
}

.modal-backdrop {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.42);
    padding: 20px;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    position: relative;
    width: min(100%, 520px);
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 14px;
    background: #fff;
    padding: 24px;
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

.modal h2 {
    margin: 0 42px 4px 0;
    font-size: 22px;
}

.modal-person {
    margin: 0 0 18px;
    color: var(--muted);
    font-weight: 650;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    min-height: 34px;
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
    padding: 0;
    font-size: 20px;
    line-height: 1;
}

.modal-close:hover {
    background: #eef2f7;
    transform: none;
}

.search-field {
    position: relative;
}

.search-results {
    position: absolute;
    z-index: 5;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 18px 40px rgba(15, 63, 74, 0.18);
}

.search-result,
.search-empty {
    display: block;
    width: 100%;
    min-height: 40px;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: #fff;
    color: var(--text);
    padding: 10px 12px;
    text-align: left;
    font-weight: 650;
}

.search-result:hover,
.search-result:focus {
    background: #eff6ff;
}

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

.report-panel {
    padding: 22px;
}

.print-button {
    margin-top: 36px;
}

.chart-wrap {
    margin: 8px 0 26px;
    overflow-x: auto;
}

.bar-chart {
    display: block;
    width: 100%;
    min-width: 720px;
    height: auto;
}

.chart-title {
    fill: #36546a;
    font-size: 12px;
    font-weight: 800;
}

.chart-grid {
    stroke: #dbe6f2;
    stroke-width: 1;
}

.chart-label,
.chart-date {
    fill: var(--muted);
    font-size: 12px;
}

.chart-bar {
    fill: var(--primary);
}

.chart-empty {
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--muted);
    padding: 24px;
    text-align: center;
}

.report-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
}

.report-grid--extra {
    margin-top: 14px;
}

.stats-table {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    margin-bottom: 16px;
    overflow: hidden;
}

.stats-table th,
.stats-table td {
    border-right: 1px solid var(--border);
    padding: 9px 10px;
}

.stats-table th:last-child,
.stats-table td:last-child {
    border-right: 0;
    text-align: right;
}

.stats-table th {
    background: #eef3f8;
    color: #40556a;
    text-transform: none;
}

.stats-table tr:nth-child(odd) td {
    background: #f8fafc;
}

.new-visitors-note {
    border: 1px solid #a7dce7;
    border-radius: 9px;
    background: #dff6fb;
    color: #115565;
    margin-bottom: 16px;
    padding: 14px 18px;
}

@media print {
    .topbar,
    .print-button {
        display: none;
    }

    body {
        background: #fff;
    }

    .page {
        width: 100%;
        padding: 0;
    }

    .panel {
        border: 0;
        box-shadow: none;
    }
}

@media (max-width: 980px) {
    .topbar__inner {
        align-items: flex-start;
        flex-direction: column;
    }

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

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

@media (max-width: 760px) {
    .topbar {
        position: static;
    }

    .topbar__inner,
    .page,
    .page--narrow {
        width: min(100% - 24px, 1180px);
    }

    .page {
        padding: 22px 0 42px;
    }

    .panel {
        padding: 18px;
    }

    .brand {
        max-width: none;
    }

    .nav {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nav a {
        background: rgba(255, 255, 255, 0.08);
        text-align: center;
    }

    .registration-header,
    .report-header,
    .report-grid,
    .visit-search,
    .link-visitor-form,
    .list-search {
        display: block;
    }

    .date-form,
    .report-filter {
        display: grid;
        grid-template-columns: 1fr;
    }

    .date-form input[type='date'],
    .report-filter input[type='date'],
    .date-form button,
    .report-filter button,
    .print-button,
    .visit-search .button,
    .link-visitor-form .button,
    .link-visitor-form button,
    .list-search .button,
    .list-search button {
        width: 100%;
        max-width: none;
        margin-top: 8px;
    }

    .visit-stats,
    .print-button {
        margin-top: 12px;
    }

    .visit-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .visit-actions,
    .row-actions {
        justify-content: flex-start;
    }

    .bar-chart {
        min-width: 680px;
    }
}

@media (max-width: 520px) {
    h1 {
        font-size: 27px;
    }

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

    .topbar {
        padding: 12px 0;
    }

    .table-wrap {
        margin-inline: -18px;
        padding-inline: 18px;
    }
}
