* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    background: #c9daed;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

.hero {
    position: relative;
    background: #1f5bff;
    color: #fff;
    text-align: center;
    padding: 88px 24px 64px;
}

.btn-admin {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    color: #fff;
    border: 1px solid #fff;
    border-radius: 999px;
    padding: 10px 20px;
    font-size: 17px;
    line-height: 1.2;
    cursor: pointer;
}

.btn-admin:hover {
    background: rgba(255, 255, 255, 0.12);
}

.hero h1 {
    margin: 0;
    font-size: 56px;
    line-height: 1.1;
    font-weight: 700;
}

.page {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 24px;
    max-width: 1760px;
    margin: 0 auto;
    padding: 80px 24px 80px;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 8px;
    position: sticky;
    top: 24px;
    align-self: start;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 142px;
    height: 45px;
    padding: 0 14px;
    border-radius: 16px;
    background: #f7f7f7;
    font-size: 20px;
    overflow: hidden;
}

.nav-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #1d3bbd;
    flex: 0 0 14px;
    opacity: 0;
}

.nav-item.is-active .nav-dot {
    opacity: 1;
}

.nav-item.admin-only[hidden],
#send[hidden],
body:not(.is-admin) .nav-item.admin-only,
body:not(.is-admin) #send {
    display: none !important;
}

body.is-admin .nav-item.admin-only {
    display: flex;
}

.section {
    scroll-margin-top: 24px;
    margin-bottom: 80px;
}

#view {
    padding-top: 56px;
}

.page-title {
    margin: 100px 0px 20px 0px;
    font-size: 50px;
    line-height: 1.15;
    font-weight: 700;
}

.cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(240px, 1fr));
    gap: 28px;
}

.upload-card {
    position: relative;
    min-height: 450px;
    border-radius: 16px;
    background: #f7f7f7;
    padding: 28px 22px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.card-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
}

.card-icon svg {
    width: 56px;
    height: 56px;
}

.card-icon-people svg {
    width: 72px;
    height: 48px;
}

.card-text {
    margin: 36px 0 24px;
    font-size: 25px;
    line-height: 1.35;
    font-weight: 700;
}

.btn-upload {
    position: absolute;
    top: calc(50% + 106px);
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    width: 184px;
    height: 73px;
    border: 0;
    border-radius: 10px;
    background: #1d3bbd;
    color: #fff;
    font-size: 20px;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.btn-upload:hover {
    background: #162f96;
}

.btn-upload:disabled {
    opacity: 0.65;
    cursor: wait;
}

.card-status {
    position: absolute;
    left: 22px;
    right: 22px;
    bottom: 24px;
    margin: 0;
    width: auto;
    min-height: 28px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* padding: 6px 16px; */
    font-size: 20px;
    line-height: 1.35;
    text-align: center;
}

.card-status.is-error {
    background: #fecbc1;
}

.card-status.is-success {
    background: #a2deae;
}

.filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
    align-items: start;
}

.filter-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.filter-title,
.filter-panel {
    background: #fcf2f9;
    border-radius: 10px;
}

.filter-title {
    padding: 14px 18px;
    font-size: 20px;
    font-weight: 400;
}

.filter-panel {
    height: 340px;
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.metric-row select {
    min-width: 90px;
    padding: 4px 8px;
    border: 1px solid #c8cede;
    border-radius: 6px;
    background: #fff;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.toggle-row,
.check-item,
.metric-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    line-height: 1.45;
    margin-bottom: 12px;
}

.toggle-row input,
.check-item input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch {
    width: 39px;
    height: 23px;
    border-radius: 999px;
    background: #c5c7d1;
    position: relative;
    flex: 0 0 auto;
}

.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #fff;
}

.toggle-row input:checked + .switch {
    background: #1d3bbd;
}

.toggle-row input:checked + .switch::after {
    left: 19px;
}

.dot {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #8b8fa2;
    flex: 0 0 auto;
}

.check-item input:checked + .dot {
    background: #1d3bbd;
}

.check-item[hidden] {
    display: none;
}

.check-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
}

.fio-search {
    width: 30%;
    margin: 4px 0 14px;
    padding: 8px 12px;
    border: 1px solid #d4c4d0;
    border-radius: 8px;
    background: #fff;
    font-size: 18px;
}

