:root {
    --bg: #eef3f8;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --line: #e5ebf2;
    --text: #172033;
    --muted: #6b7280;
    --blue: #2f9be6;
    --blue-dark: #1479c9;
    --green: #12a579;
    --red: #d44b4b;
    --amber: #f5ad32;
    --shadow: 0 18px 45px rgba(32, 49, 74, 0.08);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, Arial, "Segoe UI", Tahoma, Helvetica, sans-serif;
}

html[dir="rtl"] body {
    font-family: "Segoe UI", Tahoma, Arial, Helvetica, sans-serif;
}

html[dir="rtl"] .app-shell {
    direction: rtl;
}

html[dir="rtl"] .sidebar {
    border-left: 1px solid var(--line);
    border-right: 0;
}

html[dir="rtl"] input,
html[dir="rtl"] select,
html[dir="rtl"] textarea {
    text-align: right;
}

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

.app-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.public-shell {
    display: block;
}

.public-shell .topbar {
    justify-content: center;
}

.public-shell .topbar-title {
    justify-content: center;
    width: 100%;
}

.public-shell .topbar nav {
    display: none;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    align-items: center;
    display: flex;
    font-size: 20px;
    font-weight: 800;
    gap: 12px;
    margin-bottom: 34px;
}

.brand-mark {
    align-items: center;
    background: linear-gradient(135deg, var(--blue), #56c0ff);
    border-radius: 10px;
    color: white;
    display: inline-flex;
    font-size: 13px;
    height: 38px;
    justify-content: center;
    width: 38px;
}

.side-nav {
    display: grid;
    gap: 8px;
}

.side-nav a {
    border-radius: 12px;
    color: #334155;
    display: block;
    font-weight: 700;
    padding: 12px 14px;
}

.side-nav a:hover,
.side-nav a.active {
    background: var(--blue);
    color: white;
}

.sidebar-footer {
    border-top: 1px solid var(--line);
    margin-top: auto;
    padding-top: 18px;
}

.user-chip {
    background: var(--surface-soft);
    border-radius: 12px;
    color: #334155;
    font-weight: 700;
    margin-bottom: 10px;
    padding: 10px 12px;
}

.sidebar-footer .footer-link {
    color: #334155;
    display: block;
    font-weight: 700;
    padding: 0 12px;
}

.content-shell {
    min-width: 0;
}

.topbar {
    align-items: center;
    background: rgba(238, 243, 248, 0.88);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: space-between;
    min-height: 74px;
    padding: 18px 28px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar-title {
    align-items: center;
    display: flex;
    gap: 12px;
}

.header-logo {
    display: block;
    max-height: 42px;
    max-width: 150px;
    object-fit: contain;
}

.topbar strong {
    display: block;
    font-size: 18px;
}

.topbar span {
    color: #334155;
    font-size: 13px;
    font-weight: 800;
}

.topbar nav {
    display: flex;
    gap: 8px;
}

.topbar nav a {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: #334155;
    font-weight: 700;
    padding: 9px 12px;
}

main {
    margin: 0 auto;
    max-width: 1500px;
    padding: 8px 28px 36px;
}

.page-head {
    margin: 10px 0 22px;
}

.page-head h1 {
    font-size: 26px;
    margin: 0 0 6px;
}

.page-head p,
.panel p {
    color: var(--muted);
}

h1, h2 {
    letter-spacing: 0;
}

h2 {
    font-size: 18px;
    margin: 0 0 16px;
}

.login-panel,
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    padding: 20px;
}

.login-panel {
    max-width: 400px;
    margin: 12vh auto;
}

.login-title {
    color: var(--text);
    font-size: 1.8em;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 10px;
}

.login-panel h1 {
    font-size: 1.8em;
}

.login-panel input,
.login-panel select,
.login-panel button {
    width: 100%;
}

.grid.two {
    display: grid;
    gap: 20px;
    grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
}

.narrow {
    max-width: 1200px;
}

label {
    color: #475569;
    display: block;
    font-size: 13px;
    font-weight: 800;
    margin: 8px 0 5px;
}

input, select, button {
    border: 1px solid #d8e1eb;
    border-radius: 8px;
    font-size: 13px;
    min-height: 34px;
    padding: 6px 10px;
}

input, select {
    background: #fbfdff;
    color: var(--text);
}

input[readonly] {
    background: #f3f6fa;
    color: #64748b;
}

button {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
    cursor: pointer;
    font-weight: 800;
}

button:hover {
    background: var(--blue-dark);
}

table {
    background: white;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    width: 100%;
}

th, td {
    border-bottom: 1px solid var(--line);
    padding: 6px 10px;
    text-align: left;
    vertical-align: middle;
}

th {
    background: var(--surface-soft);
    color: #475569;
    font-size: 12px;
    font-weight: 900;
    position: sticky;
    top: 0;
    z-index: 1;
}

td {
    font-weight: 400;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 14px 0;
}

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

.dashboard-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--text);
    display: block;
    min-height: 92px;
    padding: 18px;
}

