/* ==============================
   GLOBAL STYLING
================================ */

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background-color: #f4f6f8;
}

.container {
    max-width: 1000px;
    margin: 40px auto;
    padding: 20px;
}

/* ==============================
   TOP NAV
================================ */

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.top-nav .brand {
    font-size: 18px;
    font-weight: bold;
    color: #2c7be5;
    text-decoration: none;
}

.top-nav .user-area {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: #444;
}

.top-nav .user-area a {
    color: #2c7be5;
    text-decoration: none;
    font-weight: bold;
}

.top-nav .user-area a:hover { text-decoration: underline; }

a.user-name-btn {
    background: #eef4ff;
    color: #2c7be5;
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 13px;
    font-weight: bold;
    text-decoration: none;
    transition: background 0.15s;
}

a.user-name-btn:hover {
    background: #d8eaff;
    text-decoration: none;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
}

h2 {
    margin-bottom: 20px;
}

/* ==============================
   PLATFORM NAV (outer top bar)
================================ */

.platform-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.platform-nav .brand {
    font-size: 18px;
    font-weight: bold;
    color: #2c7be5;
    text-decoration: none;
}

.platform-nav .user-area {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}

.platform-nav .user-area a {
    color: #2c7be5;
    text-decoration: none;
    font-weight: bold;
}

.platform-nav .user-area a:hover { text-decoration: underline; }

.home-icon {
    font-size: 20px;
    text-decoration: none;
    line-height: 1;
}

/* ==============================
   SIMULATION BOX
================================ */

.sim-bg {
    padding: 16px;
    box-sizing: border-box;
    min-height: calc(100vh - 52px);
}

.sim-bg-biscuit {
    background-color: #f0e6d3;
}

.sim-box {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.10);
    overflow: hidden;
    min-height: calc(100vh - 84px);
}

.sim-inner-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background-color: #1e293b;
    color: white;
}

.sim-inner-nav a {
    color: white;
    text-decoration: none;
    font-size: 14px;
    margin-left: 16px;
}

.sim-inner-nav a:hover { opacity: 0.8; }

.sim-inner-nav .sim-title {
    font-weight: bold;
    font-size: 16px;
    color: white;
    margin-left: 16px;
}

.sim-inner-nav .btn {
    margin-top: 0;
    padding: 6px 14px;
    font-size: 13px;
}

.sim-inner-nav .team-name {
    color: #cbd5e1;
    font-size: 14px;
    margin-right: 8px;
}

.sim-content {
    padding: 28px 32px;
}

/* ==============================
   NAVBAR
================================ */

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background-color: #1e293b;
    color: white;
}

.nav-logo {
    font-size: 18px;
    font-weight: bold;
    color: white;
}

.navbar a {
    color: white;
    text-decoration: none;
    margin-left: 20px;
    font-weight: 500;
}

.navbar a:hover {
    opacity: 0.8;
}

.navbar a {
    color: white;
    margin-left: 15px;
    text-decoration: none;
}

.logged-in {
    color: white;
    margin-right: 15px;
    font-weight: bold;
}

/* ==============================
   CARD DESIGN
================================ */