.metric-row {
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.metric-row input[type="number"] {
    width: 92px;
    height: 40px;
    border: 1px solid #c5b4c2;
    border-radius: 8px;
    background: #fff;
    text-align: center;
    padding: 4px 6px;
}

.metric-row input[type="number"]::-webkit-inner-spin-button,
.metric-row input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    height: 28px;
}

.list-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1px;
}

.table-wrap {
    background: #fcf2f9;
    border-radius: 10px;
    overflow: auto;
    max-height: 920px;
}

.students-table {
    width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    font-size: 16px;
}

.students-table th,
.students-table td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid #f0d6ea;
}

.students-table th {
    font-weight: 700;
    background: #f8e6f3;
    text-align: center;
}

.students-table thead tr:first-child th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.students-table thead tr:nth-child(2) th {
    position: sticky;
    top: 38px;
    z-index: 2;
}

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

.students-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.empty {
    text-align: center;
    color: #5b5b5b;
    white-space: normal !important;
}

.toast {
    position: fixed;
    top: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    padding: 16px 24px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(29, 59, 189, 0.18);
    font-size: 20px;
    font-weight: 700;
}

.toast[hidden] {
    display: none;
}

.toast-check {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #2f9e44;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
}

.toast.is-error .toast-check {
    background: #c92a2a;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(170, 198, 224, 0.72);
    padding: 24px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-card {
    width: min(520px, 100%);
    background: #fff;
    border-radius: 28px;
    padding: 36px 40px 32px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(29, 59, 189, 0.12);
}

.modal-title {
    margin: 0 0 28px;
    font-size: 24px;
    font-weight: 700;
}

.modal-input {
    width: 100%;
    height: 52px;
    border: 0;
    border-radius: 999px;
    background: #f4c6ea;
    padding: 0 22px;
    font-size: 18px;
    color: #4a4a4a;
    outline: none;
    box-shadow: none;
}

.modal-input:focus {
    outline: none;
    box-shadow: none;
    border: 0;
}

.modal-input::placeholder {
    color: #c48bb8;
}

.modal-error {
    margin: 14px 0 0;
    color: #c92a2a;
    font-size: 16px;
}

.modal-error[hidden] {
    display: none;
}

.modal-ok {
    display: block;
    margin: 28px auto 0;
    min-width: 92px;
    height: 48px;
    padding: 0 28px;
    border: 0;
    border-radius: 999px;
    background: #e85ec8;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
}

.modal-ok:hover {
    background: #d44eb6;
}

.sub-title {
    margin: 0 0 24px;
    font-size: 22px;
    font-weight: 400;
}

.templates-layout {
    display: grid;
    grid-template-columns: max-content max-content;
    column-gap: 80px;
    row-gap: 14px;
    align-items: start;
    margin-top: 50px;
}

.templates-heading {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
    align-self: end;
}

.templates {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.custom-col {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.custom-template-body {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 14px;
}

.insert-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 260px;
    padding-left: 29px;
    margin-top: 4px;
}

.btn-save-template {
    align-self: flex-start;
    margin: 4px 0 8px 29px;
    min-width: 220px;
    height: 56px;
    padding: 0 24px;
    border: 2px solid #1d3bbd;
    border-radius: 999px;
    background: #fff;
    color: #1d3bbd;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.btn-save-template:hover:not(:disabled) {
    background: #1d3bbd;
    color: #fff;
}

.btn-save-template:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.template-row {
    position: relative;
    display: flex;
    align-items: center;
}

.btn-delete-sample {
    position: absolute;
    right: -14px;
    bottom: -14px;
    z-index: 2;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #b02a2a;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.btn-delete-sample:hover {
    background: rgba(201, 42, 42, 0.12);
}

.btn-delete-sample:disabled {
    opacity: .5;
    cursor: wait;
}

.sms-bubble {
    position: relative;
    width: 500px;
    max-width: 100%;
    min-height: 156px;
    box-sizing: border-box;
    border-style: solid;
    border-color: transparent;
    border-width: 32px 36px;
    border-image-source: url("/static/sms_mailing/img/sms-bubble.png");
    border-image-slice: 32 36 32 36 fill;
    border-image-repeat: stretch;
    padding: 10px 14px 12px;
}

.template-row .sms-bubble {
    cursor: pointer;
}

.sms-bubble::before {
    content: "";
    position: absolute;
    z-index: 0;
    top: -10px;
    right: -13px;
    bottom: -25px;
    left: -16px;
    border-radius: 16px;
    background: #fcf2f9;
    opacity: 0;
    pointer-events: none;
}

.template-choice:has(input:checked) + .sms-bubble::before {
    opacity: 1;
}

.sms-bubble-text,
.sms-bubble textarea {
    position: relative;
    z-index: 1;
    display: block;
    box-sizing: border-box;
    margin: 0;
    width: 100%;
    height: auto;
    min-height: 48px;
    padding: 0;
    border: 0;
    overflow: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    text-align: left;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 20px;
    line-height: 1.35;
    font-weight: 400;
    color: #111;
    background: transparent;
}

.sms-bubble textarea {
    resize: none;
    outline: none;
    box-shadow: none;
    appearance: none;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 20px;
    line-height: 1.35;
    font-weight: 400;
}

.sms-bubble textarea::placeholder {
    color: rgba(0, 0, 0, 0.35);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 20px;
}

.sms-bubble textarea:focus::placeholder {
    color: transparent;
}

.template-choice {
    display: flex;
    align-items: center;
    flex: 0 0 15px;
    width: 15px;
    cursor: pointer;
}

.template-choice input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.template-choice input:checked + .dot {
    background: #1d3bbd;
}

.custom-template {
    min-width: 0;
}

.insert-title {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 400;
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.3;
}

.add-heading {
    margin: 0;
}

.btn-insert {
    border: 0;
    background: #fff;
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 18px;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.btn-insert:hover {
    background: #f7f7f7;
}

.insert-plus {
    color: #1d3bbd;
    font-weight: 700;
}

.btn-send {
    display: block;
    margin: 48px 0 0;
    min-width: 220px;
    height: 75px;
    padding: 0 28px;
    border: 0;
    border-radius: 50px;
    background: #f382d8;
    font-size: 20px;
    cursor: pointer;
}

.btn-send:hover:not(:disabled) {
    background: #e56bc8;
}

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

@media (max-width: 1100px) {
    .hero h1,
    .page-title {
        font-size: 36px;
    }

    .page {
        grid-template-columns: 1fr;
        padding: 32px 16px 56px;
    }

    .sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        position: static;
    }

    .cards,
    .filters {
        grid-template-columns: 1fr;
    }

    .list-header {
        flex-direction: column;
    }

    .templates-layout {
        grid-template-columns: 1fr;
        column-gap: 24px;
        row-gap: 24px;
    }

    .templates-heading,
    .templates,
    .custom-col {
        grid-column: 1;
        grid-row: auto;
    }

    .btn-admin {
        top: 12px;
        right: 12px;
        font-size: 15px;
        padding: 8px 16px;
    }
}

body.is-admin .students-table input.active-toggle {
    pointer-events: none;
    cursor: not-allowed;
    opacity: 0.55;
}

body:not(.is-admin) .students-table th.admin-col,
body:not(.is-admin) .students-table td.admin-col {
    display: none;
}

.students-table td.admin-col {
    width: 36px;
    text-align: center;
}

.students-table th.admin-col {
    width: 36px;
    text-align: center;
    vertical-align: middle;
}

.students-table input.active-toggle {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #1d3bbd;
}

.students-table input.active-toggle:disabled {
    cursor: pointer;
    opacity: 0.6;
}

.students-table input.threat-toggle {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #1d3bbd;
}

.students-table input.threat-toggle:disabled {
    opacity: 0.6;
    cursor: wait;
}

.students-table .select-all-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    gap: 0;
    font-size: 0;
}

.students-table .select-all-toggle .switch {
    width: 30px;
    height: 18px;
}

.students-table .select-all-toggle .switch::after {
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
}

.students-table .select-all-toggle input:checked + .switch::after {
    left: 14px;
}

body:not(.is-admin) .select-all-toggle {
    display: none !important;
}

.students-table .penalty-value {
    display: inline-block;
    min-width: 22px;
    padding: 2px 6px;
    border-radius: 6px;
    cursor: context-menu;
    transition: background-color .15s ease;
}

body.is-admin .students-table .penalty-value:hover {
    background: rgba(29, 59, 189, 0.10);
}

.students-table .penalty-value.is-saving {
    opacity: 0.6;
}

.students-table .penalty-input {
    width: 52px;
    height: 28px;
    padding: 2px 6px;
    border: 1px solid #1d3bbd;
    border-radius: 6px;
    background: #fff;
    font: inherit;
    font-size: 16px;
    text-align: center;
    outline: none;
    box-shadow: 0 0 0 2px rgba(29, 59, 189, 0.15);
}

.char-counter {
    margin: 6px 0 0 29px;
    font-size: 16px;
    line-height: 1.3;
    color: #5b5b5b;
}

.char-counter.is-over {
    color: #c92a2a;
    font-weight: 700;
}

/* Hero */
@media (max-width: 768px) {
    .hero {
        padding: 72px 16px 40px;
    }

    .hero h1 {
        font-size: 30px;
    }

    .btn-admin {
        top: 10px;
        right: 10px;
        padding: 7px 14px;
        font-size: 13px;
    }
}

/* Layout */
@media (max-width: 768px) {
    .page {
        padding: 24px 12px 48px;
        gap: 20px;
    }

    .section {
        margin-bottom: 48px;
        scroll-margin-top: 16px;
    }

    #view {
        padding-top: 28px;
    }

    .page-title {
        margin: 32px 0 14px;
        font-size: 26px;
    }

    .templates-heading {
        margin: 0;
    }

    .upload-title {
        margin-top: 24px;
    }
}

