/* =============================================================
   1. CORE RESET & PRINT SETTINGS
   ============================================================= */
* {
    box-sizing: border-box;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

body {
    margin: 0;
    padding: 0;
    background: #e2e8f0; 
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* =============================================================
   2. STYLISH TOP BAR (WEB INTERFACE)
   ============================================================= */
.top-bar {
    position: fixed;
    top: 20px;
    background: rgba(15, 23, 42, 0.85); /* Semi-transparent Midnight */
    backdrop-filter: blur(12px); /* Blur effect */
    -webkit-backdrop-filter: blur(12px);
    padding: 12px 30px;
    border-radius: 100px;
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 1000;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* STYLISH DROPDOWN */
.top-bar select {
    appearance: none; /* Remove default arrow */
    background-color: #334155;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    color: #fff;
    padding: 10px 40px 10px 18px;
    border-radius: 12px;
    border: 1px solid #475569;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.top-bar select:hover {
    background-color: #475569;
    border-color: #64748b;
    transform: translateY(-1px);
}

/* STYLISH BUTTONS */
.home-btn, .print-btn {
    padding: 10px 22px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.home-btn { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.print-btn { background: linear-gradient(135deg, #10b981, #059669); }

.home-btn:hover, .print-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
    filter: brightness(1.1);
}

.home-btn:active, .print-btn:active {
    transform: translateY(0);
}

/* =============================================================
   3. THE PAGE CONTAINER (A4)
   ============================================================= */
.page {
    width: 210mm;
    background: #fff;
    margin: 100px auto 40px auto;
    padding: 12mm 15mm;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border-radius: 8px;
}

/* =============================================================
   4. HEADER SECTION
   ============================================================= */
.header {
    text-align: center;
    margin-bottom: 25px;
}

.school {
    font-size: 25pt;
    font-weight: 700;
    color: #1e3a8a;
    text-transform: uppercase;
    margin: 0;
    letter-spacing: -0.5px;
}

.exam {
    font-size: 13pt;
    color: #475569;
    font-weight: 600;
    margin: 5px 0;
    letter-spacing: 2px;
}

.class {
    display: inline-block;
    background: #1e3a8a;
    color: #fff;
    padding: 6px 35px;
    border-radius: 50px;
    font-weight: 800;
    font-size: 12pt;
    margin-top: 8px;
    box-shadow: 0 4px 10px rgba(30, 58, 138, 0.3);
}

/* =============================================================
   5. TABLE STYLING
   ============================================================= */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 5px;
    table-layout: fixed;
}

thead th {
    background: #1e293b !important;
    color: #ffffff !important;
    padding: 15px;
    font-size: 11pt;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

th:first-child { border-radius: 10px 0 0 10px; }
th:last-child { border-radius: 0 10px 10px 0; }

td {
    padding: 8px;
    vertical-align: middle;
    text-align: center;
}

td:first-child { border-radius: 10px 0 0 10px; }
td:last-child { border-radius: 0 10px 10px 0; }

/* 🌈 ROW COLORS & ACCENTS */
tr:nth-child(6n+1) td { background-color: #f0f9ff !important; border-left: 8px solid #3b82f6 !important; }
tr:nth-child(6n+2) td { background-color: #fff1f2 !important; border-left: 8px solid #f43f5e !important; }
tr:nth-child(6n+3) td { background-color: #f0fdf4 !important; border-left: 8px solid #22c55e !important; }
tr:nth-child(6n+4) td { background-color: #fffbeb !important; border-left: 8px solid #f59e0b !important; }
tr:nth-child(6n+5) td { background-color: #faf5ff !important; border-left: 8px solid #a855f7 !important; }
tr:nth-child(6n+6) td { background-color: #f0fdfa !important; border-left: 8px solid #14b8a6 !important; }

.date { font-weight: 700; font-size: 14pt; color: #0f172a; display: block; }
.day { font-size: 14pt; color: #3f1a9b; text-transform: uppercase; font-weight: 700; }

/* BOLD SUBJECT NAME */
td:last-child {
    font-weight: 700; 
    font-size: 14pt; 
    color: #0f172a;
    text-transform: uppercase;
    letter-spacing: -0.5px;
}

.no-exam td { 
    background: #f8fafc !important; 
    color: #94a3b8 !important; 
    font-style: italic; 
    border-left: 8px solid #94a3b8 !important;
}

/* =============================================================
   6. FOOTER
   ============================================================= */
.notes {
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    padding: 18px;
    border-radius: 12px;
    font-size: 10pt;
    line-height: 1.5;
    margin-top: 20px;
}

.signatures {
    margin-top: 50px;
    display: flex;
    justify-content: space-between;
}

.sig-box {
    width: 30%;
    text-align: center;
    font-weight: 800;
}

.line {
    border-bottom: 2px solid #1e293b;
    margin-bottom: 10px;
    height: 40px;
}

/* Container for stacked subjects */
.subject-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px; /* Space between the two subjects */
}

/* Style for individual subjects in a stack */
.subject-stack span {
    display: block;
    line-height: 1.1;
}

/* Optional: Slightly reduce font size when two subjects are present 
   to keep the table row from becoming too tall */
.subject-stack span {
    font-size: 14pt; 
}

/* Keep the first subject bold or slightly different if desired */
.subject-stack span:first-child {
    color: #1e3a8a;
}
.timetable-title {
    margin-top: 4px;
    font-size: 12pt;          /* readable, not huge */
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #475569;
}

/* =============================================================
   7. PRINT OVERRIDES
   ============================================================= */
@media print {

    @page {
        size: A4 portrait;
        margin: 6mm;
    }

    body {
        background: #fff;
    }

    .top-bar {
        display: none !important;
    }

    /* Force everything to stay on one page */
    .page {
        width: 100%;
        margin: 0;
        padding: 4mm;
        box-shadow: none;

        /* 🔑 KEY PART */
        page-break-inside: avoid;
        break-inside: avoid;
        transform: scale(0.95);           /* auto fit */
        transform-origin: top left;
    }

    table,
    tr,
    td {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    td {
        padding: 4px;        /* compact but readable */
        font-size: 9pt;    /* print-safe size */
        line-height: 1;
    }

    th {
        font-size: 9pt;
        padding: 5px;
    }
    .timetable-title {
        font-size: 10pt;
        letter-spacing: 0.8px;
        color: #334155;
    }
}
/* =========================
   MOBILE VIEW ONLY
   (NO DESKTOP, NO PRINT)
   ========================= */
@media screen and (max-width: 768px) {

    /* Top bar */
    .top-bar {
        position: static;
        transform: none;
        margin: 10px auto;
        padding: 10px;
        border-radius: 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .top-bar select {
        width: 100%;
        font-size: 14px;
    }

    .home-btn,
    .print-btn {
        width: 48%;
        font-size: 13px;
        padding: 8px;
        justify-content: center;
    }

    /* Page */
    .page {
        width: 100%;
        margin: 10px auto;
        padding: 10px;
        border-radius: 12px;
    }

    /* Header */
    .school {
        font-size: 18px;
    }

    .timetable-title {
        font-size: 13px;
        letter-spacing: 0.8px;
    }

    .exam {
        font-size: 12px;
    }

    .class {
        font-size: 12px;
        padding: 4px 14px;
    }

    /* Table → card style (mobile only) */
    table,
    thead,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    thead {
        display: none; /* mobile only */
    }

    tr {
        margin-bottom: 12px;
        border-radius: 10px;
        overflow: hidden;
    }

    td {
        text-align: left;
        padding: 8px 10px;
        font-size: 14px;
        border-bottom: none;
    }

    td:first-child {
        background: rgba(0,0,0,0.04);
        font-weight: 700;
    }

    .date {
        font-size: 14px;
    }

    .day {
        display: block;
        font-size: 11px;
        color: #64748b;
    }

    .subject-stack span,
    .subject-name {
        font-size: 15px;
        font-weight: 700;
        display: block;
    }

    .prep-text {
        font-size: 14px;
        font-style: italic;
    }
}