.dashboard-card strong {
    color: var(--text);
    display: block;
    font-size: 17px;
    margin-bottom: 7px;
}

.dashboard-card span {
    color: var(--muted);
    display: block;
    line-height: 1.35;
}

.editable-card-list {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}

.edit-card {
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
}

.compact-card {
    padding: 10px;
}

.edit-card-header {
    align-items: flex-start;
    display: flex;
    gap: 8px;
    justify-content: space-between;
    margin-bottom: 6px;
}

.edit-card-header strong {
    display: block;
    font-size: 15px;
    margin-bottom: 3px;
}

.edit-card-header span {
    color: var(--muted);
    display: block;
    font-size: 12px;
    line-height: 1.35;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.card-actions button {
    min-height: 30px;
    padding: 5px 9px;
}

.card-form-grid {
    display: grid;
    gap: 5px 6px;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.project-card-grid {
    align-items: end;
    grid-template-columns: minmax(190px, 1.6fr) 72px 72px 76px 92px 90px 92px 72px 70px minmax(110px, 1fr);
    overflow-x: auto;
}

.employee-card-grid {
    grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.leave-card-grid,
.salary-card-grid {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.holiday-card-grid {
    grid-template-columns: minmax(150px, 0.5fr) minmax(220px, 1fr);
}

.card-form-grid label {
    color: #475569;
    font-size: 11px;
    line-height: 1.15;
    margin: 0;
    min-width: 0;
}

.card-form-grid input,
.card-form-grid select {
    display: block;
    margin-top: 3px;
    min-height: 30px;
    padding: 4px 8px;
    width: 100%;
}

.project-card-grid .small-code-field,
.project-card-grid .tiny-code-field {
    min-width: 0;
}

#projectsCards {
    gap: 0;
    margin-top: 0;
}

#projectsCards .edit-card {
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 2px 4px;
}

#projectsCards .card-actions {
    gap: 3px;
}

#projectsCards .card-actions button {
    min-height: 26px;
    padding: 3px 8px;
}

#projectsCards .project-card-grid {
    gap: 2px 4px;
}

#projectsCards .card-form-grid label {
    font-size: 10px;
}

#projectsCards .card-form-grid input,
#projectsCards .card-form-grid select {
    min-height: 26px;
    padding: 2px 6px;
}

.project-table-shell {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow-x: auto;
}

.table-top-scroll {
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    height: 16px;
    margin-bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.table-top-scroll div {
    height: 1px;
}

.table-top-scroll + .project-table-shell {
    border-radius: 0 0 8px 8px;
}

.project-row-grid {
    align-items: center;
    display: grid;
    gap: 3px;
    grid-template-columns: 160px minmax(180px, 1.5fr) 62px 58px 70px 88px 88px 92px 62px 58px minmax(190px, 1.3fr) 34px;
    min-width: 1260px;
}

.projects-header-row {
    background: var(--surface-soft);
    border-bottom: 1px solid var(--line);
    color: #475569;
    font-size: 11px;
    font-weight: 900;
    padding: 5px 4px;
    position: sticky;
    top: 0;
    z-index: 2;
}

#projectsCards .generated-code {
    color: var(--text);
    font-size: 11px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#projectsCards input {
    min-height: 24px;
    padding: 2px 5px;
    width: 100%;
}

