:root {
    --bg: #edf3f7;
    --bg-strong: #dfeaf1;
    --card: rgba(255, 255, 255, 0.92);
    --line: #cbdbe6;
    --text: #183247;
    --muted: #60798c;
    --accent: #2679bd;
    --accent-strong: #165f9f;
    --accent-soft: #d7ebfb;
    --danger: #c95757;
    --success: #67b782;
    --shadow: 0 16px 40px rgba(40, 73, 98, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    margin: 0;
    font-family: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(38, 121, 189, 0.12), transparent 28%),
        radial-gradient(circle at top right, rgba(103, 183, 130, 0.12), transparent 24%),
        linear-gradient(180deg, #f8fbfd 0%, var(--bg) 52%, var(--bg-strong) 100%);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 18px 30px;
    background: rgba(248, 252, 254, 0.82);
    border-bottom: 1px solid rgba(203, 219, 230, 0.85);
    position: sticky;
    top: 0;
    backdrop-filter: blur(16px);
    box-shadow: 0 8px 24px rgba(47, 80, 106, 0.06);
    z-index: 10;
}

.brand-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.brand {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: 0.02em;
}
.brand-subtitle {
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}
.nav { display: flex; gap: 10px; flex-wrap: wrap; }
.nav a, .button {
    text-decoration: none;
    border: none;
    cursor: pointer;
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: white;
    padding: 11px 17px;
    border-radius: 14px;
    font-weight: 600;
    box-shadow: 0 10px 18px rgba(38, 121, 189, 0.18);
    transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
.nav a:hover, .button:hover { transform: translateY(-1px); }
.nav a {
    background: rgba(215, 235, 251, 0.76);
    color: var(--text);
    box-shadow: none;
}
.nav a.active {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: white;
    box-shadow: 0 10px 18px rgba(38, 121, 189, 0.18);
}
.button.light {
    background: rgba(215, 235, 251, 0.88);
    color: var(--text);
    box-shadow: none;
}
.button.danger {
    background: linear-gradient(180deg, #d96d6d 0%, var(--danger) 100%);
    box-shadow: 0 10px 18px rgba(201, 87, 87, 0.18);
}
.button:disabled,
.nav a[aria-disabled="true"] {
    opacity: 0.72;
    cursor: wait;
    transform: none !important;
    box-shadow: none;
}

.page {
    padding: 26px;
    max-width: 1600px;
    margin: 0 auto;
}
.panel {
    background: var(--card);
    border: 1px solid rgba(203, 219, 230, 0.9);
    border-radius: 24px;
    padding: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}
.panel.narrow { max-width: 760px; margin: 0 auto; }
.page-hero {
    background:
        radial-gradient(circle at top right, rgba(38, 121, 189, 0.12), transparent 28%),
        linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(244,249,253,0.96) 100%);
}
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.panel-head h1,
.panel-head h2,
.panel-head h3 {
    margin: 0;
}

.page-subtitle {
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
    margin-top: 6px;
}

.center-text {
    text-align: center;
}

.hero-stats {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.hero-stat {
    min-width: 170px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(226, 242, 255, 0.72);
    border: 1px solid rgba(183, 217, 246, 0.9);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hero-stat strong {
    font-size: 24px;
    color: var(--accent);
}

.hero-stat span {
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1.1fr;
    gap: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 16px;
}
.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 600;
}
.form-grid .full { grid-column: 1 / -1; }
.check { flex-direction: row !important; align-items: center; }
.inner-panel {
    margin-top: 4px;
    background: rgba(248, 252, 255, 0.88);
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 11px 12px;
    font: inherit;
    color: var(--text);
    background: rgba(251, 253, 255, 0.95);
    transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(38, 121, 189, 0.7);
    box-shadow: 0 0 0 4px rgba(38, 121, 189, 0.12);
    background: white;
}

.table-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.list-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border: 1px solid rgba(203, 219, 230, 0.85);
    border-radius: 16px;
    text-decoration: none;
    color: inherit;
    background: rgba(251, 253, 255, 0.9);
    transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.list-row:hover {
    transform: translateY(-1px);
    border-color: rgba(38, 121, 189, 0.45);
    box-shadow: 0 12px 22px rgba(38, 121, 189, 0.08);
}
.align-top { align-items: flex-start; }
.lesson-student-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}
.student-transfer-box {
    width: min(360px, 100%);
}
.student-transfer-box summary {
    list-style: none;
}
.student-transfer-box summary::-webkit-details-marker {
    display: none;
}

.muted { color: var(--muted); font-size: 14px; }
.empty-state {
    padding: 16px;
    border: 1px dashed var(--line);
    border-radius: 16px;
    color: var(--muted);
    text-align: center;
    background: rgba(255, 255, 255, 0.5);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

.status-badge-active {
    background: #e6f7ea;
    color: #237247;
}

.status-badge-muted {
    background: #eef3f6;
    color: #698093;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(150px, 1fr));
    gap: 16px;
}
.day-card {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.92) 0%, rgba(245,250,253,0.92) 100%);
    border: 1px solid rgba(203, 219, 230, 0.95);
    border-radius: 22px;
    padding: 14px;
    min-height: 260px;
    box-shadow: 0 12px 28px rgba(58, 94, 122, 0.08);
}
.day-title {
    font-weight: 800;
    font-size: 17px;
}
.day-date {
    color: var(--muted);
    margin: 6px 0 12px;
    font-size: 14px;
}
.day-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 10px;
}
.day-actions.inline-actions {
    flex-direction: row;
    flex-wrap: wrap;
}
.lesson-stack { display: flex; flex-direction: column; gap: 10px; }
.lesson-chip {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    color: inherit;
    border-radius: 16px;
    padding: 12px 13px;
    border: 1px solid rgba(203, 219, 230, 0.8);
    background: rgba(255, 255, 255, 0.96);
    width: 100%;
    text-align: left;
    cursor: pointer;
    font: inherit;
    box-shadow: 0 8px 18px rgba(58, 94, 122, 0.08);
    transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}
