* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #f3f6f9;
    color: #222;
    line-height: 1.45;
}

a {
    color: #1f4e79;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    background: #1f4e79;
    color: #fff;
    flex: 0 0 250px;
    min-height: 100vh;
    padding: 22px 18px;
    position: sticky;
    top: 0;
}

.brand {
    border-bottom: 1px solid rgba(255, 255, 255, 0.22);
    margin-bottom: 18px;
    padding-bottom: 18px;
}

.brand h1 {
    font-size: 22px;
    line-height: 1.2;
    margin: 0;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar nav a {
    border-radius: 6px;
    color: #fff;
    display: block;
    font-size: 15px;
    min-height: 44px;
    padding: 12px 12px;
    text-decoration: none;
}

.sidebar nav a:hover,
.sidebar nav a:focus {
    background: rgba(255, 255, 255, 0.14);
    outline: none;
}

.content-shell {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #d8dee6;
    display: flex;
    justify-content: space-between;
    min-height: 64px;
    padding: 14px 24px;
}

.topbar-title {
    color: #1f4e79;
    font-size: 20px;
    font-weight: bold;
}

.user-menu {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.user-menu a {
    font-weight: bold;
    text-decoration: none;
}

.role-badge {
    background: #eaf1f7;
    border: 1px solid #c7d8e6;
    border-radius: 999px;
    color: #1f4e79;
    font-size: 13px;
    padding: 3px 8px;
}

.menu-toggle {
    align-items: center;
    background: #1f4e79;
    border: 0;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: none;
    font-size: 16px;
    min-height: 44px;
    padding: 10px 14px;
}

.menu-icon {
    display: inline-block;
    font-size: 22px;
    line-height: 1;
    margin-right: 8px;
}

.mobile-overlay {
    background: rgba(15, 28, 39, 0.45);
    display: none;
    inset: 0;
    position: fixed;
    z-index: 20;
}

main {
    flex: 1;
    margin: 0 auto;
    max-width: 1180px;
    padding: 24px;
    width: 100%;
}

.page {
    background: #fff;
    border: 1px solid #d8dee6;
    border-radius: 8px;
    padding: 24px;
}

.page h2 {
    color: #1f4e79;
    font-size: 24px;
    line-height: 1.25;
    margin: 0 0 18px;
}

.page h3,
.panel h3,
.info-box h3 {
    color: #1f4e79;
    font-size: 18px;
    margin: 0 0 14px;
}

footer {
    color: #666;
    font-size: 14px;
    padding: 16px 24px 24px;
    text-align: center;
}

.form-grid,
.search-grid,
.info-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.search-grid {
    margin-bottom: 18px;
}

.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

label,
.label {
    color: #2d3b48;
    font-weight: bold;
}

label {
    margin-bottom: 6px;
}

.label {
    display: block;
    font-size: 14px;
    margin-bottom: 3px;
}

.value {
    color: #222;
    font-weight: bold;
    overflow-wrap: anywhere;
}

input,
select,
textarea {
    background: #fff;
    border: 1px solid #b8c2cc;
    border-radius: 5px;
    font: inherit;
    min-height: 44px;
    padding: 10px 12px;
    width: 100%;
}

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

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

input[type="file"] {
    padding: 9px;
}

.actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.button,
button.button,
.actions button,
button[type="submit"] {
    background: #1f4e79;
    border: 0;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    min-height: 44px;
    padding: 10px 18px;
    text-decoration: none;
}

.button.secondary {
    background: #5b6b78;
}

.button:hover,
button[type="submit"]:hover {
    filter: brightness(0.95);
}

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

.message.success {
    background: #e8f5ec;
    border: 1px solid #a9d8b6;
    color: #1d6b34;
}

.message.error {
    background: #fdeceb;
    border: 1px solid #edb2ad;
    color: #9f2f24;
}

.message:not(.success):not(.error) {
    background: #eef4fa;
    border: 1px solid #b9cfe1;
    color: #244b68;
}

.table-wrap {
    margin-top: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    background: #fff;
    border-collapse: collapse;
    min-width: 680px;
    width: 100%;
}

th,
td {
    border: 1px solid #d8dee6;
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #eaf1f7;
    color: #1f4e79;
}

pre {
    font-family: Consolas, monospace;
    font-size: 13px;
    margin: 0;
    max-width: 360px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.panel,
.info-box {
    border: 1px solid #d8dee6;
    border-radius: 6px;
    margin-bottom: 18px;
    padding: 16px;
}

.panel {
    margin-top: 18px;
}

.choice-list {
    display: grid;
    gap: 10px;
}

.choice-item {
    border: 1px solid #d8dee6;
    border-radius: 5px;
    padding: 10px;
}

.choice-item label {
    cursor: pointer;
    display: block;
    font-weight: normal;
    margin: 0;
}

.muted,
.hint {
    color: #5b6b78;
    font-size: 14px;
}

.hint {
    margin: 0 0 16px;
}

.patient-code,
.template-summary {
    background: #eaf1f7;
    border: 1px solid #c7d8e6;
    border-radius: 5px;
    color: #1f4e79;
    display: inline-block;
    font-weight: bold;
    margin-bottom: 18px;
    padding: 8px 12px;
}

.template-summary {
    display: block;
}

.logo-preview {
    border: 1px solid #d8dee6;
    border-radius: 6px;
    margin-bottom: 16px;
    padding: 14px;
    width: fit-content;
}

.logo-preview img {
    display: block;
    max-height: 110px;
    max-width: 220px;
}

.test-line {
    border-bottom: 1px solid #eef2f5;
    padding: 8px 0;
}

.test-line:last-child {
    border-bottom: 0;
}

.action-link {
    display: inline-block;
    margin-top: 4px;
}

.dashboard-header {
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 20px;
}

.dashboard-header h2 {
    margin: 0;
}

.quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.summary-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-bottom: 22px;
}

.summary-card {
    background: #f8fbfd;
    border: 1px solid #d8dee6;
    border-left: 4px solid #1f4e79;
    border-radius: 6px;
    padding: 16px;
}

.summary-card .label {
    color: #5b6b78;
    font-size: 14px;
    margin-bottom: 8px;
}

.summary-card .value {
    color: #1f4e79;
    font-size: 30px;
    line-height: 1;
}

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

.auth-page {
    align-items: center;
    background: #f3f6f9;
    display: flex;
    min-height: 100vh;
    padding: 18px;
}

.auth-card {
    background: #fff;
    border: 1px solid #d8dee6;
    border-radius: 8px;
    margin: 0 auto;
    max-width: 430px;
    padding: 28px;
    width: 100%;
}

.auth-card h1 {
    color: #1f4e79;
    font-size: 24px;
    margin: 0 0 8px;
}

.auth-card .form-group {
    margin-top: 16px;
}

@media (max-width: 1080px) {
    .summary-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .sidebar {
        height: 100vh;
        left: 0;
        max-width: 82vw;
        position: fixed;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        width: 280px;
        z-index: 30;
    }

    body.menu-open .sidebar {
        transform: translateX(0);
    }

    body.menu-open .mobile-overlay {
        display: block;
    }

    main {
        padding: 16px;
    }

    .topbar {
        padding: 12px 16px;
    }

    .page {
        padding: 18px;
    }

    .dashboard-header,
    .dashboard-grid {
        display: grid;
        grid-template-columns: 1fr;
    }

    .form-grid,
    .search-grid,
    .info-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: auto;
    }
}

@media (max-width: 640px) {
    html {
        font-size: 15px;
    }

    .topbar-title {
        font-size: 17px;
    }

    .user-menu {
        align-items: flex-start;
        flex-direction: column;
        font-size: 14px;
        gap: 4px;
    }

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

    .actions,
    .quick-links {
        align-items: stretch;
        flex-direction: column;
    }

    .button,
    button.button,
    .actions button,
    button[type="submit"] {
        width: 100%;
    }

    table {
        min-width: 620px;
    }
}