#projectsCards .pending-save {
    background: #fffaf0;
}

#projectsCards .save-error {
    background: #fff1f1;
}

.project-delete-button {
    align-items: center;
    background: #fff;
    border-color: #f1b5b5;
    color: var(--red);
    display: inline-flex;
    font-size: 12px;
    justify-content: center;
    min-height: 24px;
    padding: 0;
    width: 26px;
}

.project-delete-button:hover {
    background: #ffecec;
}

#addProjectPanel {
    margin-bottom: 10px;
    padding-bottom: 12px;
}

#addProjectPanel .project-form {
    gap: 4px 6px;
    grid-template-columns: minmax(180px, 1.5fr) 72px 72px 76px 92px 90px 92px 72px 70px minmax(190px, 1.3fr);
}

#addProjectPanel input {
    min-height: 28px;
    padding: 3px 8px;
}

.empty-state {
    background: var(--surface-soft);
    border: 1px dashed #d8e1eb;
    border-radius: 8px;
    color: var(--muted);
    padding: 14px;
}

.attendance-controls,
.form-grid,
.punch-row,
.project-form {
    display: grid;
    gap: 10px;
    margin: 8px 0;
}

.attendance-controls {
    align-items: end;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.section-title-row {
    align-items: start;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.month-controls {
    align-items: end;
    display: grid;
    gap: 8px;
    grid-template-columns: 150px 120px;
    min-width: 280px;
}

.month-controls label {
    grid-column: 1 / -1;
    margin: 0;
}

.monthly-kpis {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    margin: 12px 0;
}

.monthly-kpis span {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    padding: 10px 12px;
}

.monthly-kpis b {
    color: var(--text);
    display: block;
    font-size: 18px;
    margin-bottom: 3px;
}

.monthly-table-wrap {
    margin-top: 10px;
}

.daily-month-details {
    margin-top: 12px;
}

.daily-month-details summary {
    color: var(--blue-dark);
    cursor: pointer;
    font-weight: 800;
}

.allocation-warning-row td {
    background: #fff7ed;
}

.form-grid {
    grid-template-columns: 130px minmax(180px, 1fr);
}

.punch-row {
    grid-template-columns: 140px 120px 100px;
}

.project-form {
    grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.titled-form label {
    margin: 0;
}

.titled-form input,
.titled-form select {
    display: block;
    margin-top: 4px;
    width: 100%;
}

.allocation-row {
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(360px, 1fr) 120px 90px;
    margin: 8px 0;
}

.weekly-table-wrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: auto;
}

.top-scroll-wrap {
    transform: rotateX(180deg);
}

.top-scroll-wrap > table,
.top-scroll-wrap > div {
    transform: rotateX(180deg);
}

.weekly-table-wrap.no-x-scroll {
    overflow-x: hidden;
}

.holiday-panel {
    align-self: start;
}

.holiday-panel #holidayCards {
    max-height: 330px;
    overflow-y: auto;
    padding-right: 4px;
}

.vacation-records-panel {
    width: 100%;
}

.record-view-controls {
    align-items: end;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    margin: 8px 0 12px;
}

.record-view-controls label {
    margin: 0;
}

.leave-summary-card details {
    margin-top: 8px;
}

.leave-summary-card summary {
    color: var(--blue-dark);
    cursor: pointer;
    font-weight: 800;
}

.remaining-credit {
    background: #ecfdf5;
    border: 1px solid #b8ead5;
    border-radius: 8px;
    color: #0f7a58;
    min-width: 44px;
    padding: 6px 8px;
    text-align: center;
}

.leave-metric-grid {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(6, minmax(88px, 1fr));
}

.leave-metric-grid span {
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #64748b;
    font-size: 12px;
    padding: 6px 8px;
}

.leave-metric-grid b {
    color: var(--text);
    display: block;
    font-size: 14px;
}

.leave-detail-list {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}

.leave-grouped-table th,
.leave-grouped-table td {
    font-size: 12px;
    padding: 5px 6px;
}

.leave-grouped-table td:last-child {
    white-space: normal;
}

.leave-calendar {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(7, minmax(110px, 1fr));
}

.leave-calendar > b {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #475569;
    font-size: 12px;
    padding: 7px;
    text-align: center;
}

.leave-calendar-cell {
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 82px;
    padding: 6px;
}

.leave-calendar-cell.muted {
    background: #f7f9fc;
}

.leave-calendar-cell strong,
.leave-calendar-cell span {
    display: block;
}

.leave-calendar-cell span {
    background: #eef7ff;
    border-radius: 6px;
    font-size: 11px;
    margin-top: 4px;
    padding: 3px 5px;
}

.company-table-stack {
    display: grid;
    gap: 16px;
}

.company-salary-table h3 {
    font-size: 16px;
    margin: 0 0 8px;
}

.salary-year-table {
    table-layout: fixed;
}

.salary-year-table th,
.salary-year-table td {
    font-size: 11px;
    padding: 4px 3px;
    text-align: center;
}

.salary-year-input {
    font-size: 11px;
    min-height: 26px;
    padding: 3px 4px;
    text-align: center;
    width: 100%;
}

.salary-year-table th:nth-child(1),
.salary-year-table td:nth-child(1) {
    width: 72px;
}

.salary-year-table th:nth-child(2),
.salary-year-table td:nth-child(2) {
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 170px;
}

.chart-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(3, minmax(280px, 1fr));
}

