@font-face {
    font-family: 'Kurdish';
    src: url('../kurdish.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --primary: #218A9D;
    --primary-dark: #1a6f7f;
    --secondary: #8F7217;
    --bg: #e8f4f8;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: rgba(33, 138, 157, 0.16);
    --danger: #dc2626;
    --ok: #059669;
    --shadow: 0 10px 32px rgba(33, 138, 157, 0.12);
}

* {
    font-family: 'Kurdish', Tahoma, sans-serif;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body.app-body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2.5rem;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--card);
    border-radius: 1.1rem;
    padding: 1rem 1.2rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.topbar h1 {
    margin: 0;
    font-size: 1.35rem;
    color: var(--primary);
}

.topbar p {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.58rem 1rem;
    border-radius: 0.7rem;
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    color: inherit;
    background: #f3f4f6;
}

.btn:hover {
    transform: translateY(-1px);
}

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

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

.btn-gold {
    background: var(--secondary);
    color: #fff;
}

.btn-outline {
    background: rgba(33, 138, 157, 0.1);
    color: var(--primary);
}

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

.btn-ghost {
    background: transparent;
    color: var(--muted);
}

.btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
}

.flash {
    border-radius: 0.9rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.flash-success {
    background: #ecfdf5;
    color: #047857;
}

.flash-error {
    background: #fef2f2;
    color: #b91c1c;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.subject-card {
    background: var(--card);
    border-radius: 1.25rem;
    padding: 1.25rem;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    min-height: 210px;
    box-shadow: var(--shadow);
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.subject-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 6px;
    background: var(--card-color, var(--primary));
}

.subject-card.add-card {
    border: 2px dashed #cbd5e1;
    min-height: 190px;
    box-shadow: none;
}

.subject-card:hover {
    transform: translateY(-6px);
    border-color: var(--card-color, var(--primary));
    box-shadow: 0 16px 36px rgba(33, 138, 157, 0.18);
}

.card-icon {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--card-color, var(--primary));
    margin-bottom: 0.9rem;
    font-size: 1.25rem;
}

.subject-card h2 {
    margin: 0 0 0.4rem;
    font-size: 1.12rem;
    line-height: 1.7;
    color: #111827;
}

.subject-card .desc {
    color: var(--muted);
    font-size: 0.86rem;
    margin: 0 0 auto;
    line-height: 1.7;
}

