/* style.css */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

:root {
    --navy: #1E2D4A;
    --amber: #F5A623;
    --amber-soft: #FEF3DC;
    --slate: #6B7A8D;
    --slate-light: #EEF1F5;
    --white: #FFFFFF;
    --green: #27AE60;
    --border: #D8DDE4;
    --text: #1A1A2E;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

html {
    height: 100%;
    background: var(--navy);
}

body {
    font-family: -apple-system, 'Helvetica Neue', sans-serif;
    background: #F0F3F8;
    color: var(--text);
    min-height: 100%;
    overscroll-behavior: none;
}

/* HEADER */
header {
    background: var(--navy);
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: 16px;
    padding-left: calc(20px + var(--safe-left));
    padding-right: calc(20px + var(--safe-right));
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-icon {
    width: 38px;
    height: 38px;
    background: var(--amber);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

header h1 {
    color: #fff;
    font-size: 17px;
    font-weight: 600;
}

header span {
    color: rgba(255, 255, 255, 0.45);
    font-size: 12px;
    display: block;
    margin-top: 1px;
}

.resources-btn {
    margin-left: auto;
    width: 44px;
    height: 44px;
    border-radius: 11px;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 19px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-appearance: none;
}

.resources-btn:active {
    background: rgba(255, 255, 255, 0.22);
}

/* CLASS TABS */
.class-bar {
    background: var(--navy);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 calc(12px + var(--safe-left)) 0 calc(12px + var(--safe-left));
}

.class-bar::-webkit-scrollbar {
    display: none;
}

.region-filter-bar {
    background: var(--navy);
    display: flex;
    gap: 8px;
    padding: 10px calc(14px + var(--safe-left)) 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.region-filter-bar::-webkit-scrollbar {
    display: none;
}

.region-filter-btn {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.6);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-appearance: none;
    font-family: inherit;
}

.region-filter-btn.active {
    background: var(--amber);
    border-color: var(--amber);
    color: var(--navy);
}

.class-tab {
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 7px;
}

.class-tab.active {
    color: var(--amber);
    border-bottom-color: var(--amber);
    font-weight: 600;
}

.class-tab .tab-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.7;
}

.add-class-btn {
    margin-left: 6px;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 2px dashed rgba(255, 255, 255, 0.25);
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* LAYOUT */
.app {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    max-width: 700px;
    margin: 16px auto;
    padding: 0 calc(14px + var(--safe-left)) calc(30px + var(--safe-bottom));
}

@media (min-width: 640px) {
    .app {
        grid-template-columns: 1fr 1fr;
    }
}

/* PANELS */
.panel {
    background: var(--white);
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.panel-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--slate);
    margin-bottom: 14px;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.panel-header .panel-title {
    margin-bottom: 0;
}

/* CLASS INFO */
.class-info-bar {
    grid-column: 1 / -1;
    background: var(--navy);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.info-chips {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.info-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13.5px;
}

.edit-class-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    -webkit-appearance: none;
}

/* STUDENTS */
.students-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.student-card {
    border: 2px solid var(--border);
    border-radius: 13px;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--white);
    user-select: none;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.student-card:active {
    background: var(--amber-soft);
    border-color: var(--amber);
}

.student-card.selected {
    border-color: var(--amber);
    background: var(--amber-soft);
}

.student-card.has-status {
    border-radius: 13px 13px 0 0;
    border-bottom: none;
    margin-bottom: 0;
}

.student-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--slate-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: var(--navy);
    flex-shrink: 0;
}

.student-card.selected .student-avatar {
    background: var(--amber);
    color: #fff;
}

.student-info {
    flex: 1;
    min-width: 0;
}

.student-name {
    font-weight: 600;
    font-size: 15px;
}

.student-phone {
    font-size: 12px;
    color: var(--slate);
    margin-top: 2px;
}

.check-mark {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: transparent;
    flex-shrink: 0;
}

.student-card.selected .check-mark {
    background: var(--amber);
    border-color: var(--amber);
    color: #fff;
}

.selected-count {
    font-size: 11px;
    font-weight: 700;
    color: var(--amber);
    background: var(--amber-soft);
    padding: 3px 9px;
    border-radius: 20px;
    margin-left: auto;
}

/* STUDENT STATUS */
.student-status {
    border: 2px solid var(--amber);
    border-top: none;
    border-radius: 0 0 13px 13px;
    margin-top: -10px;
    padding: 12px 14px 14px;
    background: var(--amber-soft);
}

.student-status .status-row {
    margin-bottom: 0;
}

.student-status .extra-field.visible {
    margin-top: 10px;
}

.student-status .field-label {
    margin-bottom: 6px;
}

.student-status input[type="number"],
.student-status input[type="text"] {
    margin-bottom: 0;
}

.status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 12px;
}

.status-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: var(--white);
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--slate);
    font-family: inherit;
    -webkit-appearance: none;
    white-space: nowrap;
}

