/* ============================================================
   Dziennik korepetycji – arkusz stylów
   ============================================================ */
:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --border: #e5e7eb;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .75rem 1.5rem;
    background: #111827;
    color: #fff;
    flex-wrap: wrap;
}
.topbar .brand a { color: #fff; font-weight: 700; font-size: 1.05rem; }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a {
    color: #d1d5db;
    padding: .4rem .75rem;
    border-radius: 8px;
    font-size: .92rem;
}
.mainnav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.mainnav a.active { background: var(--primary); color: #fff; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .6rem; color: #e5e7eb; }
.badge {
    background: #374151;
    color: #e5e7eb;
    padding: .1rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Layout */
.container { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 2rem 0; }

h1 { margin: 0 0 1rem; font-size: 1.6rem; }
h2 { margin: 0 0 .75rem; font-size: 1.15rem; }
.muted { color: var(--muted); }

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.card.narrow { max-width: 420px; margin: 3rem auto; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* Forms */
.form label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
.form input, .form select, .form textarea {
    width: 100%;
    margin-top: .2rem;
    padding: .5rem .6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    background: #fff;
    color: var(--text);
}
.form input:focus, .form select:focus, .form textarea:focus {
    outline: 2px solid rgba(37, 99, 235, .35);
    border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 1rem; align-items: end; }
.form-row button { margin-bottom: .6rem; }

.inline-form { display: flex; gap: .4rem; align-items: center; }
.inline-form input, .inline-form select { margin: 0; }
.inline-form label { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: #e5e7eb;
    color: #111827;
    border: none;
    border-radius: 8px;
    padding: .5rem .9rem;
    font-size: .9rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { filter: brightness(.96); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .55rem; font-size: .8rem; }

/* Alerts */
.alert {
    padding: .7rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: .92rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .6rem .55rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table tr:hover td { background: #f9fafb; }
.actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    text-align: center;
}
.stat-value { display: block; font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: .85rem; }

.quick-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.5rem; }

/* Grades & chips */
.grade {
    display: inline-block;
    min-width: 2.2rem;
    text-align: center;
    padding: .1rem .4rem;
    border-radius: 6px;
    font-weight: 700;
    background: #e0e7ff;
    color: #3730a3;
}
.grade-5, .grade-6 { background: #dcfce7; color: #166534; }
.grade-1, .grade-2 { background: #fee2e2; color: #991b1b; }
.avg-box { margin-bottom: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.chip { background: #eef2ff; color: #3730a3; border-radius: 999px; padding: .2rem .7rem; font-size: .85rem; }

/* Status */
.status { padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.status-planned { background: #e0f2fe; color: #075985; }
.status-completed { background: #dcfce7; color: #166534; }
.status-cancelled { background: #fee2e2; color: #991b1b; }

/* Messages */
.messages { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
.msg { padding: .7rem .9rem; border-radius: 8px; border: 1px solid var(--border); }
.msg.incoming { background: #f0f9ff; border-color: #bae6fd; }
.msg.outgoing { background: #f9fafb; }
.msg-head { display: flex; justify-content: space-between; margin-bottom: .3rem; font-size: .85rem; }
.msg p { margin: 0; }

code { background: #f3f4f6; padding: .1rem .35rem; border-radius: 4px; font-size: .85rem; }


/* Badge ról */
.badge-admin   { background: #7c2d12; color: #fed7aa; }
.badge-teacher { background: #1e3a8a; color: #dbeafe; }
.badge-parent  { background: #166534; color: #dcfce7; }
.badge-student { background: #374151; color: #e5e7eb; }

/* Frekwencja */
.att { padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.att-present { background: #dcfce7; color: #166534; }
.att-absent  { background: #fee2e2; color: #991b1b; }
.att-late    { background: #fef3c7; color: #92400e; }
.att-excused { background: #dbeafe; color: #1e40af; }
.details-box { background: #f9fafb; border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem; }
.details-box summary { cursor: pointer; font-size: .92rem; }

/* Karta edycji */
.edit-card { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .08), var(--shadow); }

/* Lista przypisanych dzieci (edycja rodzica) */
.children-box {
    grid-column: 1 / -1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .6rem .9rem;
    margin-bottom: .6rem;
}
.children-box legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.check-label {
    display: flex !important;
    align-items: center;
    gap: .45rem;
    font-size: .9rem;
    color: var(--text) !important;
    margin: .25rem 0 !important;
    cursor: pointer;
}
.check-label input[type="checkbox"] { width: auto; margin: 0; }

/* Wyróżnienie wpisów zgłoszonych przez rodzica */
.status-parent-report::after { content: " (rodzic)"; font-size: .7rem; opacity: .8; }


/* Formularz dodawania oceny — czytelny układ siatki */
.grid-grade-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: .2rem 1rem;
    align-items: start;
}
.grid-grade-form label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .02em;
    margin-bottom: .7rem;
}
.grid-grade-form .span-2 { grid-column: span 2; }
.grid-grade-form .form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    margin-top: .2rem;
}
/* Pole z jednostką (waga "x") */
.input-unit {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-top: .2rem;
}
.input-unit input { margin-top: 0 !important; }
.input-unit .unit {
    color: var(--muted);
    font-size: .85rem;
    font-weight: 400;
    white-space: nowrap;
}
@media (max-width: 600px) {
    .grid-grade-form .span-2 { grid-column: 1 / -1; }
}

/* Edycja oceny inline w wierszu tabeli */
.row-edit {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    flex-wrap: wrap;
}
.row-edit-form {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    flex-wrap: wrap;
    margin: 0;
}
.re-field {
    display: flex;
    flex-direction: column;
    gap: .15rem;
}
.re-caption {
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 600;
}
.row-edit select,
.row-edit input {
    margin: 0 !important;
    padding: .32rem .45rem !important;
    font-size: .85rem !important;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    height: 2rem;
}
.row-edit select:focus,
.row-edit input:focus {
    outline: 2px solid rgba(37, 99, 235, .35);
    border-color: var(--primary);
}
.re-grade select   { width: 4.5rem; font-weight: 600; text-align: center; }
.re-weight input   { width: 3.8rem; text-align: center; }
.re-comment input  { width: 11rem; }
.row-edit .btn-sm  { height: 2rem; display: inline-flex; align-items: center; }
.row-edit form + form { margin-left: 0; }
@media (max-width: 720px) {
    .re-comment input { width: 100%; }
    .row-edit, .row-edit-form { width: 100%; }
}

/* Filtr ucznia na liście ocen */
.filter-form {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}
.filter-form .filter-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--muted);
    margin: 0;
}
.filter-form select {
    margin: 0;
    padding: .4rem .5rem;
    font-size: .9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    min-width: 12rem;
}
.filter-form select:focus {
    outline: 2px solid rgba(37, 99, 235, .35);
    border-color: var(--primary);
}

/* Panel edycji płatności (rozwijany) */
.row-details { display: inline-block; }
.row-details summary { cursor: pointer; list-style: none; }
.row-details summary::-webkit-details-marker { display: none; }
.row-edit-panel {
    position: absolute;
    right: 1rem;
    z-index: 20;
    margin-top: .4rem;
    padding: 1rem;
    min-width: 340px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
    grid-template-columns: repeat(2, minmax(140px, 1fr)) !important;
    text-align: left;
}
.row-edit-panel .span-2 { grid-column: 1 / -1; }
.row-edit-panel .form-actions { grid-column: 1 / -1; }

/* Wiadomości – zakładki skrzynki */
.mail-tabs {
    display: flex;
    gap: .4rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.mail-tab {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem .9rem;
    border-radius: 8px 8px 0 0;
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: .9rem;
    border: 1px solid transparent;
    border-bottom: none;
    margin-bottom: -1px;
}
.mail-tab:hover { color: var(--text); background: #f3f4f6; }
.mail-tab.active {
    color: var(--primary);
    background: #fff;
    border-color: var(--border);
    border-bottom-color: #fff;
}
.tab-count {
    background: #e5e7eb;
    color: var(--muted);
    border-radius: 999px;
    padding: .05rem .45rem;
    font-size: .75rem;
    font-weight: 700;
}
.mail-tab.active .tab-count { background: #dbeafe; color: var(--primary-dark); }
.tab-unread {
    background: var(--danger);
    color: #fff;
    border-radius: 999px;
    padding: .05rem .45rem;
    font-size: .72rem;
    font-weight: 700;
}

/* Nieprzeczytana wiadomość */
.msg.unread {
    background: #eff6ff;
    border-color: #93c5fd;
    border-left: 4px solid var(--primary);
}
.msg-new {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 999px;
    padding: .05rem .4rem;
    margin-left: .35rem;
    vertical-align: middle;
}

/* Badge liczby nieprzeczytanych w nawigacji */
.nav-badge {
    display: inline-block;
    min-width: 1.1rem;
    background: var(--danger);
    color: #fff;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    line-height: 1;
    padding: .18rem .35rem;
    margin-left: .25rem;
    text-align: center;
}
.mainnav a { position: relative; }

/* Czat wiadomości – układ dwukolumnowy */
.chat-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1rem;
    align-items: start;
}
@media (max-width: 800px) {
    .chat-layout { grid-template-columns: 1fr; }
}

/* Lista rozmów */
.chat-list { padding: .8rem; }
.chat-list-head { padding-bottom: .5rem; border-bottom: 1px solid var(--border); margin-bottom: .5rem; }
.chat-new { margin-bottom: .6rem; }
.chat-new summary { display: inline-block; }
.chat-new-form { margin-top: .6rem; }
.chat-threads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .2rem; }
.chat-empty { padding: .6rem 0; }
.chat-thread {
    display: block;
    padding: .55rem .6rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid transparent;
}
.chat-thread:hover { background: #f3f4f6; }
.chat-thread.active { background: #eff6ff; border-color: #bfdbfe; }
.chat-thread.has-unread { font-weight: 600; }
.ct-top { display: flex; align-items: center; justify-content: space-between; gap: .4rem; }
.ct-name { font-size: .92rem; }
.ct-preview { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .1rem; font-weight: 400; }
.ct-time { font-size: .72rem; color: var(--muted); margin-top: .15rem; }

/* Okno wątku */
.chat-window { display: flex; flex-direction: column; min-height: 480px; padding: 0; }
.chat-placeholder { padding: 2rem; text-align: center; }
.chat-window-head {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: .8rem 1rem; border-bottom: 1px solid var(--border);
}
.chat-scroll {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-height: 520px;
    overflow-y: auto;
    background: #fafbfc;
}
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble-row.theirs { justify-content: flex-start; }
.bubble {
    max-width: 78%;
    padding: .5rem .75rem;
    border-radius: 12px;
    font-size: .92rem;
    line-height: 1.35;
}
.bubble-row.theirs .bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble-row.mine .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble-time { font-size: .68rem; margin-top: .25rem; opacity: .75; }
.bubble-row.mine .bubble-time { text-align: right; }

/* Pole odpowiedzi */
.chat-reply {
    display: flex;
    gap: .5rem;
    align-items: flex-end;
    padding: .75rem 1rem;
    border-top: 1px solid var(--border);
}
.chat-reply textarea { flex: 1; resize: vertical; }
