/* =========================================================
   ALP Marking System - Mobile App Friendly Styles
   ========================================================= */

* {
    box-sizing: border-box;
}

html {
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: Arial, sans-serif;
    background: #f4f6f8;
    margin: 0;
    padding: 0;
    color: #222;
    overscroll-behavior-y: contain;
}

.container {
    max-width: 1250px;
    margin: 20px auto;
    padding: 0 14px 30px;
}

h1 {
    margin-bottom: 10px;
    font-size: 28px;
}

h2 {
    margin-top: 0;
    font-size: 22px;
}

h3 {
    font-size: 18px;
}

.card {
    background: #fff;
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    overflow: hidden;
}

.card,
button,
.mark-btn,
.bottom-nav a,
.button-link {
    transition: all 0.18s ease;
}

/* =========================================================
   Forms and Buttons
   ========================================================= */

.filter-form .form-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

label {
    margin-bottom: 6px;
    font-weight: bold;
    font-size: 14px;
}

select,
button,
input {
    padding: 12px;
    font-size: 16px;
    border-radius: 10px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
}

.actions {
    margin-top: 14px;
}

button {
    background: #1f5fbf;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 700;
}

button:hover {
    background: #174b98;
}

button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

button,
a,
summary,
.mark-btn {
    touch-action: manipulation;
}

.button-link {
    display: inline-block;
    text-decoration: none;
    background: #1f5fbf;
    color: white;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
}

.button-link:hover {
    background: #174b98;
}

.message {
    background: #fff3cd;
    border: 1px solid #ffecb5;
    padding: 12px;
    border-radius: 10px;
    line-height: 1.5;
}

/* =========================================================
   Access / Login
   ========================================================= */

.login-card {
    max-width: 460px;
    margin: 40px auto;
}

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

/* =========================================================
   Details / Accordion Base
   ========================================================= */

details summary {
    cursor: pointer;
}

.class-summary,
.student-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    font-weight: 600;
}

.student-total-preview {
    color: #1f5fbf;
    font-weight: 700;
    text-align: right;
}

.student-card {
    margin-top: 12px;
    border-top: 1px solid #eee;
    padding-top: 12px;
}

/* =========================================================
   Question / Marking Layout
   ========================================================= */

.question-list {
    margin-top: 12px;
}

.question-card {
    border: 1px solid #e4e7eb;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fafbfd;
}

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

.question-left {
    flex: 1;
    min-width: 0;
}

.question-title {
    margin-bottom: 8px;
    line-height: 1.5;
    word-break: break-word;
}

.performance-indicator {
    font-size: 13px;
    background: #eef6ff;
    border: 1px solid #d7e8ff;
    padding: 8px 10px;
    border-radius: 8px;
    display: inline-block;
    line-height: 1.4;
    word-break: break-word;
}

.question-right {
    min-width: 180px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex-shrink: 0;
}

.mini-details {
    position: relative;
}

.mini-details > summary {
    list-style: none;
    font-size: 14px;
    line-height: 1.2;
    padding: 8px 10px;
    border-radius: 10px;
    background: #eef1f4;
    border: 1px solid #d8dde3;
    text-align: center;
    user-select: none;
}

.mini-details > summary::-webkit-details-marker {
    display: none;
}

.question-details-box {
    margin-top: 10px;
    background: #ffffff;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    padding: 12px;
    min-width: 280px;
    max-width: 520px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.question-details-box p {
    margin: 0 0 10px 0;
    line-height: 1.4;
    word-break: break-word;
}

.question-image-wrap {
    margin-top: 10px;
}

.question-image {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    display: block;
}

.mark-input {
    min-width: 78px;
    font-weight: bold;
}

.mark-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 90px;
}

.mark-btn {
    min-height: 54px;
    border-radius: 12px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    font-size: 20px;
    font-weight: 800;
    cursor: pointer;
}

.mark-btn:hover {
    background: #f3f6fb;
}