.card {
    background: white;
    padding: 30px;
    margin-bottom: 25px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.large-card {
    overflow-x: auto;
}

/* ==============================
   BUTTONS
================================ */

.btn {
    display: inline-block;
    padding: 12px 25px;
    background-color: #2563eb;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    margin-right: 10px;
    margin-top: 20px;
}

.btn:hover {
    opacity: 0.9;
}

.btn.secondary {
    background-color: #4b5563;
}

.btn.teacher {
    background-color: #7c3aed;
}

/* ==============================
   FORMS
================================ */

form {
    display: flex;
    flex-direction: column;
}

label {
    display: block;
    margin-top: 10px;
    margin-bottom: 5px;
    font-weight: bold;
}

input, select {
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
}

/* Auth forms: full-width stacked inputs */
.card form input,
.card form select {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

button {
    margin-top: 20px;
    padding: 10px;
    border-radius: 6px;
    border: none;
    background-color: #2563eb;
    color: white;
    font-size: 14px;
    cursor: pointer;
}

button:hover {
    background-color: #1e5ed6;
}

/* ==============================
   TABLE
================================ */

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

th, td {
    padding: 12px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}

th {
    background-color: #f0f3f7;
}

/* ==============================
   ERROR MESSAGE
================================ */

.error {
    background: #ffe0e0;
    color: #a10000;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 15px;
}

.error-message {
    background-color: #fee2e2;
    color: #b91c1c;
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 5px;
}

.investment-table {
    width: 100%;
    max-width: 600px;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.investment-table td {
    border-bottom: 1px solid #ddd;
    padding: 8px;
}

.investment-table tr:last-child td {
    border-bottom: 2px solid #333;
}
details {
    margin-bottom: 15px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 6px;
    overflow-x: auto;
}

summary {
    cursor: pointer;
    font-size: 1.05em;
    margin-bottom: 8px;
}

details ul {
    margin-top: 8px;
}

summary {
    cursor: pointer;
    font-size: 1.05em;
    margin-bottom: 8px;
}

details table {
    margin-top: 10px;
}

#performanceTable th:hover {
    background-color: #f0f0f0;
}

.sortable {
cursor:pointer;
}

.sortable:hover {
background-color:#f2f2f2;
}

.my-team {
    background-color: #f3f3f3;
    font-weight: 600;
}

#performanceTable tr.my-team td {
    background-color: #f3f3f3;
}

.performance-style td {
    vertical-align: top;
}

.performance-style td div {
    margin: 1px 0;
}

.process-header td {
    border-top: 2px solid #ddd;
    padding-top: 10px;
}

.run-row td {
    vertical-align: middle;
}

.run-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.run-row input {
    width: 90px;
}

.run-row button {
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-run-btn {
    margin-top:6px;
}

/* ==============================
   ERROR MODAL
================================ */

.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    background: rgba(0,0,0,0.6);

    display: flex;
    justify-content: center;
    align-items: center;

    z-index: 2000;
}

.error-modal {
    background: white;
    padding: 30px;
    border-radius: 10px;
    width: 380px;

    box-shadow: 0 8px 30px rgba(0,0,0,0.4);

    text-align: left;
}

.error-modal h2 {
    margin-top: 0;
}

.error-modal ul {
    margin-top: 10px;
    margin-bottom: 20px;
}

.error-modal button {
    background-color: #2563eb;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
}

/* ==============================
   PDF IMPROVEMENTS
================================ */

@page {
    size: A4;
    margin: 2cm;
}

table {
    page-break-inside: avoid;
}

h1, h2, h3 {
    page-break-after: avoid;
}

details {
    page-break-inside: avoid;
}


/* ==============================
   RESPONSIVE — MOBILE (≤ 768px)
================================ */

@media (max-width: 768px) {

    /* Outer container pages (login, hub, etc.) */
    .container {
        margin: 16px auto;
        padding: 12px 16px;
    }

    /* Platform nav */
    .platform-nav {
        padding: 10px 16px;
    }

    .platform-nav .brand {
        font-size: 16px;
    }

    a.user-name-btn {
        font-size: 12px;
        padding: 4px 10px;
    }

    /* Simulator background shell */
    .sim-bg {
        padding: 6px;
    }

    .sim-box {
        border-radius: 6px;
        min-height: calc(100vh - 60px);
    }

    /* Simulator inner nav */
    .sim-inner-nav {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .sim-inner-nav .sim-title {
        font-size: 13px;
    }

    .sim-inner-nav a {
        font-size: 13px;
        margin-left: 8px;
    }

    .sim-inner-nav .btn {
        padding: 5px 10px;
        font-size: 12px;
        margin-top: 0;
    }

    /* Main content area */
    .sim-content {
        padding: 14px 16px;
    }

    /* Cards */
    .card {
        padding: 16px;
        margin-bottom: 14px;
    }

    /* Forms — full-width inputs, tighter spacing */
    form label {
        margin-top: 10px;
    }

    form input,
    form select {
        width: 100%;
        box-sizing: border-box;
    }

    /* Buttons */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Error modal */
    .error-modal {
        width: 88%;
        padding: 20px;
    }

}

/* ==============================
   RESPONSIVE — PHONE (≤ 600px)
   Production planning table:
   card-per-line stacked layout
================================ */

@media (max-width: 600px) {

    .production-plan-table thead {
        display: none;
    }

    .production-plan-table tbody tr {
        display: block;
        margin-bottom: 16px;
        border: 2px solid #c8d9f5;
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    .production-plan-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
        border-bottom: none;
    }

    /* Line header band — process type and unit range */
    .production-plan-table td:first-of-type {
        background: #eef4ff;
        border-bottom: 1px solid #c8d9f5;
        padding: 10px 14px;
    }

    /* Runs content area */
    .production-plan-table td:nth-of-type(2) {
        padding: 12px 14px;
    }

    /* Biscuit select stretches to fill available width */
    .production-plan-table .run-row select {
        flex: 1;
        min-width: 0;
    }

    /* Monthly results table — card-per-team-row */
    .monthly-results-table thead {
        display: none;
    }

    .monthly-results-table tbody tr {
        display: block;
        margin-bottom: 14px;
        border: 2px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    /* Team name — header band */
    .monthly-results-table td:nth-of-type(1) {
        display: block;
        background: #eef4ff;
        border-bottom: 1px solid #c8d9f5;
        padding: 10px 14px;
        font-weight: bold;
        font-size: 15px;
    }

    /* All other cells — label: value rows */
    .monthly-results-table td:nth-of-type(n+2) {
        display: flex;
        justify-content: space-between;
        padding: 6px 14px;
        border-bottom: 1px solid #f0f0f0;
        border-top: none;
    }

    .monthly-results-table td:nth-of-type(n+2)::before {
        font-weight: bold;
        color: #555;
        margin-right: 8px;
        white-space: nowrap;
    }

    .monthly-results-table td:nth-of-type(2)::before  { content: "Quality:"; }
    .monthly-results-table td:nth-of-type(3)::before  { content: "Auto Submitted:"; }
    .monthly-results-table td:nth-of-type(4)::before  { content: "Produced:"; }
    .monthly-results-table td:nth-of-type(5)::before  { content: "Sold:"; }
    .monthly-results-table td:nth-of-type(6)::before  { content: "Revenue:"; }
    .monthly-results-table td:nth-of-type(7)::before  { content: "Total Cost:"; }
    .monthly-results-table td:nth-of-type(8)::before  { content: "Profit:"; }

    /* ---- Investment breakdown table (4 cols) ---- */

    .investment-breakdown-table thead {
        display: none;
    }

    .investment-breakdown-table tbody tr {
        display: block;
        margin-bottom: 14px;
        border: 2px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    /* Team name — header band */
    .investment-breakdown-table td:nth-of-type(1) {
        display: block;
        background: #eef4ff;
        border-bottom: 1px solid #c8d9f5;
        padding: 10px 14px;
        font-weight: bold;
        font-size: 15px;
    }

    /* Financial cells — label:value rows */
    .investment-breakdown-table td:nth-of-type(n+2) {
        display: flex;
        justify-content: space-between;
        padding: 6px 14px;
        border-bottom: 1px solid #f0f0f0;
        border-top: none;
    }

    .investment-breakdown-table td:nth-of-type(n+2)::before {
        font-weight: bold;
        color: #555;
        margin-right: 8px;
        white-space: nowrap;
    }

    .investment-breakdown-table td:nth-of-type(2)::before { content: "Initial Investment:"; }
    .investment-breakdown-table td:nth-of-type(3)::before { content: "Unused Capital:"; }
    .investment-breakdown-table td:nth-of-type(4)::before { content: "Remaining Investment:"; }

    /* ---- Registered teams table (6 cols, has inline forms) ---- */

    .registered-teams-table thead {
        display: none;
    }

    .registered-teams-table tbody tr {
        display: block;
        margin-bottom: 16px;
        border: 2px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    /* Team name — header band */
    .registered-teams-table td:nth-of-type(1) {
        display: block;
        background: #eef4ff;
        border-bottom: 1px solid #c8d9f5;
        padding: 10px 14px;
        font-weight: bold;
        font-size: 15px;
    }

    /* Password, Status, Factory Result — label:value rows */
    .registered-teams-table td:nth-of-type(2),
    .registered-teams-table td:nth-of-type(3),
    .registered-teams-table td:nth-of-type(4) {
        display: flex;
        justify-content: space-between;
        padding: 6px 14px;
        border-bottom: 1px solid #f0f0f0;
        border-top: none;
    }

    .registered-teams-table td:nth-of-type(2)::before { content: "Password:";       font-weight: bold; color: #555; margin-right: 8px; white-space: nowrap; }
    .registered-teams-table td:nth-of-type(3)::before { content: "Status:";          font-weight: bold; color: #555; margin-right: 8px; white-space: nowrap; }
    .registered-teams-table td:nth-of-type(4)::before { content: "Factory Result:";  font-weight: bold; color: #555; margin-right: 8px; white-space: nowrap; }

    /* Rename form — full-width block */
    .registered-teams-table td:nth-of-type(5) {
        display: block;
        padding: 10px 14px;
        border-bottom: 1px solid #f0f0f0;
        border-top: none;
    }

    .registered-teams-table td:nth-of-type(5) input[type="text"] {
        width: 100%;
        box-sizing: border-box;
    }

    .registered-teams-table td:nth-of-type(5) button {
        margin-top: 8px;
        width: 100%;
    }

    /* Delete button — full-width block */
    .registered-teams-table td:nth-of-type(6) {
        display: block;
        padding: 10px 14px;
        border-top: none;
    }

    .registered-teams-table td:nth-of-type(6) button {
        margin-top: 0;
        width: 100%;
    }

    /* ---- Team performance table (single-row, 12 cols) ---- */

    .team-performance-table thead {
        display: none;
    }

    .team-performance-table tbody tr {
        display: block;
        margin-bottom: 14px;
        border: 2px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    .team-performance-table td {
        display: flex;
        justify-content: space-between;
        padding: 6px 14px;
        border-bottom: 1px solid #f0f0f0;
        border-top: none;
    }

    .team-performance-table td::before {
        font-weight: bold;
        color: #555;
        margin-right: 8px;
        white-space: nowrap;
    }

    .team-performance-table td:nth-of-type(1)::before  { content: "Profit:"; }
    .team-performance-table td:nth-of-type(2)::before  { content: "Gross Profit Margin:"; }
    .team-performance-table td:nth-of-type(3)::before  { content: "Cash:"; }
    .team-performance-table td:nth-of-type(4)::before  { content: "Remaining Investment:"; }
    .team-performance-table td:nth-of-type(5)::before  { content: "Overheads:"; }
    .team-performance-table td:nth-of-type(6)::before  { content: "Total Units Produced:"; }
    .team-performance-table td:nth-of-type(7)::before  { content: "Total Units Sold:"; }
    .team-performance-table td:nth-of-type(8)::before  { content: "Units Not Sold:"; }
    .team-performance-table td:nth-of-type(9)::before  { content: "% Wastage:"; }
    .team-performance-table td:nth-of-type(10)::before { content: "Wastage Cost:"; }
    .team-performance-table td:nth-of-type(11)::before { content: "Capacity Utilisation:"; }
    .team-performance-table td:nth-of-type(12)::before { content: "Buffer Stock:"; }

    /* ---- Class performance table (multi-row, 13 cols) ---- */

    .class-performance-table thead {
        display: none;
    }

    .class-performance-table tbody tr {
        display: block;
        margin-bottom: 14px;
        border: 2px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    .class-performance-table tbody tr.my-team {
        border-color: #c8d9f5;
    }

    /* Team name — header band */
    .class-performance-table td:nth-of-type(1) {
        display: block;
        background: #eef4ff;
        border-bottom: 1px solid #c8d9f5;
        padding: 10px 14px;
        font-weight: bold;
        font-size: 15px;
    }

    .class-performance-table tbody tr.my-team td:nth-of-type(1) {
        background: #dbeafe;
    }

    /* All other cells — label: value rows */
    .class-performance-table td:nth-of-type(n+2) {
        display: flex;
        justify-content: space-between;
        padding: 6px 14px;
        border-bottom: 1px solid #f0f0f0;
        border-top: none;
    }

    .class-performance-table td:nth-of-type(n+2)::before {
        font-weight: bold;
        color: #555;
        margin-right: 8px;
        white-space: nowrap;
    }

    .class-performance-table td:nth-of-type(2)::before  { content: "Profit:"; }
    .class-performance-table td:nth-of-type(3)::before  { content: "Gross Profit Margin:"; }
    .class-performance-table td:nth-of-type(4)::before  { content: "Cash:"; }
    .class-performance-table td:nth-of-type(5)::before  { content: "Remaining Investment:"; }
    .class-performance-table td:nth-of-type(6)::before  { content: "Overheads:"; }
    .class-performance-table td:nth-of-type(7)::before  { content: "Total Units Produced:"; }
    .class-performance-table td:nth-of-type(8)::before  { content: "Total Units Sold:"; }
    .class-performance-table td:nth-of-type(9)::before  { content: "Units Not Sold:"; }
    .class-performance-table td:nth-of-type(10)::before { content: "% Wastage:"; }
    .class-performance-table td:nth-of-type(11)::before { content: "Wastage Cost:"; }
    .class-performance-table td:nth-of-type(12)::before { content: "Capacity Utilisation:"; }
    .class-performance-table td:nth-of-type(13)::before { content: "Buffer Stock:"; }

}
