* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: #1f2933;
    background: #f4f7f9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
}

a {
    color: #0f766e;
    text-decoration: none;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 36px;
    border: 1px solid #cbd5df;
    border-radius: 6px;
    background: #fff;
    color: #1f2933;
    padding: 7px 9px;
}

input[type="checkbox"] {
    width: auto;
    min-height: auto;
}

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

label {
    display: grid;
    gap: 6px;
    color: #52616b;
    font-size: 13px;
}

code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #eef2f5;
}

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 20px;
    align-items: center;
    min-height: 60px;
    padding: 0 24px;
    background: #ffffff;
    border-bottom: 1px solid #dde5ea;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    font-weight: 700;
    color: #0b4f4a;
}

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

.nav a {
    padding: 8px 10px;
    border-radius: 6px;
    color: #334e5c;
}

.nav a:hover {
    background: #edf7f5;
    color: #0f766e;
}

.user-chip {
    color: #52616b;
    white-space: nowrap;
}

.page {
    width: min(1440px, calc(100% - 32px));
    margin: 24px auto 48px;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(20, 83, 45, 0.04) 48%, rgba(14, 116, 144, 0.10)),
        #f4f7f9;
}

.panel {
    background: #fff;
    border: 1px solid #dde5ea;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: 0 8px 24px rgba(31, 41, 51, 0.04);
}