.status-btn:active {
    opacity: 0.75;
}

.status-btn .btn-icon {
    font-size: 14px;
    line-height: 1;
}

.status-btn[data-s="absent"].active {
    border-color: #E74C3C;
    background: #FDECEB;
    color: #C0392B;
}

.status-btn[data-s="late"].active {
    border-color: var(--amber);
    background: var(--amber-soft);
    color: #B97309;
}

.status-btn[data-s="left_early"].active {
    border-color: #229ED9;
    background: #EFF9FF;
    color: #1A7FB0;
}

.status-btn[data-s="late_left_early"].active {
    border-color: var(--navy);
    background: #E9EDF3;
    color: var(--navy);
}

.extra-field {
    display: none;
    margin-top: 4px;
}

.extra-field.visible {
    display: block;
}

label.field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate);
    display: block;
    margin-bottom: 6px;
    letter-spacing: 0.3px;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    font-size: 16px;
    padding: 11px 13px;
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    background: var(--white);
    outline: none;
    font-family: inherit;
    margin-bottom: 10px;
    -webkit-appearance: none;
    appearance: none;
}

input:focus {
    border-color: var(--amber);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 13px 0;
}

/* PREVIEW */
.preview-panel {
    grid-column: 1 / -1;
}

.msg-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 8px;
    display: block;
}

.msg-label.wa {
    color: #25D366;
}

.msg-label.tg {
    color: #229ED9;
}

.message-preview {
    background: var(--slate-light);
    border-radius: 12px;
    padding: 14px;
    font-size: 14px;
    line-height: 1.75;
    color: var(--text);
    white-space: pre-wrap;
    font-family: inherit;
    border: 2px dashed var(--border);
    min-height: 76px;
}

.message-preview.has-content {
    background: var(--white);
    border-style: solid;
}

.placeholder-text {
    color: var(--slate);
    font-style: italic;
    font-size: 13px;
}

.telegram-preview {
    background: #EFF9FF;
    border: 2px solid #B3DFF5;
    border-radius: 12px;
    padding: 14px;
    font-size: 14px;
    line-height: 1.75;
    white-space: pre-wrap;
    font-family: inherit;
}

/* WA BUTTONS */
.wa-buttons-section {
    margin-top: 12px;
}

.contact-row {
    display: flex;
    gap: 8px;
    margin-bottom: 9px;
}

.wa-student-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding: 13px 16px;
    border-radius: 13px;
    background: #25D366;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    font-family: inherit;
    -webkit-appearance: none;
}

.wa-student-btn:active {
    opacity: 0.82;
}

.wa-student-btn .btn-name {
    flex: 1;
    min-width: 0;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wa-student-btn .btn-arrow {
    opacity: 0.8;
    font-size: 15px;
    flex-shrink: 0;
}

.call-student-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: auto;
    border-radius: 13px;
    background: var(--navy);
    color: #fff;
    border: none;
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
    -webkit-appearance: none;
}

.call-student-btn:active {
    opacity: 0.82;
}

.tg-copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 13px;
    background: #229ED9;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    margin-top: 11px;
    -webkit-appearance: none;
}

.tg-copy-btn:active {
    opacity: 0.82;
}

.tg-copy-btn:disabled {
    opacity: 0.38;
}

.tg-copy-btn.copied {
    background: var(--green);
}

.region-tg-row {
    display: flex;
    gap: 8px;
    margin-top: 9px;
}

.region-tg-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 10px;
    border-radius: 11px;
    border: 2px solid #B3DFF5;
    background: #EFF9FF;
    color: #1A7FB0;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    -webkit-appearance: none;
}

.region-tg-btn:active {
    background: #D9F0FB;
}

.region-tg-btn[data-missing="true"] {
    opacity: 0.5;
    border-style: dashed;
}

/* MODAL */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
    overscroll-behavior: contain;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--white);
    border-radius: 22px 22px 0 0;
    padding: 24px 20px calc(20px + var(--safe-bottom));
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.18);
    transform: translateY(40px);
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-backdrop.open .modal {
    transform: translateY(0);
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 20px;
}

.modal h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 18px;
    color: var(--navy);
}

.modal-field {
    margin-bottom: 14px;
}

.modal-field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate);
    display: block;
    margin-bottom: 5px;
    letter-spacing: 0.3px;
}