/* Sidebar */
@media (max-width: 768px) {
    .sidebar {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        padding: 4px 0 8px;
        scrollbar-width: none;
    }

    .sidebar::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        flex: 0 0 auto;
        width: auto;
        height: 42px;
        padding: 0 14px;
        font-size: 15px;
        border-radius: 12px;
    }
}

/* Upload cards */
@media (max-width: 768px) {
    .cards {
        gap: 14px;
    }

    .upload-card {
        min-height: auto;
        padding: 22px 16px 18px;
    }

    .card-icon {
        width: 56px;
        height: 56px;
        margin-top: 0;
    }

    .card-icon svg {
        width: 44px;
        height: 44px;
    }

    .card-icon-people svg {
        width: 56px;
        height: 38px;
    }

    .card-text {
        margin: 16px 0 18px;
        font-size: 19px;
    }

    .btn-upload {
        position: static;
        transform: none;
        width: 100%;
        height: 52px;
        margin: 0;
        font-size: 16px;
    }

    .card-status {
        position: static;
        margin-top: 12px;
        font-size: 15px;
        min-height: 24px;
        padding: 4px 12px;
    }
}

/* Filters */
@media (max-width: 768px) {
    .filter-title {
        font-size: 17px;
        padding: 12px 16px;
    }

    .filter-panel {
        height: auto;
        max-height: 320px;
        padding: 10px;
    }

    .toggle-row,
    .check-item,
    .metric-row {
        font-size: 15px;
        gap: 8px;
        margin-bottom: 10px;
    }

    .fio-search {
        width: 100%;
        font-size: 16px;
        padding: 8px 12px;
    }

    .metric-row {
        margin-bottom: 16px;
    }

    .metric-row input[type="number"] {
        width: 76px;
        height: 36px;
        font-size: 16px;
    }

    .metric-row select {
        font-size: 16px;
    }
}