.mark-btn.selected {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

.mark-btn.zero.selected {
    background: #dc2626;
    border-color: #dc2626;
}

.save-status {
    font-size: 12px;
    min-height: 16px;
    line-height: 1.3;
}

.save-status.saving {
    color: #996c00;
}

.save-status.saved {
    color: #198754;
    font-weight: 600;
}

.save-status.error {
    color: #dc3545;
    font-weight: 600;
}

.total-box {
    margin-top: 10px;
    font-weight: bold;
    background: #eef6ff;
    padding: 10px 12px;
    border-radius: 10px;
    display: inline-block;
    line-height: 1.4;
}

/* =========================================================
   Dashboard
   ========================================================= */

.dashboard-header {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 16px;
}

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

.kpi-label {
    font-size: 13px;
    color: #555;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 30px;
    font-weight: 700;
    color: #1f5fbf;
    line-height: 1.2;
}

.dashboard-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.sortable-table th {
    user-select: none;
}

.sortable-table th:hover {
    background: #dde7f5;
}

.table-wrapper {
    overflow-x: auto;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

th,
td {
    border: 1px solid #ddd;
    padding: 10px;
    vertical-align: top;
    text-align: left;
    line-height: 1.4;
}

th {
    background: #f3f6fa;
}

canvas {
    width: 100% !important;
    max-width: 100%;
    height: 320px !important;
}

/* =========================================================
   Mobile App Shell Helpers
   These support the new base.html / home.html structure.
   ========================================================= */

.app-header {
    backdrop-filter: blur(10px);
}

.bottom-nav {
    padding-bottom: max(6px, env(safe-area-inset-bottom));
}

.home-action:active,
.bottom-nav a:active,
button:active {
    transform: scale(0.98);
}

/* =========================================================
   Tablet
   ========================================================= */

@media (max-width: 900px) {
    .container {
        padding: 0 12px 24px;
    }

    .filter-form .form-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .question-main-row {
        flex-direction: column;
    }

    .question-right {
        min-width: auto;
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .question-details-box {
        min-width: auto;
        max-width: 100%;
    }

    .dashboard-header {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-two-col {
        grid-template-columns: 1fr;
    }

    canvas {
        height: 280px !important;
    }
}

/* =========================================================
   Mobile
   ========================================================= */

@media (max-width: 600px) {
    .container {
        margin: 0 auto;
        padding: 0 10px 20px;
    }

    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    .card {
        padding: 14px;
        margin-bottom: 14px;
        border-radius: 16px;
    }

    .filter-form .form-row {
        grid-template-columns: 1fr;
    }

    .class-summary,
    .student-summary {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .student-total-preview {
        text-align: left;
    }

    .question-card {
        padding: 10px;
    }

    .question-right {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .mark-control,
    .mark-input {
        width: 100%;
    }

    .dashboard-header {
        grid-template-columns: 1fr;
    }

    .kpi-value {
        font-size: 26px;
    }

    table {
        min-width: 560px;
    }

    canvas {
        height: 240px !important;
    }

    .login-card {
        margin: 20px auto;
        max-width: 100%;
    }

    .button-link {
        width: 100%;
        text-align: center;
        margin-bottom: 8px;
    }
}


/* =========================================================
   Arabic / RTL Support
   ========================================================= */

html[dir="rtl"] body {
    direction: rtl;
    text-align: right;
}

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

html[dir="rtl"] .app-subtitle,
html[dir="rtl"] .home-subtitle,
html[dir="rtl"] .kpi-label {
    text-align: right;
}

html[dir="rtl"] .home-card {
    text-align: center;
}

html[dir="rtl"] .home-meta {
    text-align: right;
}

html[dir="rtl"] .home-action {
    flex-direction: row-reverse;
}

html[dir="rtl"] .class-summary,
html[dir="rtl"] .student-summary,
html[dir="rtl"] .mobile-toolbar-row,
html[dir="rtl"] .question-main-row,
html[dir="rtl"] .question-right {
    direction: rtl;
}

html[dir="rtl"] .student-total-preview {
    text-align: left;
}

html[dir="rtl"] .details-icon-row {
    justify-content: flex-start;
}

html[dir="rtl"] .mini-details summary {
    margin-left: 0;
    margin-right: auto;
}

html[dir="rtl"] table,
html[dir="rtl"] th,
html[dir="rtl"] td {
    text-align: right;
}

html[dir="rtl"] .bottom-nav {
    direction: rtl;
}

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

html[dir="rtl"] canvas {
    direction: ltr;
}
