:root {
    --page: #f5f7f4;
    --surface: #ffffff;
    --surface-soft: #f8faf7;
    --ink: #17231d;
    --muted: #66736b;
    --brand: #12392a;
    --brand-2: #2f6f4f;
    --accent: #d6aa3d;
    --line: #dfe6df;
    --danger: #a33a35;
    --shadow: 0 16px 42px rgba(23, 35, 29, .08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: var(--page);
    color: var(--ink);
}

a {
    color: var(--brand);
    text-decoration: none;
    font-weight: 750;
}

.app-shell {
    display: grid;
    grid-template-columns: 292px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #ffffff;
    border-right: 1px solid var(--line);
    padding: 20px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand-box {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 6px 6px 18px;
    border-bottom: 1px solid var(--line);
}

.brand-logo {
    width: 248px;
    max-width: 100%;
    height: auto;
    flex: 0 0 auto;
    display: block;
    object-fit: contain;
}

.brand-title {
    font-weight: 900;
    color: var(--brand);
    font-size: 20px;
    line-height: 1.05;
}

.brand-sub {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    margin-top: 4px;
}

.nav {
    display: grid;
    gap: 4px;
    margin-top: 18px;
    max-height: calc(100vh - 180px);
    overflow: auto;
    padding-right: 2px;
}

.nav a,
.nav span {
    padding: 10px 12px;
    border-radius: var(--radius);
    font-weight: 800;
    color: var(--ink);
    display: block;
}

.nav a:hover,
.nav a.active {
    background: var(--brand);
    color: #ffffff;
}

.nav span {
    opacity: .55;
}

.nav-label {
    margin: 16px 10px 4px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 900;
}

.logout-box {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 16px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
}

.user-mini {
    display: grid;
    gap: 3px;
    margin-bottom: 10px;
}

.user-mini span,
.muted {
    color: var(--muted);
}

.logout-box button,
.primary,
.button {
    border: 0;
    background: var(--brand);
    color: #ffffff;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-weight: 850;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
}

.button.light {
    background: #ffffff;
    color: var(--brand);
    border: 1px solid var(--line);
}

.main {
    padding: 32px 40px 64px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
    align-items: flex-start;
}

h1 {
    margin: 0;
    color: var(--ink);
    font-size: 34px;
    line-height: 1.12;
    font-weight: 900;
}

.topbar p {
    margin: 8px 0 0;
    color: var(--muted);
}

.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.quick-actions a {
    background: var(--brand);
    color: #ffffff;
    border-radius: var(--radius);
    padding: 10px 13px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

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

.card h2 {
    margin: 0;
    color: var(--ink);
    font-size: 20px;
    font-weight: 900;
}

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

.kpi {
    position: relative;
    overflow: hidden;
}

.kpi::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--brand), var(--accent));
}

.kpi span {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 900;
}

.kpi strong {
    display: block;
    color: var(--brand);
    font-size: 34px;
    margin-top: 8px;
}

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

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: #ffffff;
}

th {
    background: var(--surface-soft);
    color: var(--ink);
    padding: 12px 13px;
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 900;
}

td {
    padding: 12px 13px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    padding: 6px 10px;
    border-radius: 999px;
    background: #edf5ee;
    color: var(--brand);
    font-size: 12px;
    font-weight: 900;
}

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

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

label {
    display: block;
    margin-bottom: 7px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 850;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 13px;
    background: #ffffff;
    font: inherit;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(47, 111, 79, .18);
    border-color: var(--brand-2);
}

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

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.alert {
    background: #edf5ee;
    border: 1px solid #d5e6d8;
    color: var(--brand);
    padding: 13px 14px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-weight: 850;
}

.alert.error {
    background: #fae8e7;
    color: var(--danger);
    border-color: #f1c4c1;
}

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

.doc-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-soft);
    display: grid;
    gap: 10px;
}

.doc-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: var(--radius);
}

.file-icon {
    height: 120px;
    background: var(--brand);
    color: #ffffff;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    font-weight: 950;
}

.timeline {
    display: grid;
    gap: 12px;
}

.timeline div {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
}

.timeline span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 30px;
    background:
        linear-gradient(135deg, rgba(18, 57, 42, .08), rgba(214, 170, 61, .06)),
        var(--page);
}

.login-card {
    width: min(520px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}

.login-brand {
    border: 0;
    padding: 0 0 22px;
    justify-content: center;
}

.login-brand .brand-logo {
    width: 420px;
}

.login-card h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.login-card p {
    color: var(--muted);
    margin: 0 0 20px;
}

.login-card label {
    margin-top: 14px;
}

.login-card button {
    width: 100%;
    margin-top: 18px;
}

.item-row {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) 100px 100px 130px;
    gap: 10px;
    margin-bottom: 10px;
    align-items: start;
}

