:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e2e4e9;
    --text: #1f2430;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success-bg: #ecfdf5;
    --success-text: #065f46;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --sidebar-bg: #171b26;
    --sidebar-text: #cbd2e0;
    --sidebar-active: #2563eb;
    --radius: 8px;
    --sidebar-width: 220px;
}

* {
    box-sizing: border-box;
}

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

h1 {
    font-size: 1.4rem;
    margin: 0 0 1rem;
}

h2 {
    font-size: 1.05rem;
    margin: 0 0 0.75rem;
}

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

a:hover {
    text-decoration: underline;
}

.muted {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* App shell: sidebar + main */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.75rem;
}

.sidebar-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
    padding: 0 0.5rem 1.25rem;
}

.nav-toggle {
    display: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-nav a {
    color: var(--sidebar-text);
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.92rem;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-nav a.active {
    background: var(--sidebar-active);
    color: #fff;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.username {
    font-weight: 600;
}

.logout-form {
    margin: 0;
}

.content {
    padding: 1.5rem;
    flex: 1;
}

.content-plain {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

/* Cards, tables, forms */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 340px;
}

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}

.table th {
    background: #fafbfc;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table td.row-actions {
    text-align: right;
    white-space: nowrap;
}

.row-actions .btn + .btn {
    margin-left: 0.4rem;
}

.lbl-short {
    display: none;
}

.row-edit-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.row-edit-actions {
    display: flex;
    gap: 0.4rem;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.form-grid-top {
    align-items: start;
}

.form-grid .col-2 {
    grid-column: span 2;
}

.form-grid .col-3 {
    grid-column: span 3;
}

.form-grid .col-6 {
    grid-column: span 6;
}

.form-grid .col-12 {
    grid-column: 1 / -1;
}

.form-grid .btn {
    width: 100%;
}

.form-grid-top .btn {
    width: auto;
}

.form-actions {
    text-align: right;
}

.settings-updated {
    margin: 0.9rem 0 0;
}

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

    .form-grid .col-2,
    .form-grid .col-3,
    .form-grid .col-6,
    .form-grid .col-12 {
        grid-column: auto;
    }

    .form-actions {
        text-align: left;
    }
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.combo {
    position: relative;
}

.combo-input {
    width: 100%;
}

.combo [hidden] {
    display: none !important;
}

.combo-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    margin: 0.25rem 0 0;
    padding: 0.25rem;
    list-style: none;
    max-height: 16rem;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.combo-list li {
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
}

.combo-list li.active,
.combo-list li:hover {
    background: var(--bg);
}

.combo-list li[aria-selected="true"] {
    font-weight: 600;
    color: var(--primary);
}

.combo-list li.combo-empty {
    color: var(--text-muted);
    cursor: default;
}

.numbered tr {
    counter-increment: row-number;
}

.numbered td.row-no::before {
    content: counter(row-number);
}

.table th.col-no,
.table td.row-no {
    width: 3.5rem;
    text-align: right;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.col-amount {
    text-align: right !important;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.col-count {
    text-align: center !important;
}

.show-mobile {
    display: none;
}

.sort-link {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.sort-link:hover {
    color: var(--primary);
    text-decoration: none;
}

.sort-link.active {
    color: var(--primary);
}

.sort-arrow {
    font-size: 0.75em;
    opacity: 0.6;
}

.sort-link.active .sort-arrow {
    opacity: 1;
}

.toolbar {
    margin-bottom: 1rem;
}

.toolbar input[type="search"] {
    width: 100%;
    max-width: 360px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-top: 0.85rem;
}

.pagination-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.text-error {
    color: var(--error-text);
    font-size: 0.8rem;
}

.form-inline {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
}

.form-inline label {
    flex: 1 1 180px;
}

.form-inline input,
.form-inline select {
    width: 100%;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

label[hidden] {
    display: none;
}

input,
select {
    font: inherit;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

input:focus,
select:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    background: var(--bg);
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.btn-small {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}

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

input:disabled {
    background: var(--bg);
    cursor: not-allowed;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem 0.5rem;
}

.btn-link:hover {
    color: var(--danger);
    text-decoration: underline;
}

.role-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.role-admin {
    background: #ede9fe;
    color: #5b21b6;
}

.role-user {
    background: #e0f2fe;
    color: #075985;
}

.alert {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
}

/* Günlük rapor */
.report-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
}

.report-date-form {
    margin: 0;
}

.report-print {
    margin-left: auto;
}

.report {
    --tone-cash: #dcdcdc;
    --tone-bank-1: #dce7c8;
    --tone-bank-2: #bdb6f2;
    --tone-bank-3: #a4cbdc;
    --tone-bank-4: #f6d8c1;
    --tone-bank-5: #d6a1a1;
    --tone-kesilen: #f7c9f7;
    --tone-eft: #fdfda0;
}

.report th,
.report td {
    white-space: nowrap;
    border-right: 1px solid var(--border);
}

.report th:last-child,
.report td:last-child {
    border-right: none;
}

.report-date {
    text-transform: none;
    font-size: 0.95rem;
    color: var(--text);
}

.report-sub th {
    font-size: 0.7rem;
}

.report-upper {
    text-transform: uppercase;
}

.report-student {
    font-weight: 600;
}

.report-count {
    text-align: center !important;
}

.report-amount {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.report-single {
    color: var(--danger);
    font-weight: 700;
}

/* Günün SATILAN toplamı: öğrenci sütununda kırmızı, kalın etiket. */
.report-satilan-label {
    color: var(--danger);
    font-weight: 700;
}

.report-total th {
    background: #d9d9d9;
    color: var(--text);
    border-top: 1px solid var(--text);
    border-bottom: 1px solid var(--text);
    text-transform: none;
    font-size: 0.9rem;
    letter-spacing: 0;
}

.report-total th.report-upper {
    text-transform: uppercase;
}

.report .report-total th[class*="tone-"] {
    font-weight: 700;
}

.report-total-period th {
    border-top: 3px solid var(--text);
    border-bottom: 3px solid var(--text);
}

.report-day th {
    background: #fafbfc;
    color: var(--text);
    text-transform: none;
    font-size: 0.95rem;
    border-top: 3px solid var(--text);
}

.report-day a {
    color: inherit;
}

.report .tone-cash { background: var(--tone-cash); }
.report .tone-bank-1 { background: var(--tone-bank-1); }
.report .tone-bank-2 { background: var(--tone-bank-2); }
.report .tone-bank-3 { background: var(--tone-bank-3); }
.report .tone-bank-4 { background: var(--tone-bank-4); }
.report .tone-bank-5 { background: var(--tone-bank-5); }
.report .tone-kesilen { background: var(--tone-kesilen); }
.report .tone-eft { background: var(--tone-eft); }

.report-col-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 0.25em;
}

.report-col-link:hover {
    text-decoration-style: solid;
}

@media print {
    .report-col-link {
        text-decoration: none;
    }
}

.report-grand {
    margin: 0.85rem 0 0;
    text-align: right;
}

@media print {
    @page {
        size: landscape;
        margin: 10mm;
    }

    .sidebar,
    .topbar,
    .no-print {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .content {
        padding: 0;
    }

    .table-wrap {
        overflow: visible;
        border: none;
    }

    .report th,
    .report td {
        font-size: 0.75rem;
        padding: 0.25rem 0.4rem;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Gelir listesi: satır menüsü ve satır altı detay/düzenleme alanı */
.table th.col-menu,
.table td.col-menu {
    width: 7rem;
    padding-right: 0;
}

.row-menu summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.row-menu summary::-webkit-details-marker {
    display: none;
}

.row-menu-list {
    position: fixed;
    top: -9999px;
    left: -9999px;
    z-index: 50;
    min-width: 9rem;
    padding: 0.25rem;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.row-menu-list button {
    text-align: left;
    background: none;
    border: none;
    padding: 0.5rem 0.75rem;
    font: inherit;
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
}

.row-menu-list button:hover {
    background: var(--bg);
}

.row-menu-list button.danger {
    color: var(--danger);
}

.numbered tr.income-extra {
    counter-increment: none;
}

.income-extra > td {
    padding: 1rem;
    background: #fafbfc;
}

/* Açık düzenleme formundaki öğrenci listesi tablonun kaydırma alanında kırpılmasın. */
.table-wrap:has(.income-extra:not([hidden])) {
    overflow: visible;
}

.income-extra-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.income-extra-head .btn {
    margin-left: auto;
}

.income-detail-table {
    max-width: 30rem;
    background: var(--surface);
    border: 1px solid var(--border);
}

.income-detail-table tfoot th {
    background: #f0f2f5;
    color: var(--text);
    text-transform: none;
}

.form-actions .btn + .btn {
    margin-left: 0.4rem;
}

/* İşlem günlüğü */
.audit-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.audit-filters label {
    min-width: 10rem;
}

.audit-time {
    white-space: nowrap;
    color: var(--text-muted);
}

.audit-action {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--bg);
}

.audit-create { background: var(--success-bg); color: var(--success-text); }
.audit-update { background: #fef9c3; color: #854d0e; }
.audit-delete { background: var(--error-bg); color: var(--error-text); }

.audit-details {
    margin-top: 0.3rem;
    font-size: 0.85rem;
}

.audit-details summary {
    cursor: pointer;
    color: var(--primary);
}

.audit-details ul {
    margin: 0.3rem 0 0;
    padding-left: 1.1rem;
}

/* Responsive: collapse sidebar to a top bar on narrow screens */
@media (max-width: 720px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 0.6rem 1rem;
    }

    .sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .sidebar-brand {
        padding: 0;
    }

    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.4rem;
        line-height: 1;
        color: #fff;
        background: none;
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: var(--radius);
        cursor: pointer;
    }

    .sidebar-nav {
        display: none;
        padding-top: 0.6rem;
    }

    .sidebar.open .sidebar-nav {
        display: flex;
    }

    .sidebar-nav a {
        padding: 0.7rem 0.75rem;
    }

    .topbar {
        padding: 0.6rem 1rem;
    }

    .content,
    .content-plain {
        padding: 1rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    .card {
        padding: 1rem;
    }

    .hide-mobile {
        display: none;
    }

    .show-mobile {
        display: block;
        font-size: 0.8rem;
    }

    .table {
        table-layout: fixed;
    }

    .table th,
    .table td {
        padding: 0.5rem 0.45rem;
        font-size: 0.92rem;
        overflow-wrap: anywhere;
    }

    .table th.col-no,
    .table td.row-no {
        width: 2.9rem;
        white-space: nowrap;
        overflow-wrap: normal;
    }

    .table th.col-actions {
        width: 6.5rem;
    }

    .row-actions .btn {
        padding: 0.5rem;
    }

    .row-actions .btn + .btn {
        margin-left: 0.3rem;
    }

    .lbl-full {
        display: none;
    }

    .lbl-short {
        display: inline;
    }

    input,
    select {
        font-size: 16px;
    }

    .row-edit-fields label {
        flex: 1 1 100%;
    }

    .row-edit-fields input,
    .row-edit-fields select {
        width: 100%;
    }

    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .form-inline label {
        flex: 0 0 auto;
    }

    .table.report {
        table-layout: auto;
    }

    .report-toolbar .btn,
    .report-toolbar input {
        flex: 1 1 auto;
    }

    .report-print {
        margin-left: 0;
    }

    .audit-filters label {
        flex: 1 1 100%;
    }

    .audit-time {
        white-space: normal;
    }

    .table th.col-menu,
    .table td.col-menu {
        width: 3.4rem;
    }

    .row-menu summary {
        padding: 0.35rem 0.6rem;
    }
}