.chart-card {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
}

.chart-card h3 {
    font-size: 15px;
    margin: 0 0 10px;
}

.chart-card canvas {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    height: auto;
    max-width: 100%;
    width: 100%;
}

#weeklyProjectsTable {
    min-width: 1180px;
}

#projectsTable {
    min-width: 1550px;
}

#yearMatrixTable {
    font-size: 12px;
    min-width: 1800px;
}

#yearMatrixTable.year-summary {
    table-layout: fixed;
    min-width: 0;
}

#yearMatrixTable.year-summary th,
#yearMatrixTable.year-summary td {
    font-size: 11px;
    padding: 4px 3px;
    text-align: center;
}

#yearMatrixTable.year-summary th {
    font-weight: 800;
}

#yearMatrixTable.year-summary td {
    font-weight: 400;
}

#yearMatrixTable.year-summary th:nth-child(1),
#yearMatrixTable.year-summary td:nth-child(1),
#yearMatrixTable.year-summary th:nth-child(2),
#yearMatrixTable.year-summary td:nth-child(2) {
    width: 46px;
}

#yearMatrixTable.year-summary th:nth-child(3),
#yearMatrixTable.year-summary td:nth-child(3) {
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 160px;
}

#yearMatrixTable.month-fit {
    table-layout: fixed;
    min-width: 0;
}

#yearMatrixTable.month-fit th,
#yearMatrixTable.month-fit td {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 10px;
    padding: 3px 2px;
    text-align: center;
}

#yearMatrixTable.month-fit th {
    font-weight: 800;
}

#yearMatrixTable.month-fit td {
    font-weight: 400;
}

#yearMatrixTable.month-fit th:nth-child(1),
#yearMatrixTable.month-fit td:nth-child(1),
#yearMatrixTable.month-fit th:nth-child(2),
#yearMatrixTable.month-fit td:nth-child(2) {
    width: 42px;
}

#yearMatrixTable.month-fit th:nth-child(3),
#yearMatrixTable.month-fit td:nth-child(3) {
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 148px;
}