.item-row textarea {
    min-height: 70px;
}

.dropzone {
    border: 2px dashed var(--line);
    border-radius: var(--radius);
    padding: 24px;
    background: var(--surface-soft);
    text-align: center;
}

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

    .sidebar {
        position: relative;
        height: auto;
    }

    .logout-box {
        position: relative;
        left: auto;
        right: auto;
        bottom: auto;
        margin-top: 20px;
    }

    .main {
        padding: 24px;
    }

    .kpi-grid,
    .grid-2,
    .form-grid,
    .doc-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        display: grid;
    }

    .quick-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 720px) {
    .main {
        padding: 18px;
    }

    h1 {
        font-size: 28px;
    }

    .item-row {
        grid-template-columns: 1fr;
    }
}

.chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 2000;
}

.chat-toggle {
    border: 0;
    background: var(--brand);
    color: #ffffff;
    border-radius: var(--radius);
    min-height: 48px;
    padding: 0 16px;
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
    cursor: pointer;
}

.chat-toggle strong {
    min-width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--ink);
    display: grid;
    place-items: center;
    font-size: 12px;
}

.chat-panel {
    position: absolute;
    right: 0;
    bottom: 58px;
    width: min(920px, calc(100vw - 32px));
    height: min(680px, calc(100vh - 96px));
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 24px 70px rgba(23, 35, 29, .22);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.chat-panel[hidden] {
    display: none;
}

.chat-panel-head {
    min-height: 58px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.chat-panel-head strong,
.chat-thread-head strong {
    display: block;
    font-weight: 950;
}

.chat-panel-head span,
.chat-thread-head span,
.chat-message-meta {
    color: var(--muted);
    font-size: 12px;
}

.chat-close {
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.chat-panel-body {
    min-height: 0;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
}

.chat-sidebar {
    min-height: 0;
    border-right: 1px solid var(--line);
    padding: 12px;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 10px;
    background: var(--surface-soft);
}

.chat-start,
.chat-group-form {
    display: grid;
    gap: 8px;
}

.chat-start {
    grid-template-columns: minmax(0, 1fr) auto;
}

.chat-group-form {
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.chat-list {
    min-height: 0;
    overflow: auto;
    display: grid;
    align-content: start;
    gap: 8px;
}

.chat-list-item {
    position: relative;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #ffffff;
    padding: 10px 38px 10px 10px;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 4px;
}

.chat-list-item.active {
    border-color: var(--brand-2);
    background: #edf5ee;
}

.chat-list-item strong,
.chat-list-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-list-item span {
    color: var(--muted);
    font-size: 12px;
}

.chat-list-item em {
    position: absolute;
    top: 10px;
    right: 10px;
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--ink);
    display: grid;
    place-items: center;
    font-size: 12px;
    font-style: normal;
    font-weight: 950;
}

.chat-thread {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-thread-head {
    min-height: 58px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.chat-messages {
    min-height: 0;
    overflow: auto;
    padding: 14px;
    background: #f6f8f5;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-empty {
    color: var(--muted);
    font-weight: 800;
    padding: 12px;
}

.chat-message {
    max-width: 76%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #ffffff;
    padding: 10px 12px;
    align-self: flex-start;
    display: grid;
    gap: 6px;
}

.chat-message.own {
    align-self: flex-end;
    background: #edf5ee;
    border-color: #d5e6d8;
}

.chat-message p {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-attachment {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 7px 9px;
    background: #ffffff;
    overflow-wrap: anywhere;
}

.chat-compose {
    border-top: 1px solid var(--line);
    padding: 12px;
    display: grid;
    gap: 10px;
}

.chat-compose textarea {
    min-height: 58px;
    max-height: 140px;
}

.chat-compose-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.chat-compose input[type="file"] {
    min-height: 40px;
    padding: 8px;
}

@media (max-width: 780px) {
    .chat-widget {
        left: 12px;
        right: 12px;
        bottom: 12px;
    }

    .chat-toggle {
        margin-left: auto;
    }

    .chat-panel {
        left: 0;
        right: 0;
        width: 100%;
        height: min(84vh, 720px);
    }

    .chat-panel-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .chat-sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--line);
        max-height: 250px;
    }

    .chat-message {
        max-width: 90%;
    }

    .chat-compose-actions {
        grid-template-columns: 1fr;
    }
}
