:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --black: #111827;
    --sidebar-bg: #111827;
    --sidebar-hover: #1f2937;
    --light-gray: #f3f4f6;
    --white: #ffffff;
    --status-pending: #f59e0b;
    --status-pending-dark: #b45309;
    --status-ongoing: #0ea5e9;
    --status-completed: #16a34a;
    --status-completed-dark: #15803d;
    --status-rectification: #e11d48;
    --status-rectification-dark: #9f1239;
    --red: #4f46e5;
    --red-dark: #3730a3;
    --sidebar-width: 220px;
}
* { box-sizing: border-box; }
body { margin:0; font-family:'Segoe UI', Arial, sans-serif; background:var(--light-gray); color:var(--black); overflow-x:hidden; }

/* ---------- Login screen ---------- */
#loginScreen { display:flex; align-items:center; justify-content:center; min-height:100vh; background:var(--black); padding:20px; box-sizing:border-box; overflow-y:auto; }
.login-box { background:var(--white); border-radius:10px; padding:40px 36px; width:100%; max-width:380px; box-shadow:0 10px 30px rgba(0,0,0,0.4); border-top:6px solid var(--primary); text-align:center; }
.login-logo-img { max-width:220px; height:auto; margin:0 auto 14px; display:block; }
.login-logo .title { font-weight:700; font-size:19px; }
.login-subtitle { font-size:13px; color:#888; margin:6px 0 22px; }
.login-box label { display:block; margin:14px 0 6px; font-weight:600; font-size:13px; text-align:left; }
.login-box input { width:100%; padding:11px; border:1px solid #ccc; border-radius:6px; font-size:14px; }
.login-hint { margin-top:20px; font-size:12px; color:#999; }
.login-hint strong { color:#555; }
.login-error { background:#fef2f2; color:var(--status-rectification-dark); border-left:5px solid var(--status-rectification); padding:10px 14px; border-radius:5px; font-size:13px; margin-bottom:6px; display:none; text-align:left; }

/* ---------- App shell ---------- */
#appScreen { display:none; }
.sidebar { position:fixed; top:0; left:0; bottom:0; width:var(--sidebar-width); background:var(--sidebar-bg); color:var(--white); display:flex; flex-direction:column; border-right:4px solid var(--primary); }
.sidebar-brand { display:flex; flex-direction:column; align-items:center; gap:8px; padding:20px 14px; border-bottom:1px solid #24304a; text-align:center; }
.brand-logo-img { height:40px; width:auto; max-width:100%; object-fit:contain; background:#fff; padding:4px 6px; border-radius:6px; flex-shrink:0; }
.brand-name { font-weight:700; font-size:14px; line-height:1.2; }
.brand-sub { font-size:10px; color:#93a0b8; text-transform:uppercase; margin-top:2px; }
.sidebar-nav { flex:1; padding:16px 10px; display:flex; flex-direction:column; gap:6px; }
.sidebar-nav a { color:#cbd5e1; text-decoration:none; padding:12px 14px; border-radius:6px; font-weight:600; font-size:14px; cursor:pointer; display:flex; align-items:center; gap:10px; }
.sidebar-nav a .icon { color:var(--primary); width:16px; text-align:center; filter:brightness(1.6); }
.sidebar-nav a:hover { background:var(--sidebar-hover); color:var(--white); }
.sidebar-nav a.active { background:var(--primary); color:var(--white); }
.sidebar-nav a.active .icon { color:var(--white); filter:none; }
.nav-badge { background:var(--status-rectification); color:var(--white); font-size:10px; font-weight:700; padding:1px 7px; border-radius:20px; margin-left:auto; }
.sidebar-user { padding:14px 18px; border-top:1px solid #24304a; }
.sidebar-user-name { font-size:12px; color:#cbd5e1; margin-bottom:8px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sidebar-role-badge { display:inline-block; background:var(--primary); color:var(--white); font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:0.5px; padding:2px 8px; border-radius:20px; margin-bottom:8px; }
.permission-group { margin-top:20px; padding-top:16px; border-top:1px solid #e5e7eb; }
.permission-group:first-of-type { margin-top:16px; padding-top:0; border-top:none; }
.permission-group h3 { margin:0 0 10px; font-size:13px; text-transform:uppercase; letter-spacing:0.5px; color:var(--primary); }
.permission-checkbox { display:flex; align-items:center; gap:10px; padding:8px 0; font-size:14px; font-weight:500; cursor:pointer; }
.permission-checkbox input { width:16px; height:16px; accent-color:var(--primary); cursor:pointer; }

/* Modal overlay for the Request Change form */
.modal-overlay { position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:100; align-items:center; justify-content:center; padding:16px; box-sizing:border-box; }
.modal-box { background:var(--white); border-radius:10px; padding:28px 30px; width:100%; max-width:420px; max-height:90vh; overflow-y:auto; box-shadow:0 12px 32px rgba(0,0,0,0.3); }
.modal-box h2 { margin-top:0; border-bottom:2px solid var(--primary); padding-bottom:10px; }
.modal-box label { display:block; margin:12px 0 6px; font-weight:600; font-size:14px; }
.modal-box select, .modal-box textarea, .modal-box input { width:100%; padding:9px; border:1px solid #ccc; border-radius:5px; font-size:14px; font-family:inherit; }
.modal-box textarea { min-height:70px; resize:vertical; }
.sidebar-logout { font-size:12px; color:#f87171; text-decoration:none; font-weight:700; cursor:pointer; }
.sidebar-logout:hover { color:#fca5a5; }
.sidebar-footer { padding:12px 18px 16px; font-size:10px; color:#64748b; border-top:1px solid #24304a; }

.main { margin-left:var(--sidebar-width); min-height:100vh; transition:margin-left 0.2s ease; }
.topbar { background:var(--white); padding:18px 30px; border-bottom:3px solid var(--primary); }
.topbar h1 { margin:0; font-size:20px; }
.topbar h1 span { color:var(--primary); }
.container { max-width:1150px; margin:30px auto; padding:0 30px; }

.summary-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(160px,1fr)); gap:18px; margin-bottom:25px; }
.summary-card { background:var(--white); border-radius:8px; padding:18px 20px; box-shadow:0 2px 6px rgba(0,0,0,0.08); border-left:5px solid var(--primary); text-align:center; }
.summary-card.pending { border-left-color:var(--status-pending); }
.summary-card.ongoing { border-left-color:var(--status-ongoing); }
.summary-card.completed { border-left-color:var(--status-completed); }
.summary-card.rectification { border-left-color:var(--status-rectification); }
.summary-card.red { border-left-color:var(--status-completed); }
.summary-card-clickable { cursor:pointer; transition:transform 0.15s, box-shadow 0.15s, border-color 0.15s; }
.summary-card-clickable:hover { transform:translateY(-3px); box-shadow:0 8px 20px rgba(0,0,0,0.14); }
.summary-card .num { font-size:32px; font-weight:800; }
.summary-card .label { font-size:12px; color:#666; text-transform:uppercase; margin-top:4px; }

.card { background:var(--white); border-radius:8px; padding:20px; margin-bottom:25px; box-shadow:0 2px 6px rgba(0,0,0,0.08); border-top:4px solid var(--primary); }
.card.card-rectification { border-top-color:var(--status-rectification); }
.card h2 { margin-top:0; border-bottom:2px solid var(--primary); padding-bottom:10px; font-size:16px; }
.card-rectification h2 { border-bottom-color:var(--status-rectification); }

form.job-form { display:grid; grid-template-columns:1fr 1fr; gap:0 20px; }
form.job-form .full { grid-column:1/-1; }
form.job-form label { display:block; margin:10px 0 4px; font-weight:600; }
form.job-form input, form.job-form select, form.job-form textarea { width:100%; padding:9px; border:1px solid #ccc; border-radius:5px; font-size:14px; font-family:inherit; }
#reasonField { display:none; }
#reasonField.show { display:block; }

/* filter bar */
.filter-bar { display:grid; grid-template-columns:repeat(auto-fit, minmax(150px,1fr)); gap:14px; align-items:end; background:var(--white); border-radius:8px; padding:18px 20px; margin-bottom:20px; box-shadow:0 2px 6px rgba(0,0,0,0.08); border-left:5px solid var(--primary); }
.filter-bar label { display:block; font-size:11px; font-weight:700; text-transform:uppercase; color:#555; margin-bottom:4px; }
.filter-bar input, .filter-bar select { width:100%; padding:8px; border:1px solid #ccc; border-radius:5px; font-size:13px; }
.filter-actions { display:flex; gap:8px; }

.btn { display:inline-block; background:var(--primary); color:var(--white); border:none; padding:10px 20px; border-radius:5px; font-weight:600; cursor:pointer; margin-top:14px; font-size:14px; text-decoration:none; }
.btn:hover { background:var(--primary-dark); }
.btn-black { background:var(--black); }
.btn-black:hover { background:#2d3748; }
.btn-danger { background:var(--status-rectification); }
.btn-danger:hover { background:var(--status-rectification-dark); }
.btn-success { background:var(--status-completed); }
.btn-success:hover { background:var(--status-completed-dark); }
.btn-sm { padding:6px 12px; font-size:12px; margin-top:0; }

table { width:100%; border-collapse:collapse; margin-top:10px; }
.table-wrap { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table-wrap table { min-width:640px; }
th, td { padding:12px 10px; text-align:left; border-bottom:1px solid #e5e7eb; font-size:13px; vertical-align:top; }
th { background:var(--black); color:var(--white); text-transform:uppercase; font-size:11px; }
tr:hover { background:#fafbff; }

.badge { padding:4px 10px; border-radius:20px; font-size:12px; font-weight:700; color:var(--white); display:inline-block; white-space:nowrap; }
.badge-confirmed { background:var(--primary); }
.badge-production { background:#0891b2; }
.badge-pending { background:var(--status-pending); }
.badge-ongoing { background:var(--status-ongoing); }
.badge-completed { background:var(--status-completed); }
.badge-rectification { background:var(--status-rectification); }
.reason-note { display:block; margin-top:4px; font-size:11px; color:var(--status-pending-dark); font-style:italic; }
.rectification-note { display:block; margin-top:4px; font-size:11px; color:var(--status-rectification-dark); font-style:italic; }
.attempt-badge { display:inline-block; background:var(--status-rectification); color:var(--white); font-size:11px; font-weight:700; padding:2px 8px; border-radius:20px; margin-left:4px; }

/* Site Visit Requests - photo thumbnails */
.photo-thumb-row { display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.photo-thumb { width:56px; height:56px; object-fit:cover; border-radius:6px; border:1px solid #ddd; cursor:pointer; }
.photo-thumb-empty { font-size:12px; color:#999; font-style:italic; }

.empty-msg { text-align:center; color:#777; padding:20px; font-style:italic; }
.flash { padding:12px 16px; border-radius:5px; margin-bottom:18px; font-weight:600; background:var(--black); color:var(--white); border-left:5px solid var(--status-completed); display:none; }
.page { display:none; }
.page.active { display:block; }
.note { background:#fff7ed; border-left:5px solid var(--status-pending); padding:10px 14px; font-size:13px; margin-bottom:20px; border-radius:4px; }

/* Dashboard two-column layout + donut chart */
.dashboard-grid { display:grid; grid-template-columns:1.3fr 1fr; gap:20px; }
.dashboard-grid .card { margin-bottom:25px; }
.quick-links-col { display:flex; flex-direction:column; gap:10px; }
.quick-links-col .btn { margin-top:0; text-align:center; }
.donut-wrap { display:flex; align-items:center; gap:30px; flex-wrap:wrap; justify-content:center; padding:10px 0; }
.donut-wrap svg { max-width:100%; height:auto; }
.donut-legend { display:flex; flex-direction:column; gap:12px; }
.donut-legend-item { font-size:14px; font-weight:600; display:flex; align-items:center; gap:8px; }
.donut-legend-item .dot { width:12px; height:12px; border-radius:50%; display:inline-block; }
.donut-legend-item .pct { color:#888; font-weight:500; font-size:12px; }
@media (max-width:800px) { .dashboard-grid { grid-template-columns:1fr; } }

@media (max-width:900px) {
    :root { --sidebar-width:64px; }
    .brand-name, .brand-sub, .sidebar-footer, .sidebar-user-name { display:none; }
    .sidebar-brand { justify-content:center; }
    .sidebar-nav a .label { display:none; }
    .sidebar-nav a .nav-badge { position:absolute; top:6px; right:6px; margin-left:0; }
    .sidebar-nav a { justify-content:center; position:relative; }
    form.job-form { grid-template-columns:1fr; }
}

/* ---------- Mobile phones ---------- */
@media (max-width:600px) {
    :root { --sidebar-width:56px; }
    .container { padding:0 12px; margin:16px auto; }
    .topbar { padding:14px 16px; }
    .topbar h1 { font-size:17px; }

    .login-box { padding:28px 20px; max-width:100%; }

    .summary-grid { grid-template-columns:repeat(2, 1fr); gap:10px; }
    .summary-card { padding:12px 10px; }
    .summary-card .num { font-size:22px; }
    .summary-card .label { font-size:10px; }

    .card { padding:14px; margin-bottom:16px; }
    .card h2 { font-size:14px; }

    .filter-bar { grid-template-columns:1fr 1fr; gap:10px; padding:14px; }
    .filter-actions { grid-column:1/-1; }

    form.job-form { gap:0; }
    form.job-form label { font-size:13px; }
    form.job-form input, form.job-form select, form.job-form textarea { font-size:16px; } /* prevents iOS zoom-on-focus */

    .btn { width:100%; text-align:center; padding:11px 14px; }
    .btn-sm { width:auto; padding:6px 12px; }
    td .btn, td .btn-sm { display:block; width:100%; margin-top:6px; }
    td .btn:first-child { margin-top:0; }

    .quick-links-col .btn { width:100%; }

    th, td { padding:9px 8px; font-size:12px; }
    .table-wrap table { min-width:560px; }

    .photo-thumb { width:44px; height:44px; }

    .modal-box, .login-box { width:92%; }
    .modal-box { padding:20px 18px; }

    .donut-wrap { flex-direction:column; gap:14px; }
}
</style>

/* Action button groups inside table cells (added for the PHP rewrite) */
td.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
td.actions form { display: inline-flex; gap: 6px; flex-wrap: wrap; margin: 0; }
td.actions .btn, td.actions .btn-sm { margin-top: 0; }
.login-hint em { color: #b45309; }