/* Students table */
@media (max-width: 768px) {
    .list-header {
        flex-direction: column;
    }

    .table-wrap {
        max-height: 65vh;
        -webkit-overflow-scrolling: touch;
    }

    .students-table {
        width: auto;
        min-width: 720px;
        font-size: 13px;
    }

    .students-table th,
    .students-table td {
        padding: 8px 6px;
    }

    .students-table thead tr:nth-child(2) th {
        top: 34px;
    }

    .students-table .select-all-toggle {
        padding: 6px;
        margin: -6px;
    }
}

/* Templates */
@media (max-width: 768px) {
    .templates-layout {
        grid-template-columns: 1fr;
        column-gap: 0;
        row-gap: 20px;
        margin-top: 24px;
    }

    .templates {
        gap: 14px;
    }

    .template-row {
        align-items: flex-start;
    }

    .template-row .sms-bubble,
    .custom-template-body .sms-bubble {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }

    .sms-bubble {
        border-width: 24px 28px;
        padding: 8px 10px;
    }

    .sms-bubble-text,
    .sms-bubble textarea,
    .sms-bubble textarea::placeholder {
        font-size: 16px;
    }

    .sms-bubble::before {
        top: -6px;
        right: -6px;
        bottom: -12px;
        left: -6px;
    }

    .btn-delete-sample {
        right: -8px;
        bottom: -8px;
        width: 28px;
        height: 28px;
    }

    .btn-delete-sample svg {
        width: 16px;
        height: 16px;
    }

    .custom-template-body {
        align-items: flex-start;
        gap: 10px;
    }

    .insert-col {
        min-width: 0;
        padding-left: 0;
        margin-top: 8px;
    }

    .insert-title {
        font-size: 17px;
        margin-bottom: 8px;
    }

    .btn-insert {
        width: 100%;
        font-size: 15px;
        padding: 9px 14px;
        text-align: left;
    }

    .btn-save-template {
        margin: 4px 0 8px;
        align-self: stretch;
        width: 100%;
        height: 48px;
        font-size: 15px;
    }

    .char-counter {
        margin-left: 0;
        font-size: 14px;
    }

    .btn-send {
        margin-top: 28px;
        width: 100%;
        height: 60px;
        font-size: 18px;
    }
}