.lesson-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 22px rgba(58, 94, 122, 0.12);
}
.lesson-chip strong {
    color: var(--accent);
    font-size: 16px;
}
.lesson-chip span:last-child {
    color: var(--text);
}
.lesson-chip .actions {
    margin-top: 6px;
}
.lesson-chip .actions form {
    margin: 0;
}
.chip-note {
    color: var(--muted);
    font-size: 13px;
}
.status-planned {
    background: linear-gradient(180deg, #fff6e7 0%, #fff1d8 100%);
}
.status-confirmed {
    background: linear-gradient(180deg, #ebf9f0 0%, #daf2e1 100%);
}
.status-reschedule_requested {
    background: linear-gradient(180deg, #fff0f0 0%, #ffdede 100%);
}
.status-late_reschedule_requested {
    background: linear-gradient(180deg, #ffe9dd 0%, #ffd2c0 100%);
}
.status-rescheduled {
    background: linear-gradient(180deg, #f0f1f5 0%, #e2e6ed 100%);
    opacity: 0.88;
}
.status-completed {
    background: linear-gradient(180deg, #edf8ef 0%, #d7f0dc 100%);
}
.status-cancelled { opacity: 0.65; }
.status-cancelled_by_student { opacity: 0.65; }
.status-cancelled_by_teacher { opacity: 0.65; }
.slot-chip {
    background: linear-gradient(180deg, #eaf7ff 0%, #d8efff 100%);
    border-style: dashed;
    border-color: rgba(38, 121, 189, 0.5);
}
.slot-chip strong {
    color: #0f6b92;
}

.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.flash {
    padding: 12px 16px;
    border-radius: 14px;
    background: linear-gradient(180deg, #eff8ff 0%, #e0f1ff 100%);
    border: 1px solid #b7d9f6;
    box-shadow: 0 10px 18px rgba(38, 121, 189, 0.08);
}
.message-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(16, 36, 52, 0.42);
    backdrop-filter: blur(6px);
    z-index: 1200;
}
.message-modal {
    width: min(520px, 100%);
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(203, 219, 230, 0.95);
    border-radius: 26px;
    box-shadow: 0 24px 60px rgba(25, 54, 76, 0.2);
    padding: 22px;
}
.message-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.message-head h2 {
    margin: 0;
    font-size: 30px;
}
.message-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.message-item {
    padding: 14px 16px;
    border-radius: 16px;
    background: linear-gradient(180deg, #eff8ff 0%, #e0f1ff 100%);
    border: 1px solid #b7d9f6;
    box-shadow: 0 10px 18px rgba(38, 121, 189, 0.08);
}
.message-modal .modal-actions {
    margin-top: 14px;
}
.finance-layout {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 20px;
}
.finance-column {
    min-height: 520px;
}
.finance-summary-form {
    display: flex;
    align-items: end;
    gap: 14px;
    flex-wrap: wrap;
}
.finance-summary-badges {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.finance-summary-meta {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    color: var(--muted);
    font-weight: 600;
    flex-wrap: wrap;
}
.finance-badge {
    padding: 12px 16px;
    border-radius: 16px;
    font-weight: 700;
}
.finance-badge-positive {
    background: #e6f7ea;
    color: #237247;
}
.finance-badge-negative {
    background: #fdebec;
    color: #ae3f46;
}
.finance-info-link {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 700;
    padding: 0;
    box-shadow: none;
}
.finance-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border-radius: 22px;
    background: rgba(224, 241, 255, 0.55);
}
.finance-payment-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 12px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(203, 219, 230, 0.9);
    width: 100%;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
    box-shadow: 0 10px 20px rgba(58, 94, 122, 0.08);
    transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}
.finance-payment-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 24px rgba(58, 94, 122, 0.12);
    border-color: rgba(38, 121, 189, 0.4);
}
.finance-payment-date,
.finance-payment-side {
    color: var(--accent);
    font-weight: 700;
}
.finance-payment-main {
    font-weight: 700;
}
.finance-payment-comment {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 14px;
}

.stats-month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.stats-month-title {
    font-size: 30px;
    font-weight: 800;
    text-align: center;
    flex: 1 1 240px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}

.stat-card {
    min-height: 170px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: linear-gradient(180deg, rgba(232, 245, 255, 0.95) 0%, rgba(244, 250, 255, 0.96) 100%);
}

.stat-value {
    font-size: 34px;
    line-height: 1.1;
    font-weight: 800;
    color: var(--text);
}

.stat-diff {
    font-size: 15px;
    font-weight: 700;
}

.stat-diff-green {
    color: #23834f;
}

.stat-diff-red {
    color: #b04a4a;
}

.stat-diff-neutral {
    color: var(--muted);
}

.stat-title {
    font-size: 16px;
    color: var(--muted);
    font-weight: 700;
}
.finance-balances-head {
    align-items: start;
}
.finance-balance-tools {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.finance-balance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.finance-balance-card {
    border: 1px solid rgba(203, 219, 230, 0.9);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    padding: 16px;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(58, 94, 122, 0.08);
}
.finance-balance-name {
    display: block;
    font-weight: 700;
    margin-bottom: 10px;
}
.finance-balance-value {
    font-size: 28px;
    font-weight: 800;
}
.is-positive {
    color: #319258;
}
.is-zero {
    color: #cf8a15;
}
.is-negative {
    color: #c34f56;
}
.modal-wide {
    width: min(920px, 100%);
}
.modal-actions-between {
    justify-content: space-between;
    flex-wrap: wrap;
}
.finance-student-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.finance-student-balance {
    font-size: 42px;
    font-weight: 800;
}
.finance-student-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.finance-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.finance-history-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(203, 219, 230, 0.9);
}

.info-box, .note { color: var(--muted); line-height: 1.5; }
.soft-box {
    background: linear-gradient(180deg, rgba(245,250,254,0.95) 0%, rgba(235,245,251,0.9) 100%);
}
.soft-box h3 {
    margin-top: 0;
    margin-bottom: 12px;
}
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.top-section {
    margin-top: 20px;
}
.link-box {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #f6fbff;
    border: 1px dashed var(--line);
    word-break: break-all;
}

.separator {
    border: none;
    border-top: 1px solid var(--line);
    margin: 20px 0;
}

.time-row, .actions, .week-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.top-gap {
    margin-top: 14px;
}
.time-row input { width: 78px; }
.actions.wrap { flex-wrap: wrap; margin-top: 14px; }
.lesson-manage-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    align-items: stretch;
}
.lesson-manage-actions form {
    margin: 0;
}
.lesson-manage-actions .button {
    width: 100%;
    height: 100%;
    justify-content: center;
    text-align: center;
}
.week-range {
    font-weight: 800;
    padding: 10px 16px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(203, 219, 230, 0.7);
}
.student-list-grid {
    gap: 12px;
}
.student-row {
    align-items: center;
}
.student-row.is-selected {
    border-color: rgba(38, 121, 189, 0.55);
    box-shadow: 0 16px 24px rgba(38, 121, 189, 0.12);
}
.student-row-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}
.student-card-head-tools {
    align-items: center;
}
.student-active-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}
.student-active-toggle {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px;
    font-weight: 700;
}
.student-active-toggle input {
    width: auto;
    margin: 0;
    flex: 0 0 auto;
}
.reminder-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.reminder-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid rgba(203, 219, 230, 0.85);
    border-radius: 14px;
    background: rgba(251, 253, 255, 0.92);
    font-weight: 700;
}
.reminder-option input {
    width: auto;
    margin: 0;
    flex: 0 0 auto;
}
.mini-link {
    display: inline-block;
    margin-bottom: 10px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.mini-button {
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
}
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 34, 46, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 30;
}
.modal-backdrop[hidden] {
    display: none !important;
}
.modal-panel {
    width: min(760px, 100%);
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(203, 219, 230, 0.95);
    border-radius: 26px;
    padding: 22px;
    box-shadow: 0 24px 60px rgba(25, 46, 64, 0.24);
    backdrop-filter: blur(14px);
}
.icon-close {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: rgba(215, 235, 251, 0.88);
    color: var(--text);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    transition: transform 140ms ease, background 140ms ease;
}
.icon-close:hover {
    transform: rotate(90deg);
    background: rgba(196, 225, 247, 0.95);
}

@media (max-width: 1100px) {
    .two-col { grid-template-columns: 1fr; }
    .calendar-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
    .finance-layout { grid-template-columns: 1fr; }
    .finance-student-columns { grid-template-columns: 1fr; }
    .student-row-meta { align-items: flex-start; }
}

@media (max-width: 720px) {
    .topbar, .panel-head, .week-nav { flex-direction: column; align-items: stretch; }
    .page { padding: 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .calendar-grid { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .finance-summary-form, .finance-balance-tools { flex-direction: column; align-items: stretch; }
    .finance-balance-grid { grid-template-columns: 1fr; }
    .finance-student-head { flex-direction: column; align-items: flex-start; }
    .stats-month-nav { flex-direction: column; align-items: stretch; }
    .modal-actions-between { flex-direction: column; }
    .lesson-manage-actions { grid-template-columns: 1fr; }
}