.modal-field input {
    width: 100%;
    font-size: 16px;
    padding: 11px 13px;
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.modal-field input:focus {
    border-color: var(--amber);
}

.student-builder {
    margin: 6px 0 12px;
}

.student-row {
    display: grid;
    grid-template-columns: 1fr 1fr 44px;
    gap: 7px;
    align-items: center;
    margin-bottom: 8px;
}

.student-row input {
    margin-bottom: 0;
}

.remove-student-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--white);
    cursor: pointer;
    font-size: 20px;
    color: var(--slate);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    flex-shrink: 0;
}

.remove-student-btn:active {
    border-color: #E74C3C;
    color: #E74C3C;
}

.add-student-row {
    width: 100%;
    padding: 12px;
    border: 2px dashed var(--border);
    border-radius: 11px;
    background: transparent;
    color: var(--slate);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    -webkit-appearance: none;
    margin-bottom: 4px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.modal-btn {
    flex: 1;
    padding: 14px;
    border-radius: 13px;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    -webkit-appearance: none;
}

.modal-btn.primary {
    background: var(--navy);
    color: #fff;
}

.modal-btn.primary:active {
    opacity: 0.82;
}

.modal-btn.cancel {
    background: var(--slate-light);
    color: var(--slate);
}

.modal-btn.cancel:active {
    opacity: 0.75;
}

.delete-class-btn {
    width: 100%;
    padding: 13px;
    border-radius: 11px;
    border: 2px solid #FDDBD9;
    background: #FFF5F5;
    color: #E74C3C;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    margin-top: 10px;
    -webkit-appearance: none;
}

.delete-class-btn:active {
    background: #FDDBD9;
}

/* LESSON TRACKER */
.lessons-panel {
    grid-column: 1 / -1;
}

.lessons-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: start;
}

.lessons-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lesson-row {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    border: 2px solid var(--border);
    border-radius: 11px;
    padding: 9px 10px;
    transition: border-color 0.15s, background 0.15s;
}

.lesson-row.done {
    border-color: var(--green);
    background: #F1FBF5;
}

.lesson-checkbox {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    border: 2px solid var(--border);
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    cursor: pointer;
    font-size: 13px;
    color: transparent;
    -webkit-appearance: none;
}

.lesson-row.done .lesson-checkbox {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.lesson-body {
    flex: 1;
    min-width: 0;
}

.lesson-num {
    font-size: 12px;
    font-weight: 700;
    color: var(--navy);
    margin-bottom: 4px;
}

.lesson-row.done .lesson-num {
    color: var(--green);
}

.lesson-note-input {
    width: 100%;
    font-size: 13px;
    padding: 6px 9px;
    border: 2px solid var(--border);
    border-radius: 7px;
    font-family: inherit;
    color: var(--text);
    outline: none;
    -webkit-appearance: none;
}

.lesson-note-input:focus {
    border-color: var(--amber);
}

.lessons-progress {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate);
    background: var(--slate-light);
    padding: 3px 10px;
    border-radius: 20px;
    margin-left: auto;
}

/* RESOURCES SHEET */
.resource-link-card {
    display: flex;
    align-items: center;
    gap: 13px;
    border: 2px solid var(--border);
    border-radius: 13px;
    padding: 14px;
    text-decoration: none;
    color: var(--text);
    margin-bottom: 10px;
    -webkit-appearance: none;
}

.resource-link-card:active {
    background: var(--slate-light);
}

.resource-icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--amber-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.resource-info {
    flex: 1;
    min-width: 0;
}

.resource-title {
    font-weight: 600;
    font-size: 14.5px;
    margin-bottom: 2px;
}

.resource-sub {
    font-size: 12px;
    color: var(--slate);
}

.resource-arrow {
    color: var(--slate);
    font-size: 16px;
    flex-shrink: 0;
}

.resource-extra-row {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.resource-extra-card {
    flex: 1;
    min-width: 120px;
    border: 2px solid var(--border);
    border-radius: 13px;
    padding: 14px 12px;
    text-align: center;
    background: var(--white);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.resource-extra-card:active {
    background: var(--slate-light);
}

.resource-extra-card .big-icon {
    font-size: 28px;
    display: block;
    margin-bottom: 4px;
}

.resource-extra-card .label {
    font-weight: 600;
    font-size: 13px;
    color: var(--navy);
}

.resource-extra-card .sub {
    font-size: 11px;
    color: var(--slate);
    margin-top: 2px;
}

.resource-extra-card .custom-image {
    width: 100%;
    max-height: 100px;
    object-fit: contain;
    border-radius: 8px;
    margin-top: 8px;
}

.resource-extra-card .image-upload-btn {
    display: inline-block;
    margin-top: 6px;
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 20px;
    background: var(--navy);
    color: #fff;
    border: none;
    cursor: pointer;
}