:root {
    --bg: #f7f7f7;
    --surface: #fff;
    --text: #2a3f54;
    --muted: #73879c;
    --line: #e6e9ed;
    --success: #1abb9c;
    --success-dark: #169f85;
    --sidebar: #2a3f54;
    --sidebar-dark: #172d44;
    --danger: #a94442;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Open Sans", Arial, Helvetica, sans-serif;
    font-size: 14px;
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

.app-sidebar {
    background: var(--sidebar);
    bottom: 0;
    color: #ecf0f1;
    left: 0;
    position: fixed;
    top: 0;
    width: 230px;
    z-index: 20;
}
.sidebar-brand {
    align-items: center;
    display: flex;
    font-size: 22px;
    font-weight: 700;
    gap: 10px;
    height: 58px;
    padding: 0 18px;
}
.brand-icon,
.profile-avatar,
.topbar-avatar {
    align-items: center;
    background: var(--success);
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    font-weight: 700;
    justify-content: center;
}
.brand-icon { height: 36px; width: 36px; }
.sidebar-profile {
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    gap: 12px;
    padding: 14px 16px 18px;
}
.profile-avatar { flex: 0 0 48px; height: 48px; width: 48px; }
.sidebar-profile small { color: #bab8b8; display: block; }
.sidebar-profile strong { color: #ecf0f1; display: block; line-height: 1.25; margin-top: 3px; }
.sidebar-menu { padding: 20px 0 62px; }
.sidebar-menu small {
    color: #fff;
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    padding: 0 18px 10px;
    text-transform: uppercase;
}
.sidebar-menu a {
    align-items: center;
    border-right: 4px solid transparent;
    color: #e7e7e7;
    display: flex;
    gap: 10px;
    padding: 12px 18px;
}
.sidebar-menu a:hover {
    background: linear-gradient(#334556, #2c4257), var(--sidebar);
    border-right-color: var(--success);
    color: #fff;
}
.sidebar-menu i { font-size: 18px; text-align: center; width: 20px; }
.sidebar-footer {
    background: var(--sidebar-dark);
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    left: 0;
    position: absolute;
    width: 100%;
}
.sidebar-footer a {
    color: #5a738e;
    display: grid;
    font-size: 16px;
    padding: 13px 0;
    place-items: center;
}
.sidebar-footer a:hover { background: #425567; color: #fff; }

.content {
    margin-left: 230px;
    padding: 78px 24px 34px;
}
.topbar {
    align-items: center;
    background: #ededed;
    border-bottom: 1px solid #d9dee4;
    display: flex;
    justify-content: space-between;
    left: 230px;
    min-height: 58px;
    padding: 0 22px;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 15;
}
.topbar-title strong { display: block; }
.topbar-title span,
.muted,
small { color: var(--muted); }
.topbar-user {
    align-items: center;
    color: #515356;
    display: flex;
    gap: 10px;
}
.topbar-avatar { font-size: 12px; height: 28px; width: 28px; }

.auth-shell {
    align-items: center;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}
.login-box {
    background: #fff;
    border: 1px solid #d9dee4;
    border-radius: 10px;
    box-shadow: 0 18px 45px rgba(42,63,84,.14);
    padding: 30px;
    width: min(430px, 100%);
}
.login-box h1 { font-size: 27px; font-weight: 500; line-height: 1.15; margin: 0 0 6px; }
.auth-brand {
    align-items: center;
    display: flex;
    gap: 14px;
    margin-bottom: 24px;
}
.auth-brand-icon {
    align-items: center;
    background: var(--success);
    border-radius: 14px;
    color: #fff;
    display: inline-flex;
    flex: 0 0 50px;
    font-size: 22px;
    height: 50px;
    justify-content: center;
    width: 50px;
}
.auth-brand p { line-height: 1.35; margin: 0; }
.auth-form { display: grid; gap: 15px; }
.input-icon {
    align-items: center;
    display: grid;
    grid-template-columns: 22px 1fr auto;
    min-width: 0;
    position: relative;
}
.input-icon > i {
    color: var(--muted);
    grid-column: 1;
    grid-row: 1;
    margin-left: 13px;
    pointer-events: none;
    z-index: 1;
}
.input-icon input {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 48px;
    padding-left: 42px;
}
.input-icon input:focus {
    border-color: var(--success);
    box-shadow: 0 0 0 3px rgba(26,187,156,.14);
    outline: 0;
}
.icon-btn {
    align-items: center;
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    grid-column: 3;
    grid-row: 1;
    height: 44px;
    justify-content: center;
    margin-right: 4px;
    padding: 0;
    width: 44px;
    z-index: 1;
}
.icon-btn:hover,
.icon-btn:focus { color: var(--text); outline: 0; }
.auth-submit {
    font-size: 15px;
    margin-top: 2px;
    min-height: 48px;
    width: 100%;
}
.auth-link {
    color: var(--text);
    display: inline-flex;
    font-weight: 700;
    margin-top: 17px;
    min-height: 36px;
}
.auth-link:hover { color: var(--success-dark); }

.page-head {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 18px;
}
.page-head h1 { font-size: 26px; font-weight: 400; margin: 0; }
.cards {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    margin-bottom: 18px;
}
.metric,
.panel,
.row-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(42,63,84,.06);
}
.metric { min-height: 104px; padding: 18px; }
.metric span { color: var(--muted); display: block; margin-bottom: 10px; }
.metric strong { color: var(--text); display: block; font-size: 28px; font-weight: 600; }
.panel { margin-bottom: 18px; padding: 18px; }

.btn {
    align-items: center;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    color: #333;
    cursor: pointer;
    display: inline-flex;
    font-weight: 700;
    gap: 6px;
    justify-content: center;
    min-height: 40px;
    padding: 8px 13px;
    touch-action: manipulation;
}
.btn.primary,
.btn-primary { background: var(--success); border-color: var(--success); color: #fff; }
.btn.primary:hover,
.btn-primary:hover { background: var(--success-dark); border-color: var(--success-dark); }
.btn-default { background: #fff; border-color: #ccc; color: #333; }
.btn-sm { font-size: 13px; min-height: 36px; padding: 7px 10px; }

label { color: var(--text); display: grid; font-weight: 700; gap: 7px; }
input,
select,
textarea {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
    font: inherit;
    font-size: 16px;
    min-height: 42px;
    padding: 9px 12px;
    width: 100%;
}
textarea { resize: vertical; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(220px, 1fr)); }
.full,
.form-actions { grid-column: 1 / -1; }
.check { align-items: center; display: flex; gap: 8px; }
.check input { height: 20px; width: 20px; }
.filters {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    margin-bottom: 18px;
}
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
table { border-collapse: collapse; min-width: 760px; width: 100%; }
th,
td { border-bottom: 1px solid var(--line); padding: 11px 9px; text-align: left; vertical-align: top; }
tbody tr:nth-child(odd) { background: #f9f9f9; }
th { color: var(--text); font-size: 13px; font-weight: 600; }
.badge {
    background: #d9534f;
    border-radius: 3px;
    color: #fff;
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 7px;
}
.pos { color: #3c763d; }
.neg { color: var(--danger); }
.alert {
    background: #f2dede;
    border: 1px solid #ebccd1;
    border-radius: 4px;
    color: var(--danger);
    font-weight: 700;
    margin: 12px 0;
    padding: 12px 14px;
}
.success {
    background: #dff0d8;
    border: 1px solid #d6e9c6;
    border-radius: 4px;
    color: #3c763d;
    font-weight: 700;
    margin: 12px 0;
    padding: 12px 14px;
}
.list-grid { display: grid; gap: 10px; }
.row-card { display: grid; gap: 6px; padding: 12px; }
.head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.compact-filters {
    grid-template-columns: minmax(220px, 1fr) auto;
}
.entity-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
}
.entity-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(42,63,84,.06);
    display: grid;
    gap: 14px;
    padding: 16px;
}
.entity-head {
    align-items: center;
    display: flex;
    gap: 12px;
    min-width: 0;
}
.entity-head strong {
    display: block;
    font-size: 16px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
.entity-head small {
    display: block;
    line-height: 1.35;
    margin-top: 3px;
    overflow-wrap: anywhere;
}
.entity-avatar,
.user-photo {
    border-radius: 14px;
    flex: 0 0 52px;
    height: 52px;
    width: 52px;
}
.entity-avatar {
    align-items: center;
    background: #eaf8f4;
    color: var(--success-dark);
    display: inline-flex;
    font-weight: 800;
    justify-content: center;
}
.doc-avatar { color: var(--text); }
.user-photo { object-fit: cover; }
.entity-meta {
    display: grid;
    gap: 8px;
    margin: 0;
}
.entity-meta div {
    display: grid;
    gap: 2px;
}
.entity-meta dt {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}
.entity-meta dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.entity-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.empty-state {
    grid-column: 1 / -1;
}
.empty-state strong,
.empty-state span { display: block; }

.mobile-cards { display: none; }
.mobile-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(42,63,84,.06);
    display: grid;
    gap: 12px;
    padding: 14px;
}
.mobile-card-head {
    align-items: flex-start;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}
.mobile-card-head strong {
    font-size: 16px;
    line-height: 1.25;
    min-width: 0;
    overflow-wrap: anywhere;
}
.mobile-card-head span {
    color: var(--success-dark);
    font-weight: 700;
    white-space: nowrap;
}
.mobile-card dl { display: grid; gap: 8px; margin: 0; }
.mobile-card dl div { display: grid; gap: 2px; }
.mobile-card dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}
.mobile-card dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 1100px) {
    .cards { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    .entity-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}

@media (max-width: 900px) {
    body.app-page { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
    .app-sidebar {
        bottom: 0;
        box-shadow: 0 -8px 20px rgba(23,45,68,.16);
        position: fixed;
        top: auto;
        width: 100%;
        z-index: 30;
    }
    .sidebar-brand,
    .sidebar-profile,
    .sidebar-footer,
    .sidebar-menu small { display: none; }
    .sidebar-menu {
        display: grid;
        gap: 2px;
        grid-auto-columns: minmax(68px, 1fr);
        grid-auto-flow: column;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        padding: 6px 8px max(8px, env(safe-area-inset-bottom));
        scrollbar-width: none;
    }
    .sidebar-menu::-webkit-scrollbar { display: none; }
    .sidebar-menu a {
        border: 0;
        border-radius: 6px;
        flex-direction: column;
        font-size: 11px;
        gap: 4px;
        justify-content: center;
        min-height: 60px;
        min-width: 68px;
        padding: 7px 6px;
        text-align: center;
        white-space: nowrap;
    }
    .sidebar-menu a:hover { box-shadow: inset 0 3px 0 var(--success); }
    .sidebar-menu i { font-size: 22px; }
    .topbar {
        left: 0;
        position: sticky;
        top: 0;
    }
    .content {
        margin-left: 0;
        padding: 24px 16px calc(34px + env(safe-area-inset-bottom));
    }
    .cards,
    .filters,
    .form-grid,
    .entity-grid,
    .compact-filters { grid-template-columns: 1fr; }
    .page-head { align-items: stretch; flex-direction: column; }
    .page-head .btn { width: 100%; }
    .head-actions { display: grid; grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .topbar { gap: 10px; padding: 8px 12px; }
    .topbar-title strong { font-size: 15px; }
    .topbar-title span { display: none; }
    .topbar-user > span:not(.topbar-avatar) { display: none; }
    .metric strong { font-size: 24px; }
    .panel,
    .metric { padding: 14px; }
    .table-wrap table { display: none; }
    .mobile-cards { display: grid; gap: 12px; }
    .filters .btn,
    .form-actions .btn,
    .entity-actions .btn { width: 100%; }
    .auth-shell {
        align-items: stretch;
        padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
    .login-box {
        align-self: center;
        border-radius: 14px;
        padding: 24px;
    }
}

@media (max-width: 520px) {
    .content { padding: 18px 12px calc(28px + env(safe-area-inset-bottom)); }
    .page-head h1 { font-size: 23px; }
    .sidebar-menu { grid-auto-columns: minmax(56px, 1fr); }
    .sidebar-menu a { font-size: 0; min-width: 56px; }
    .sidebar-menu i { font-size: 24px; }
    .topbar-user .btn { padding: 7px 8px; }
    .login-box { padding: 22px; }
    .auth-brand {
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 22px;
    }
    .auth-brand-icon {
        border-radius: 13px;
        flex-basis: 46px;
        height: 46px;
        width: 46px;
    }
    .login-box h1 { font-size: 25px; }
    .cards { gap: 12px; }
}

@media (max-width: 390px) {
    .auth-shell { padding-left: 0; padding-right: 0; }
    .login-box {
        border-left: 0;
        border-radius: 0;
        border-right: 0;
        box-shadow: none;
        width: 100%;
    }
}