.card-meta {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.chip {
    background: rgba(33, 138, 157, 0.08);
    color: var(--primary);
    border-radius: 999px;
    padding: 0.22rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 700;
}

.chip-muted {
    background: #f3f4f6;
    color: #4b5563;
}

.card {
    background: var(--card);
    border-radius: 1.2rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-pad {
    padding: 1.2rem;
}

.search-bar {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.search-bar input {
    flex: 1;
    min-width: 200px;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid rgba(33, 138, 157, 0.2);
    border-radius: 0.75rem;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-size: 1rem;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(33, 138, 157, 0.15);
}

.label {
    display: block;
    font-weight: 700;
    color: #374151;
    margin-bottom: 0.4rem;
}

.caption {
    display: block;
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 0.15rem;
}

.table-wrap {
    overflow-x: auto;
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

table.data th {
    background: var(--primary);
    color: #fff;
    padding: 0.75rem 0.55rem;
    text-align: center;
    font-weight: 700;
}

table.data td {
    padding: 0.7rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid #eef2f7;
    vertical-align: middle;
    word-break: break-word;
}

table.data tbody tr:hover td {
    background: rgba(33, 138, 157, 0.05);
}

.field-row {
    display: grid;
    grid-template-columns: minmax(180px, 1.4fr) 150px 110px minmax(140px, 1fr) auto;
    gap: 0.6rem;
    align-items: end;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 0.9rem;
    padding: 0.8rem;
    margin-bottom: 0.7rem;
}

.field-row > div:first-child {
    grid-column: 1 / -1;
}

.icon-grid, .color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.icon-pick, .color-pick {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 2px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: #f3f4f6;
    color: var(--primary);
}

.icon-pick input, .color-pick input {
    display: none;
}

.icon-pick.active, .color-pick.active {
    border-color: var(--primary);
    background: rgba(33, 138, 157, 0.12);
}

.color-pick span {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: block;
}

.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #9ca3af;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
}

.modal-backdrop.open {
    display: flex;
}

.modal {
    width: min(640px, 100%);
    background: #fff;
    border-radius: 1.2rem;
    max-height: 92vh;
    overflow: auto;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--line);
}

.modal-head h3 {
    margin: 0;
    color: var(--primary);
}

.modal-body {
    padding: 1.2rem;
}

.leave-modal {
    width: min(460px, 100%);
    text-align: center;
}

.leave-modal .modal-head {
    justify-content: center;
    border-bottom: 0;
    padding-bottom: 0;
}

.leave-modal .modal-head h3 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    color: #c2410c;
}

.leave-modal .modal-body p {
    margin: 0 0 1.1rem;
    color: var(--text);
    line-height: 1.85;
}

.leave-actions {
    justify-content: center;
}

.stack > * + * {
    margin-top: 0.9rem;
}

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

.report-header {
    text-align: center;
    padding: 1.5rem 1.2rem 1rem;
    border-bottom: 3px solid var(--primary);
}

.report-header img {
    width: 78px;
    border-radius: 12px;
}

.report-header h2 {
    margin: 0.4rem 0 0.2rem;
    color: var(--primary);
}

.muted {
    color: var(--muted);
}

.tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.tab {
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    text-decoration: none;
    color: var(--muted);
    background: #fff;
    font-weight: 700;
}

.tab.active {
    background: var(--primary);
    color: #fff;
}

.danger-zone {
    border: 1px solid #fecaca;
    background: #fef2f2;
    border-radius: 1rem;
    padding: 1rem;
    margin-top: 1.5rem;
}

@media (max-width: 800px) {
    .field-row {
        grid-template-columns: 1fr 1fr;
    }
}

@media print {
    .no-print { display: none !important; }
    body.app-body { background: #fff; }
    .page { padding: 0; max-width: none; }
    .card { box-shadow: none; }
    table.sheet th {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

.print-only {
    display: none !important;
}

body.sheet-page .page {
    max-width: 1280px;
    padding-bottom: 3rem;
}

.sheet-workspace {
    background: var(--card);
    border-radius: 1.2rem;
    box-shadow: var(--shadow);
    overflow: visible;
}

.sheet-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: #fff;
    border-bottom: 1px solid var(--line);
    border-radius: 1.2rem 1.2rem 0 0;
}

.sheet-search {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
    min-width: 220px;
}

.sheet-search .form-input {
    padding: 0.55rem 0.85rem;
}

.sheet-toolbar-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
}

.sheet-count {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
    padding: 0 0.4rem;
}

.sheet-dirty-pill {
    background: #fff7ed;
    color: #c2410c;
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 800;
}

.sheet-table-wrap {
    overflow: visible;
    width: 100%;
}

table.sheet {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.95rem;
    background: #fff;
}

table.sheet th {
    background: var(--primary);
    color: #fff;
    padding: 0.85rem 0.65rem;
    text-align: center;
    font-weight: 700;
    border-left: 1px solid rgba(255, 255, 255, 0.14);
}

table.sheet th .req {
    color: #fecaca;
}

table.sheet th.sheet-index,
table.sheet td.sheet-index {
    width: 52px;
}

table.sheet th.sheet-actions-h,
table.sheet td.sheet-actions {
    width: 92px;
}

table.sheet td {
    padding: 0;
    border-bottom: 1px solid #edf2f4;
    border-left: 1px solid #f1f5f7;
    background: #fff;
    vertical-align: middle;
    text-align: center;
    overflow-wrap: anywhere;
}

table.sheet td.sheet-index {
    background: #f7fafb;
    color: #64748b;
    font-weight: 800;
    text-align: center;
    user-select: none;
}

table.sheet tbody tr:hover td {
    background: #f4fbfc;
}

table.sheet tbody tr.is-blank td {
    background: #fcfefe;
}

table.sheet tbody tr.is-dirty td.sheet-index {
    box-shadow: inset -3px 0 0 #f59e0b;
    color: #b45309;
}

table.sheet tbody tr.is-error td {
    background: #fff7f7 !important;
}

table.sheet tbody tr.is-error td.sheet-index {
    background: #fee2e2 !important;
    color: var(--danger);
}

table.sheet td.is-active {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    position: relative;
    z-index: 1;
}

.sheet-input {
    width: 100%;
    min-height: 46px;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0.55rem 0.75rem;
    font-size: 0.98rem;
    box-shadow: none;
    text-align: center;
}

.sheet-input:focus {
    outline: none;
    background: #fff;
}

.sheet-input::placeholder {
    color: #c5d0d4;
    text-align: center;
}

select.sheet-input {
    text-align: center;
    text-align-last: center;
}

.sheet-add-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.sheet-add-count {
    width: 64px;
    height: 40px;
    border: 2px solid rgba(33, 138, 157, 0.2);
    border-radius: 0.7rem;
    text-align: center;
    font-weight: 800;
    color: var(--primary);
    background: #fff;
}

.sheet-add-count:focus {
    outline: none;
    border-color: var(--primary);
}

.sheet-actions {
    text-align: center;
    background: #fafbfc !important;
}

.sheet-icon-btn {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #cbd5e1;
    cursor: pointer;
}

.sheet-icon-btn:hover {
    background: rgba(33, 138, 157, 0.1);
    color: var(--primary);
}

.sheet-icon-save {
    color: var(--ok);
}

.sheet-icon-save:hover {
    background: #ecfdf5;
    color: var(--ok);
}

.sheet-icon-danger:hover {
    background: #fef2f2;
    color: var(--danger);
}

.sheet-footer {
    display: flex;
    align-items: stretch;
    border-top: 1px dashed rgba(33, 138, 157, 0.28);
}

.sheet-add-row {
    display: flex;
    flex: 1;
    width: auto;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.9rem;
    border: 0;
    background: #f7fbfc;
    color: var(--primary);
    font-weight: 800;
    cursor: pointer;
}

.sheet-add-row:hover {
    background: rgba(33, 138, 157, 0.08);
}

.sheet-footer-save {
    flex: 0 0 auto;
    border-radius: 0;
    padding: 0.9rem 1.4rem;
}

.sheet-status {
    padding: 0.7rem 1.1rem 1rem;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.sheet-status .is-ok { color: var(--ok); }
.sheet-status .is-err { color: var(--danger); }

#sheetForm.is-saving {
    opacity: 0.78;
    pointer-events: none;
}

#sheetForm.is-dirty #sheetSaveBtn {
    box-shadow: 0 8px 20px rgba(33, 138, 157, 0.28);
}

@media (max-width: 800px) {
    table.sheet {
        table-layout: auto;
    }
}

@media print {
    .print-only { display: block !important; }
    .sheet-toolbar,
    .sheet-status,
    .sheet-actions,
    .sheet-actions-h,
    .sheet-add-row,
    .sheet-footer {
        display: none !important;
    }
    .sheet-workspace {
        box-shadow: none;
        border-radius: 0;
    }
    table.sheet {
        table-layout: auto;
        border-collapse: collapse;
    }
    table.sheet tr.is-blank {
        display: none !important;
    }
    .sheet-input {
        min-height: 0;
        padding: 0.4rem 0.3rem;
    }
    .sheet-input::placeholder {
        color: transparent;
    }
    table.sheet select.sheet-input {
        appearance: none;
        background: transparent;
    }
}