.panel.narrow {
    width: min(460px, 100%);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

h1,
h2,
h3 {
    margin: 0;
    color: #17242a;
    letter-spacing: 0;
}

h1 {
    font-size: 24px;
}

h2 {
    font-size: 18px;
}

h3 {
    font-size: 15px;
}

.muted {
    color: #71818b;
}

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

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

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

.full-row {
    grid-column: 1 / -1;
}

.settings-form {
    margin-top: 16px;
    align-items: start;
}

.settings-group-title {
    grid-column: 1 / -1;
    margin-top: 8px;
    padding-top: 14px;
    border-top: 1px solid #e6edf1;
    color: #334e5c;
}

.settings-form .settings-group-title:first-of-type {
    margin-top: 2px;
    padding-top: 0;
    border-top: 0;
}

.settings-toggle {
    grid-column: 1 / -1;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #e6edf1;
    border-radius: 8px;
    background: #f7fafb;
    font-weight: 600;
}

.settings-check {
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #e6edf1;
    border-radius: 8px;
    background: #fbfcfd;
}

.field-note {
    font-size: 12px;
    line-height: 1.4;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
}

.kpi {
    background: #ffffff;
    border: 1px solid #dde5ea;
    border-radius: 8px;
    padding: 14px;
}

.kpi span {
    display: block;
    color: #71818b;
    font-size: 12px;
    margin-bottom: 8px;
}

.kpi strong {
    display: block;
    font-size: 20px;
    color: #0b4f4a;
    overflow-wrap: anywhere;
}

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

.subpanel {
    min-width: 0;
}

.subpanel h3 {
    margin-bottom: 10px;
}

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

th,
td {
    padding: 10px 9px;
    border-bottom: 1px solid #e6edf1;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    color: #52616b;
    background: #f7fafb;
    font-weight: 600;
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

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

.filter-actions {
    align-items: flex-end;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5df;
    background: #fff;
    color: #334e5c;
    cursor: pointer;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.btn.primary {
    border-color: #0f766e;
    background: #0f766e;
    color: #fff;
}

.btn.warning {
    border-color: #d97706;
    color: #92400e;
    background: #fff7ed;
}

.btn.danger {
    border-color: #b91c1c;
    color: #991b1b;
    background: #fff1f2;
}

.btn.small {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}

.period-form {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
}

.period-form label {
    width: 120px;
}

.period-form label.filter-wide {
    width: 190px;
}

.form-actions {
    margin-top: 16px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.flash {
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: 8px;
    border: 1px solid;
}

.flash.success {
    color: #065f46;
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.flash.error {
    color: #991b1b;
    background: #fff1f2;
    border-color: #fecdd3;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    background: #eef2f5;
    color: #52616b;
    font-size: 12px;
}

.badge.on {
    background: #ecfdf5;
    color: #047857;
}

.badge.off {
    background: #f3f4f6;
    color: #6b7280;
}

.schedule-tag {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.schedule-tag-1 {
    background: #e0f2fe;
    color: #075985;
}

.schedule-tag-2 {
    background: #dcfce7;
    color: #166534;
}

.schedule-tag-3 {
    background: #fef3c7;
    color: #92400e;
}

.schedule-tag-4 {
    background: #fce7f3;
    color: #9d174d;
}

.schedule-tag-5 {
    background: #ede9fe;
    color: #5b21b6;
}

.schedule-tag-6 {
    background: #ccfbf1;
    color: #0f766e;
}

.schedule-tag-7 {
    background: #fee2e2;
    color: #991b1b;
}

.schedule-tag-8 {
    background: #e5e7eb;
    color: #374151;
}

.danger-text {
    color: #b91c1c;
}

.diff-ok {
    color: #047857 !important;
}

.diff-positive {
    color: #b45309 !important;
}

.diff-negative {
    color: #b91c1c !important;
}

.error-box {
    white-space: pre-wrap;
    padding: 12px;
    border-radius: 6px;
    background: #fff1f2;
    color: #991b1b;
    overflow-x: auto;
}

.login-title {
    display: grid;
    gap: 10px;
    margin-bottom: 24px;
    text-align: center;
}

.auth-page .panel.narrow {
    width: min(560px, 100%);
    padding: 34px;
    border-color: rgba(15, 118, 110, 0.18);
    box-shadow: 0 24px 60px rgba(15, 52, 61, 0.14);
}

.auth-page .login-title::before {
    content: "";
    width: 46px;
    height: 46px;
    margin: 0 auto 4px;
    border-radius: 14px;
    background:
        linear-gradient(135deg, #0f766e, #14532d);
    box-shadow: 0 12px 28px rgba(15, 118, 110, 0.24);
}

.auth-page .login-title h1 {
    font-size: 28px;
}

.auth-page .grid,
.auth-page .login-form-grid {
    grid-template-columns: 1fr;
    gap: 16px;
}

.login-form-grid > label {
    grid-column: 1 / -1;
    width: 100%;
}

.auth-page label {
    color: #334e5c;
    font-weight: 600;
}

.auth-page input {
    min-height: 46px;
    border-color: #b9c8d2;
    border-radius: 8px;
    padding: 10px 12px;
    font-weight: 500;
}

.auth-page input:focus {
    border-color: #0f766e;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
    outline: none;
}

.qr-box {
    display: flex;
    justify-content: center;
    padding: 14px;
    border: 1px solid #dde5ea;
    border-radius: 8px;
    background: #fff;
}

.qr-box img {
    width: min(220px, 100%);
    height: auto;
    image-rendering: pixelated;
}

.auth-page textarea.secret-uri {
    min-height: 96px;
    border-color: #b9c8d2;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.secret-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    letter-spacing: 0;
}

.captcha-row {
    display: grid;
    grid-template-columns: minmax(110px, 140px) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
}

.captcha-code {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #b9c8d2;
    border-radius: 8px;
    background: #f4f8f7;
    color: #0b4f4a;
    font-weight: 800;
    letter-spacing: 0;
}

@media (max-width: 520px) {
    .captcha-row {
        grid-template-columns: 1fr;
    }
}

.auth-page .form-actions {
    margin-top: 20px;
}

.auth-page .btn {
    width: 100%;
    min-height: 46px;
    justify-content: center;
    font-weight: 700;
}

.inline-form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.inline-form input {
    flex: none;
}

.inline-total {
    display: grid;
    gap: 4px;
    min-width: 160px;
    padding: 10px 12px;
    border: 1px solid #dde5ea;
    border-radius: 8px;
    background: #f7fafb;
    text-align: right;
}

.inline-total span {
    color: #71818b;
    font-size: 12px;
}

.inline-total strong {
    color: #0b4f4a;
    font-size: 20px;
    font-variant-numeric: tabular-nums;
}

.readonly-box {
    display: grid;
    gap: 6px;
    min-height: 36px;
    padding: 9px 10px;
    border: 1px solid #dde5ea;
    border-radius: 6px;
    background: #f7fafb;
}

.readonly-box span {
    color: #71818b;
    font-size: 12px;
}

.readonly-box strong {
    color: #0b4f4a;
    font-size: 15px;
}

.audit-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.audit-strip div {
    min-height: 56px;
    padding: 10px 12px;
    border: 1px solid #dde5ea;
    border-radius: 6px;
    background: #f7fafb;
}

.audit-strip span {
    display: block;
    margin-bottom: 5px;
    color: #71818b;
    font-size: 12px;
}

.audit-strip strong {
    color: #0b4f4a;
    font-size: 15px;
    overflow-wrap: anywhere;
}

.wide-note {
    min-width: 220px;
}

.stat-input {
    min-width: 96px;
}

.record-meta {
    display: grid;
    gap: 3px;
    min-width: 190px;
    color: #71818b;
    font-size: 12px;
    line-height: 1.45;
    white-space: normal;
}

@media (max-width: 980px) {
    .topbar {
        grid-template-columns: 1fr;
        align-items: start;
        padding: 14px 16px;
    }

    .kpis,
    .grid,
    .grid.three,
    .audit-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .page {
        width: min(100% - 20px, 1440px);
        margin-top: 14px;
    }

    .auth-page {
        padding: 16px;
    }

    .auth-page .panel.narrow {
        padding: 26px;
    }

    .kpis,
    .grid,
    .grid.two,
    .grid.three,
    .audit-strip {
        grid-template-columns: 1fr;
    }

    .period-form label {
        width: calc(50% - 5px);
    }

    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }
}