/* Toast */
@media (max-width: 768px) {
    .toast {
        top: 12px;
        left: 12px;
        right: 12px;
        transform: none;
        min-width: 0;
        padding: 12px 16px;
        font-size: 15px;
        border-radius: 12px;
    }

    .toast-check {
        width: 30px;
        height: 30px;
        font-size: 18px;
        flex-shrink: 0;
    }
}

/* Modal */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 16px;
    }

    .modal-card {
        padding: 24px 20px;
        border-radius: 20px;
    }

    .modal-title {
        font-size: 19px;
        margin-bottom: 18px;
    }

    .modal-input {
        height: 48px;
        font-size: 16px;
        padding: 0 18px;
    }

    .modal-ok {
        height: 44px;
        font-size: 17px;
        margin-top: 22px;
    }
}

/* Narrow phones */
@media (max-width: 480px) {
    .hero h1 {
        font-size: 24px;
    }

    .page-title {
        font-size: 22px;
    }

    .nav-item {
        font-size: 14px;
        height: 38px;
        padding: 0 12px;
    }

    .sms-bubble {
        border-width: 20px 24px;
        padding: 6px 8px;
    }

    .sms-bubble-text,
    .sms-bubble textarea,
    .sms-bubble textarea::placeholder {
        font-size: 15px;
    }

    .students-table {
        font-size: 12px;
    }

    .students-table th,
    .students-table td {
        padding: 7px 5px;
    }

    .students-table thead tr:nth-child(2) th {
        top: 32px;
    }

    .btn-send {
        height: 54px;
        font-size: 16px;
    }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    button,
    a,
    label,
    .penalty-value {
        -webkit-tap-highlight-color: rgba(29, 59, 189, 0.12);
    }

    body.is-admin .students-table .penalty-value {
        text-decoration: underline dotted;
        text-underline-offset: 2px;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ========================================================================
   Responsive layout patch
   Keep this block at the end of style.css so it overrides legacy rules.
   ======================================================================== */

:root {
    --page-gutter: clamp(12px, 2.2vw, 32px);
    --section-space: clamp(32px, 5vw, 72px);
}

html {
    width: 100%;
    max-width: 100%;
    scroll-padding-top: 16px;
}

body {
    width: 100%;
    min-width: 0;
    min-height: 100vh;
}

img, svg, video, canvas {
    max-width: 100%;
}

button, input, textarea, select {
    max-width: 100%;
}

.hero {
    padding: clamp(76px, 7vw, 104px) var(--page-gutter) clamp(36px, 5vw, 64px);
}

.hero h1 {
    font-size: clamp(26px, 4vw, 56px);
    overflow-wrap: anywhere;
}

.btn-admin {
    max-width: calc(100% - 24px);
    white-space: normal;
}

.page {
    width: 100%;
    max-width: 1760px;
    min-width: 0;
    grid-template-columns: minmax(130px, 170px) minmax(0, 1fr);
    gap: clamp(16px, 2vw, 24px);
    padding: clamp(28px, 5vw, 64px) var(--page-gutter) clamp(40px, 6vw, 80px);
}

.sidebar,
.content,
.section,
.cards,
.filters,
.templates-layout,
.templates,
.custom-col,
.template-row,
.custom-template-body {
    min-width: 0;
}

.content {
    width: 100%;
    max-width: 100%;
}

.nav-item {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 45px;
    overflow-wrap: anywhere;
}

.section {
    margin-bottom: var(--section-space);
}

.page-title {
    margin: clamp(28px, 5vw, 64px) 0 20px;
    font-size: clamp(24px, 3.2vw, 44px);
    overflow-wrap: anywhere;
}

.upload-title {
    margin-top: 0;
}

#view {
    padding-top: clamp(24px, 4vw, 56px);
}

.cards {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr));
    gap: clamp(14px, 2vw, 28px);
}

