* {
        box-sizing: border-box;
}

html,
body {
        width: 100%;
        min-height: 100%;
        margin: 0;
        font-family: Arial, sans-serif;
        color: #1f2d3d;
        background: #f5f8fc;
}

button,
input {
    font: inherit;
}

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

.aside {
    width: 240px;
    min-height: 100vh;
    background: #fff;
    border-right: 1px solid #dbe7f3;
    box-shadow: 4px 0 20px rgba(15, 23, 42, .04);
}

.logo {
    height: 72px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    border-bottom: 1px solid #eef4fa;
}

.logo-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border: 1px solid #c7ddff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, .12);
}

.logo-text {
    color: #1e3a5f;
    font-size: 18px;
    font-weight: 700;
}

.nav {
    padding: 18px 12px;
}

.nav-title {
    display: block;
    padding: 0 10px 10px;
    color: #7b93ad;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.nav-link {
    width: 100%;
    min-height: 42px;
    margin-bottom: 6px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #35506b;
    border-radius: 12px;
    text-decoration: none;
    transition: .2s;
}

.nav-link:hover {
    color: #0f4c81;
    background: #f4f9ff;
    transform: translateX(2px);
}

.nav-link.active {
    color: #fff;
    background: linear-gradient(135deg, #3498db, #5dade2);
    box-shadow: 0 10px 20px rgba(52, 152, 219, .22);
}

.main {
    width: 100%;
    min-width: 0;
}

.header {
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    background: #f5f8fc;
    border-bottom: 1px solid #dbe7f3;
}

.header h1 {
    margin: 0;
    font-size: 24px;
    color: #16365f;
}

.content {
    padding: 24px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.card,
.panel {
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(25, 72, 130, .06);
}

.card {
    padding: 18px;
}

.card span {
    display: block;
    margin-bottom: 8px;
    color: #6f8197;
    font-size: 14px;
}

.card strong {
    color: #16365f;
    font-size: 30px;
}

.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.search {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 14px;
    outline: none;
}

.search:focus,
.form-grid input:focus {
    border-color: #9cccf3;
    box-shadow: 0 0 0 3px rgba(29, 126, 214, .08);
}

.panel {
    padding: 18px;
}

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

.panel-head h2 {
    margin: 0;
    color: #16365f;
    font-size: 20px;
}

.panel-head p {
    margin: 4px 0 0;
    color: #6f8197;
    font-size: 14px;
}

.btn {
    cursor: pointer;
    border: none;
    border-radius: 12px;
    padding: 11px 16px;
    font-weight: 600;
}

.btn-primary {
    color: #fff;
    background: #1d7ed6;
}

.btn-primary:hover {
    background: #166bb8;
}

.btn-soft {
    color: #37658f;
    background: #eef5fc;
}

.btn-soft:hover {
    background: #e2edf8;
}

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

.letters {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.letter {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    color: inherit;
    background: #fbfdff;
    border: 1px solid #e2edf8;
    border-radius: 14px;
    transition: .2s;
}

.letter:hover {
    background: #f5faff;
    border-color: #b9d8f3;
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(25, 72, 130, .08);
}

.letter-main {
    min-width: 0;
    flex: 1;
}

.letter-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

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

.letter-action {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 10px;
    color: #37658f;
    background: #eef5fc;
    border: none;
    border-radius: 10px;
    text-decoration: none;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
}

.letter-action:hover {
    background: #e2edf8;
}

.letter-action-download {
    color: #fff;
    background: #1d7ed6;
}

.letter-action-download:hover {
    background: #166bb8;
}

.letter-action-delete {
    color: #b42318;
    background: #fff0f0;
}

.letter-action-delete:hover {
    background: #ffe0e0;
}

.letter h3 {
    margin: 0;
    color: #1f2d3d;
    font-size: 16px;
}

.letter p {
    margin: 6px 0 0;
    color: #5d7087;
    font-size: 14px;
}

.date {
    color: #8a9bad;
    white-space: nowrap;
    font-size: 13px;
}

.tag {
    display: inline-block;
    padding: 5px 10px;
    color: #37658f;
    background: #eef5fc;
    border-radius: 999px;
    font-size: 12px;
}

.empty {
    text-align: center;
    padding: 48px 20px;
    background: #f8fbff;
    border: 1px dashed #c7d8ea;
    border-radius: 14px;
}

.empty h3 {
    margin: 0 0 6px;
    color: #16365f;
}

.empty p {
    margin: 0;
    color: #6f8197;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(12, 31, 55, .48);
    backdrop-filter: blur(4px);
}

.modal {
    width: 100%;
    max-width: 760px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 22px;
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 22px;
    box-shadow: 0 24px 80px rgba(15, 45, 82, .28);
}

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

.modal-head h2 {
    margin: 0;
    color: #16365f;
    font-size: 22px;
}

.modal-head p {
    margin: 6px 0 0;
    color: #6f8197;
    font-size: 14px;
}

.close {
    width: 38px;
    height: 38px;
    color: #37658f;
    background: #eef5fc;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
}

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

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.form-grid span {
    color: #6f8197;
    font-size: 13px;
}

.form-grid input {
    height: 44px;
    padding: 0 12px;
    color: #1f2d3d;
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 12px;
    outline: none;
}

.form-grid input[type="file"] {
    height: auto;
    padding: 10px 12px;
}

.form-grid textarea {
    min-height: 90px;
    padding: 12px;
    resize: vertical;
    color: #1f2d3d;
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 12px;
    outline: none;
    font: inherit;
}

.form-grid textarea:focus {
    border-color: #9cccf3;
    box-shadow: 0 0 0 3px rgba(29, 126, 214, .08);
}

.file-hint {
    color: #6f8197;
    font-size: 12px;
}

.error {
    margin: 14px 0 0;
    padding: 10px 12px;
    color: #b42318;
    background: #fff0f0;
    border-radius: 12px;
    font-size: 13px;
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

@media (max-width: 700px) {
    .layout {
        display: block;
    }

    .aside {
        width: 100%;
        min-height: auto;
    }

    .nav-link {
        display: inline-flex;
        width: auto;
        margin-right: 6px;
    }

    .content {
        padding: 16px;
    }

    .toolbar,
    .panel-head,
    .letter,
    .letter-top,
    .letter-actions,
    .actions {
        flex-direction: column;
        align-items: stretch;
    }

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


.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at top, #dbeafe 0, #f5f8fc 42%, #eef5fc 100%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 28px;
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 24px;
    box-shadow: 0 24px 80px rgba(15, 45, 82, .14);
}

.login-icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border: 1px solid #c7ddff;
    font-size: 24px;
}

.login-card h1 {
    margin: 0;
    color: #16365f;
    font-size: 26px;
}

.login-card p {
    margin: 8px 0 22px;
    color: #6f8197;
}

.login-card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.login-card label span {
    color: #6f8197;
    font-size: 13px;
}

.login-card input {
    height: 44px;
    padding: 0 12px;
    color: #1f2d3d;
    background: #fff;
    border: 1px solid #dbe7f5;
    border-radius: 12px;
    outline: none;
}

.login-card input:focus {
    border-color: #9cccf3;
    box-shadow: 0 0 0 3px rgba(29, 126, 214, .08);
}

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

.logout-button {
    width: calc(100% - 24px);
    margin: 12px;
    cursor: pointer;
    color: #37658f;
    background: #eef5fc;
    border: none;
    border-radius: 12px;
    padding: 11px 16px;
    font-weight: 600;
}

.logout-button:hover {
    background: #e2edf8;
}

.letter-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.file-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.file-badge.has-file {
    color: #17663a;
    background: #e9f8ef;
}

.file-badge.no-file {
    color: #8a6a10;
    background: #fff6d8;
}

.letter-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.letter-info {
    min-width: 0;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e2edf8;
    border-radius: 12px;
}

.letter-info span {
    display: block;
    margin-bottom: 4px;
    color: #7b93ad;
    font-size: 12px;
}

.letter-info strong {
    display: block;
    overflow: hidden;
    color: #1f2d3d;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.letter-info-link {
    width: 100%;
    cursor: pointer;
    text-align: left;
    font: inherit;
}

.letter-info-link:hover {
    border-color: #9cccf3;
    background: #f5faff;
    box-shadow: 0 0 0 3px rgba(29, 126, 214, .06);
}

.required-mark {
    color: #d93025;
}

.application-block {
    grid-column: 1 / -1;
    padding: 16px;
    background: #f8fbff;
    border: 2px solid #dbe7f5;
    border-radius: 16px;
}

.application-block-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.application-block-head h3 {
    margin: 0;
    color: #16365f;
    font-size: 17px;
}

.application-block-head p {
    margin: 5px 0 0;
    color: #6f8197;
    font-size: 13px;
}

.application-block-badge {
    flex-shrink: 0;
    padding: 5px 9px;
    color: #37658f !important;
    background: #e7f2fc;
    border-radius: 999px;
    font-size: 11px !important;
    font-weight: 600;
}

.application-current,
.application-add-area {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #dbe7f5;
}

.application-current h4,
.application-add-area h4 {
    margin: 0 0 10px;
    color: #35506b;
    font-size: 13px;
}

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

.application-field {
    min-width: 0;
    padding: 12px;
    background: #fff;
    border: 1px solid #e2edf8;
    border-radius: 12px;
}

.application-field > span {
    color: #5d7087;
    font-size: 13px;
    font-weight: 600;
}

.application-field input {
    width: 100%;
}

.application-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.application-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e2edf8;
    border-radius: 12px;
}

.application-info {
    min-width: 0;
}

.application-info strong {
    display: block;
    overflow: hidden;
    color: #1f2d3d;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.application-info span {
    display: block;
    margin-top: 3px;
    color: #7b93ad;
    font-size: 12px;
}

.application-actions {
    display: flex;
    flex-shrink: 0;
    gap: 7px;
}

.application-action {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 10px;
    cursor: pointer;
    color: #37658f;
    background: #eef5fc;
    border: none;
    border-radius: 9px;
    text-decoration: none;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
}

.application-action:hover {
    background: #e2edf8;
}

.application-action:disabled {
    cursor: not-allowed;
    opacity: .6;
}

.application-delete {
    color: #b42318;
    background: #fff0f0;
}

.application-delete:hover {
    background: #ffe0e0;
}

.application-empty {
    margin: 0 !important;
    padding: 16px;
    color: #6f8197;
    text-align: center;
    background: #fff;
    border: 1px dashed #c7d8ea;
    border-radius: 12px;
    font-size: 13px;
}

.application-error {
    margin: 0 0 10px !important;
}

@media (max-width: 700px) {
    .application-block-head {
        flex-direction: column;
    }

    .application-add-grid {
        grid-template-columns: 1fr;
    }

    .application-item {
        flex-direction: column;
        align-items: stretch;
    }

    .application-actions {
        width: 100%;
    }

    .application-action {
        flex: 1;
    }
}

/* Файлы прямо в карточке письма */
.letter-files {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #dbe7f5;
}

.letter-files-title {
    display: block;
    margin-bottom: 8px;
    color: #6f8197;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.letter-files-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.letter-file {
    display: inline-flex;
    min-width: 0;
    max-width: 100%;
    flex-direction: column;
    gap: 2px;
    padding: 8px 11px;
    color: #37658f;
    background: #eef5fc;
    border: 1px solid #dbe7f5;
    border-radius: 10px;
    text-decoration: none;
}

.letter-file:hover {
    background: #e2edf8;
    border-color: #b9d8f3;
}

.letter-file-primary {
    color: #17663a;
    background: #edf9f2;
    border-color: #d4eedf;
}

.letter-file-primary:hover {
    background: #e3f5eb;
    border-color: #bfe3ce;
}

.letter-file-kind {
    color: #7b93ad;
    font-size: 10px;
    font-weight: 600;
}

.letter-file strong {
    display: block;
    overflow: hidden;
    max-width: 280px;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* В форме теперь только загрузка файлов, без URL. */
.application-add-grid {
    grid-template-columns: 1fr;
}

@media (max-width: 700px) {
    .letter-files-list {
        flex-direction: column;
    }

    .letter-file {
        width: 100%;
    }

    .letter-file strong {
        max-width: 100%;
    }
}

/* Disabled form fields: visibly locked in edit mode */
.form-grid input:disabled,
.form-grid textarea:disabled,
.form-grid select:disabled,
.application-field input:disabled {
    color: #7b8794;
    -webkit-text-fill-color: #7b8794;
    background: #eef1f4;
    border-color: #d5dbe2;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 1;
}

.form-grid input:disabled:focus,
.form-grid textarea:disabled:focus,
.form-grid select:disabled:focus,
.application-field input:disabled:focus {
    border-color: #d5dbe2;
    box-shadow: none;
}

.form-grid input:disabled::-webkit-calendar-picker-indicator {
    cursor: not-allowed;
    opacity: .45;
}