#yearMatrixTable .matrix-hours-cell {
    background: #f8fbff;
    color: #172033;
    font-weight: 400;
    letter-spacing: 0;
}

#yearMatrixTable .matrix-empty-cell {
    color: #cbd5e1;
}

#yearMatrixTable.month-fit tbody tr:nth-child(even) .matrix-hours-cell {
    background: #eef7ff;
}

#weeklyProjectsTable input,
#weeklyProjectsTable select,
#projectsTable input {
    width: 100%;
}

#employeesTable input,
#employeesTable select {
    min-width: 120px;
    width: 100%;
}

#employeesTable {
    min-width: 1500px;
}

.row-actions,
#projectsTable th:first-child,
#projectsTable td:first-child,
#employeesTable th:first-child,
#employeesTable td:first-child {
    background: white;
    left: 0;
    position: sticky;
    z-index: 2;
}

#projectsTable th:first-child,
#employeesTable th:first-child {
    background: var(--surface-soft);
    z-index: 3;
}

.row-actions,
#projectsTable td:first-child {
    min-width: 145px;
    white-space: nowrap;
}

.row-actions button,
#projectsTable td:first-child button {
    margin: 0 4px 4px 0;
    padding-left: 9px;
    padding-right: 9px;
}

.project-name-cell {
    min-width: 180px;
}

.small-code {
    min-width: 100px;
}

.tiny-code {
    min-width: 72px;
}

#weeklyProjectsTable small {
    color: var(--muted);
    font-weight: 400;
}

#yearMatrixTable th,
#yearMatrixTable td {
    white-space: nowrap;
}

.generated-code {
    font-family: Consolas, monospace;
    font-size: 12px;
    min-width: 180px;
}

.field-display {
    color: var(--muted);
    display: block;
    font-size: 11px;
    margin-top: 2px;
}

.message {
    min-height: 20px;
}

.error {
    color: var(--red);
}

.login-error {
    animation: blink-twice 0.35s linear 4;
    font-weight: 400;
}

@keyframes blink-twice {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.ok,
.ok-total {
    color: var(--green);
}

.bad-total {
    background: #fff1f1;
    color: var(--red);
}

.pct-invalid-day {
    background: #fff4f4;
}

.pct-invalid-day input {
    background: #fff8f8;
    border-color: #f2b8b8;
}

.ok-total {
    background: #ecfdf5;
}

@media (max-width: 1050px) {
    .app-shell {
        grid-template-columns: 1fr;
    }
    .sidebar {
        height: auto;
        position: static;
    }
    .side-nav {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    }
    .grid.two {
        grid-template-columns: 1fr;
    }
    .chart-grid {
        grid-template-columns: 1fr;
    }
    .card-form-grid,
    .record-view-controls,
    .section-title-row,
    .project-card-grid,
    .employee-card-grid,
    .leave-card-grid,
    .salary-card-grid,
    .holiday-card-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }
}

@media (max-width: 720px) {
    main {
        padding: 8px 12px 24px;
    }
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 14px;
    }
    .attendance-controls,
    .form-grid,
    .punch-row,
    .project-form,
    .allocation-row,
    .month-controls,
    .monthly-kpis,
    .card-form-grid,
    .record-view-controls,
    .project-card-grid,
    .employee-card-grid,
    .leave-card-grid,
    .salary-card-grid,
    .holiday-card-grid {
        grid-template-columns: 1fr;
    }
    .leave-metric-grid,
    .leave-calendar {
        grid-template-columns: 1fr;
    }
    .edit-card-header {
        display: block;
    }
    .card-actions {
        justify-content: flex-start;
        margin-top: 10px;
    }
}

@media print {
    body {
        background: white;
    }
    .sidebar,
    .topbar,
    button,
    .actions,
    input,
    select {
        display: none !important;
    }
    .app-shell {
        display: block;
    }
    main {
        max-width: none;
        padding: 0;
    }
    .panel,
    .login-panel {
        border: 0;
        box-shadow: none;
        padding: 0;
    }
}