.upload-card {
    min-height: 0;
    height: auto;
    padding: clamp(20px, 2.5vw, 28px) clamp(14px, 2vw, 22px) 24px;
    gap: 12px;
}

.card-text {
    margin: 16px 0;
    font-size: clamp(18px, 1.7vw, 25px);
    overflow-wrap: anywhere;
}

.btn-upload {
    position: static;
    transform: none;
    width: min(100%, 220px);
    min-height: 52px;
    height: auto;
    margin: auto 0 0;
    padding: 14px 18px;
    font-size: clamp(15px, 1.4vw, 20px);
}

.card-status {
    position: static;
    width: 100%;
    min-width: 0;
    margin-top: 8px;
    padding: 8px 10px;
    font-size: clamp(14px, 1.4vw, 18px);
    overflow-wrap: anywhere;
}

.filters {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: clamp(14px, 2vw, 24px);
}

.filter-block {
    min-width: 0;
}

.filter-title {
    font-size: clamp(16px, 1.6vw, 20px);
    overflow-wrap: anywhere;
}

.filter-panel {
    height: auto;
    min-height: 220px;
    max-height: min(55vh, 520px);
}

.metric-row {
    flex-wrap: wrap;
    min-width: 0;
    font-size: clamp(15px, 1.5vw, 19px);
}

.metric-row input[type="number"] {
    width: clamp(70px, 7vw, 92px);
    min-width: 0;
}

.fio-search {
    display: block;
    width: min(100%, 420px);
    min-width: 0;
    font-size: 16px;
}

.list-header {
    min-width: 0;
    gap: 12px;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    max-height: min(75vh, 920px);
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.students-table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}

.students-table th,
.students-table td {
    overflow-wrap: anywhere;
}

.templates-layout {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: clamp(20px, 4vw, 64px);
    row-gap: 20px;
    margin-top: clamp(24px, 4vw, 50px);
}

.templates-heading,
.templates,
.custom-col {
    min-width: 0;
    max-width: 100%;
}

.templates {
    width: 100%;
}

.template-row {
    width: 100%;
    gap: 12px;
}

.template-row .sms-bubble,
.custom-template-body .sms-bubble,
.sms-bubble {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.sms-bubble {
    border-width: clamp(18px, 2vw, 32px) clamp(18px, 2.4vw, 36px);
    padding: clamp(6px, 1vw, 10px) clamp(8px, 1.2vw, 14px);
}

.sms-bubble-text,
.sms-bubble textarea {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: clamp(15px, 1.4vw, 20px);
}

.sms-bubble textarea {
    max-width: 100%;
    overflow-y: hidden;
}

.custom-template-body {
    width: 100%;
}

.insert-col {
    width: 100%;
    min-width: 0;
    padding-left: 0;
}

.btn-insert {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

.btn-save-template {
    max-width: 100%;
    white-space: normal;
}

.char-counter {
    margin-left: 0;
    overflow-wrap: anywhere;
}

.btn-send {
    max-width: 100%;
    min-height: 56px;
    height: auto;
    padding: 16px 28px;
    white-space: normal;
}

.modal-overlay {
    overflow-y: auto;
}

.modal-card {
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
}

.toast {
    width: max-content;
    max-width: calc(100vw - 24px);
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
    .page {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
    }

    .nav-item {
        width: auto;
        flex: 0 1 auto;
    }

    .templates-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .templates-heading,
    .templates,
    .custom-col {
        grid-column: 1;
        grid-row: auto;
    }
}

@media (max-width: 768px) {
    .hero {
        padding: 76px 12px 32px;
    }

    .hero h1 {
        font-size: clamp(24px, 6vw, 32px);
    }

    .btn-admin {
        top: 10px;
        right: 10px;
        padding: 7px 12px;
        font-size: 13px;
    }

    .page {
        padding: 24px 12px 44px;
        gap: 18px;
    }

    .sidebar {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 4px 0 8px;
        scrollbar-width: thin;
    }

    .nav-item {
        flex: 0 0 auto;
        white-space: nowrap;
        min-height: 40px;
        padding: 0 12px;
        font-size: 14px;
    }

    .page-title {
        margin: 28px 0 14px;
        font-size: clamp(22px, 5vw, 30px);
    }

    .upload-title,
    .templates-heading {
        margin-top: 0;
    }

    .cards {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    }

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

    .filter-panel {
        min-height: 0;
        max-height: 45vh;
    }

    .list-header {
        flex-direction: column;
        align-items: stretch;
    }

    .table-wrap {
        max-height: 65vh;
    }

    .students-table {
        min-width: 720px;
        font-size: 13px;
    }

    .students-table th,
    .students-table td {
        padding: 8px 6px;
        overflow-wrap: normal;
    }

    .custom-template-body {
        align-items: flex-start;
        gap: 10px;
    }

    .btn-send {
        width: 100%;
        margin-top: 28px;
    }
}

@media (max-width: 480px) {
    .hero {
        padding-top: 72px;
    }

    .page {
        padding-right: 10px;
        padding-left: 10px;
    }

    .upload-card {
        padding: 20px 14px;
    }

    .template-row {
        gap: 8px;
    }

    .sms-bubble {
        border-width: 18px 20px;
        padding: 6px 8px;
    }

    .sms-bubble-text,
    .sms-bubble textarea,
    .sms-bubble textarea::placeholder {
        font-size: 15px;
    }

    .modal-overlay {
        padding: 12px;
    }

    .modal-card {
        width: 100%;
        padding: 22px 16px;
    }

    .toast {
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        padding: 12px;
        font-size: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* Responsive template columns */
@media (max-width: 1100px) {
    .templates-layout {
        grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
        column-gap: clamp(14px, 2.5vw, 32px);
    }
}

.metric-row input[type="text"] {
    width: clamp(70px, 7vw, 92px);
    min-width: 0;
    height: 40px;
    padding: 4px 6px;
    border: 1px solid #c5b4c2;
    border-radius: 8px;
    background: #fff;
    text-align: center;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 768px) {
    .metric-row input[type="text"] {
        width: 76px;
        height: 36px;
        font-size: 16px;
    }
}


.templates-layout:not(:has(.template-row)) {
    grid-template-columns: minmax(0, 1fr);
}

.templates-layout:not(:has(.template-row)) .templates-heading,
.templates-layout:not(:has(.template-row)) .custom-col {
    grid-column: 1;
    grid-row: auto;
}

.templates-layout:not(:has(.template-row)) .templates {
    display: none;
}

.templates-layout:not(:has(.template-row)) .custom-col {
    width: min(100%, 600px);
    justify-self: center;
}

@media (max-width: 1100px) {
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 20;
        background: #c9daed;
        padding-top: 8px;
        padding-bottom: 8px;
        border-bottom: 1px solid rgba(29, 59, 189, 0.12);
    }

    .section,
    #view {
        scroll-margin-top: 76px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .section,
    #view {
        scroll-margin-top: 68px;
    }
}
.upload-card {
    height: 450px;
    min-height: 450px;
    max-height: 450px;
    overflow: hidden;
}

.upload-card .card-icon,
.upload-card .card-text,
.upload-card .btn-upload {
    flex-shrink: 0;
}

.upload-card .btn-upload {
    position: static;
    transform: none;
    height: 73px;
    min-height: 73px;
    max-height: 73px;
    margin: auto 0 0;
}

.upload-card .card-status {
    display: flex !important;
    flex: 0 0 53.8px;
    height: 53.8px;
    min-height: 53.8px;
    max-height: 53.8px;
    width: 100%;
    margin: 0;
    padding: 0 12px;
    box-sizing: border-box;
    overflow: hidden;
}

.upload-card .btn-upload {
    margin-top: 8px;
}

.upload-card .card-status {
    margin-top: auto;
}