/* ========================================= */
/* === TEMA KORPORAT & ASAS (Base Styles) === */
/* ========================================= */
:root {
  /* Palette Warna Baru: Lebih "Deep" & Profesional */
  --bg: #f1f5f9;           /* Kelabu cair cool tone */
  --text: #1e293b;         /* Dark Slate (bukan hitam pekat) */
  --muted: #64748b;
  --primary: #1e40af;      /* Royal Blue (PPD Corporate Color) */
  --primary-dark: #1e3a8a; /* Darker Blue untuk Header */
  --accent: #3b82f6;       /* Lighter Blue untuk highlight */
  
  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --off: #9ca3af;
  
  --card: #ffffff;
  --ring: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Oswald', sans-serif;
  -webkit-font-smoothing: antialiased; 
}

.wrap {
  max-width: 1150px;
  margin: 20px auto;
  padding: 0 16px;
}

/* === HEADER BARU DENGAN LOGO === */
h1 {
  background: var(--primary-dark);
  color: #fff;
  margin: -20px -16px 20px -16px; /* Tarik ke tepi skrin */
  padding: 20px 20px;
  font-size: 1.35rem;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.25);
  border-radius: 0 0 16px 16px; 
  display: flex;
  align-items: center;
  gap: 15px; /* Jarak antara logo dan teks */
}

/* Gaya Logo KPM - Desktop */
.header-logo {
  height: 48px; /* Tinggi standard desktop */
  width: auto;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2)); 
  flex-shrink: 0; /* PENTING: Elak logo kemek bila teks panjang */
}

@media (min-width: 769px) {
  h1 {
    margin: 0 0 20px 0;
    border-radius: 12px;
  }
}

/* === Tabs === */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: transparent;
  border: none;
  padding: 4px;
  overflow-x: auto; 
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }

.tabbtn {
  border: 1px solid transparent;
  background: #e2e8f0; 
  color: var(--muted);
  padding: 10px 20px;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-size: 0.95rem;
  box-shadow: none;
}
.tabbtn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}
.tabpane { display: none; }
.tabpane.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* === Card === */
.card {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 16px; 
  padding: 20px;
  box-shadow: var(--shadow); 
  margin-bottom: 20px;
}
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
}
.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* === Forms === */
label.small {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  display: inline-block;
}
select, input[type="time"], input[type="text"], input[type="date"], button {
  font-family: inherit;
  font-size: 1rem;
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 10px 14px; 
  background: #f8fafc;
  outline: none;
  transition: all 0.2s;
  color: var(--text);
}
select:focus, input:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.btn {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--text); }
.btn.ghost { background: #fff; border: 1px solid var(--ring); color: var(--text); box-shadow: none; }
.req::after { content:" *"; color: var(--bad); }
.invalid { border-color: var(--bad) !important; background: #fef2f2 !important; }

/* === Calendar === */
.legend { display: flex; gap: 12px; align-items: center; margin: 0 0 16px; flex-wrap: wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; } 
.dot.green{background:var(--ok)} .dot.orange{background:var(--warn)} .dot.red{background:var(--bad)} .dot.disabled{background:var(--off)}

.calendar { display: grid; grid-template-rows: auto 1fr; gap: 12px; }
.weekday { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; font-size: 0.85rem; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.weekday div { text-align: center; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }

.tile {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 12px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  transition: transform 0.1s, border-color 0.1s;
}
.tile:hover { border-color: var(--accent); }
.tile.disabled { background: #f8fafc; opacity: 0.7; pointer-events: none; }

.tile .date {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}

/* Compact Counts for Overview */
.cnt-group {
  display: inline-flex;
  gap: 4px;
}
.cnt-pill {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
  line-height: 1;
}
.cnt-pill.red { background: var(--bad); }
.cnt-pill.orange { background: var(--warn); }

.badge {
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #fff;
}
.badge.red{background:var(--bad)} .badge.orange{background:var(--warn)} .badge.green{background:var(--ok)}

.tile .body { padding: 0 10px 10px; font-size: 0.9rem; line-height: 1.4; color: var(--text); }
.tile.sel { outline: 2px solid var(--primary); background: #eff6ff; }
.tile.range { outline: 2px solid var(--primary); background: #eff6ff; }

/* Switch & Counters */
.switch { display: inline-flex; background: #e2e8f0; border-radius: 12px; padding: 4px; }
.switch button { border: none; background: transparent; padding: 6px 14px; border-radius: 8px; font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.switch button.active { background: #fff; color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.counter { font-size: 0.9rem; color: var(--primary); background: #eff6ff; border: 1px solid #bfdbfe; padding: 8px 12px; border-radius: 8px; font-weight: 600; }

/* === Table === */
table { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid var(--ring); border-radius: 12px; overflow: hidden; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--ring); text-align: left; font-size: 0.95rem; vertical-align: middle; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.5px; }
tr:last-child td { border-bottom: none; }

.pill { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; margin: 2px 4px 2px 0; }
.pill.red { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.pill.orange { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* Admin */
#adminLoginBox { display: block; text-align: center; padding: 40px 20px; }
#adminPanel { display: none; }

/* SweetAlert */
.swal-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; text-align: left; }
.swal-form .full-width { grid-column: 1 / -1; }
.btn-icon { background: #f1f5f9; color: var(--text); width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; transition: 0.2s; }
.btn-icon:hover { background: var(--primary); color: #fff; }

/* === MOBILE OPTIMIZATION === */
@media (max-width: 768px) {
  .wrap { margin: 0; width: 100%; max-width: 100%; padding: 0; background: var(--bg); }
  
  h1 { 
    margin: 0 0 16px 0; 
    border-radius: 0 0 20px 20px; 
    padding: 16px 20px; 
    text-align: left; 
    font-size: 1.1rem; 
    line-height: 1.35;
    flex-direction: row; 
    align-items: center; 
    gap: 12px; 
  }
  
  .header-logo { 
    height: 32px; 
    width: auto;
    flex-shrink: 0; 
  }
  
  .card { 
    border-radius: 12px;
    margin: 0 10px 16px 10px; 
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  }
  .tabs { padding: 0 10px 10px 10px; gap: 8px; margin-bottom: 10px; }
  .tabbtn { padding: 8px 16px; font-size: 0.85rem; }

  .row, .toolbar { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .toolbar { grid-template-columns: 1fr; }
  .row > div, .toolbar > div { width: 100% !important; margin: 0 !important; }
  
  select, input, button, .btn { width: 100%; min-height: 48px; font-size: 16px; }
  .monthnav { flex-direction: row; justify-content: space-between; width: 100%; }
  
  .weekday { display: none; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .grid .blank { display: none; }
  
  .tile {
    min-height: auto;
    flex-direction: column;
    border-left: 4px solid transparent; 
  }
  .tile:has(.badge.green) { border-left-color: var(--ok); }
  .tile:has(.badge.orange) { border-left-color: var(--warn); }
  .tile:has(.badge.red) { border-left-color: var(--bad); }

  .tile .date {
    background: transparent;
    border-bottom: 1px solid var(--ring);
    padding: 12px;
  }
  .tile .date::before {
    content: "Tarikh: ";
    font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px;
  }
  .tile .body { padding: 12px; }

  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr { 
    margin-bottom: 16px; 
    border: 1px solid var(--ring); 
    border-radius: 12px; 
    background: #fff; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    overflow: hidden;
  }
  td {
    border-bottom: 1px solid #f1f5f9;
    padding: 10px 16px;
    padding-left: 40%; 
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 36px;
  }
  td::before { 
    position: absolute; left: 16px; width: 35%; 
    text-align: left; font-weight: 600; font-size: 0.8rem; 
    color: var(--primary); text-transform: uppercase;
  }
  /* Label jadual (Shared) */
  td:nth-of-type(1)::before { content: "Kol 1"; } /* Default fallback */
  
  /* Overview Table Mobile */
  #ovTableBody td:nth-of-type(1)::before { content: "Tarikh"; }
  #ovTableBody td:nth-of-type(2)::before { content: "Masa"; }
  #ovTableBody td:nth-of-type(3)::before { content: "Bilik"; }
  #ovTableBody td:nth-of-type(4)::before { content: "Tujuan"; }
  #ovTableBody td:nth-of-type(5)::before { content: "Penempah"; }
  #ovTableBody td:nth-of-type(6)::before { content: "Tindakan"; }

  /* Admin List Mobile */
  #adminList td:nth-of-type(1) { padding-left: 16px; background: #f8fafc; justify-content: flex-start; }
  #adminList td:nth-of-type(2)::before { content: "Tarikh"; }
  #adminList td:nth-of-type(3)::before { content: "Masa"; }
  #adminList td:nth-of-type(4)::before { content: "Tujuan"; }
  #adminList td:nth-of-type(5)::before { content: "Penempah"; }
  #adminList td:nth-of-type(6)::before { content: "Edit"; }
  
  /* User List Mobile */
  #adminUserListBody td:nth-of-type(1)::before { content: "Nama"; }
  #adminUserListBody td:nth-of-type(2)::before { content: "Sektor"; }
  #adminUserListBody td:nth-of-type(3)::before { content: "Email"; }
  #adminUserListBody td:nth-of-type(4)::before { content: "Tindakan"; }

  .swal-form { grid-template-columns: 1fr; }
}

/* ========================================= */
/* === CSS TAMBAHAN (Devtest Extension) === */
/* ========================================= */

/* Container Flex di Header */
.header-flex-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.header-title-group {
  display: flex;
  align-items: center;
  gap: 15px;
}

/* Auth Controls (Top Right) */
.auth-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-login {
  background: var(--warn); 
  color: #000; 
  border: none; 
  padding: 6px 14px; 
  border-radius: 8px; 
  font-weight: 600; 
  cursor: pointer; 
  font-family: 'Oswald', sans-serif;
  font-size: 0.9rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: transform 0.1s;
}
.btn-login:active { transform: scale(0.95); }

.user-badge { 
  display: none; 
  align-items: center; 
  gap: 8px; 
  background: rgba(255,255,255,0.15); 
  padding: 4px 12px; 
  border-radius: 50px; 
  border: 1px solid rgba(255,255,255,0.2); 
  cursor: pointer; 
  color: #fff;
  font-size: 0.9rem;
}
.user-badge.active { display: flex; }

.user-role { 
  font-size: 0.7rem; 
  background: rgba(0,0,0,0.3); 
  padding: 2px 6px; 
  border-radius: 4px; 
  text-transform: uppercase; 
  letter-spacing: 0.5px;
}
.user-role.admin { background: var(--bad); }

/* Admin User Section */
.admin-user-section { 
  margin-bottom: 24px; 
  border-bottom: 2px dashed var(--ring); 
  padding-bottom: 20px; 
}
.scrollable-table { 
  overflow-x: auto; 
  max-height: 400px; 
  border: 1px solid var(--ring);
  border-radius: 10px;
}
.btn-reset {
  background: #fff;
  border: 1px solid var(--ring);
  color: var(--text);
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-reset:hover {
  background: var(--bg);
  color: var(--primary);
  border-color: var(--primary);
}

/* Mobile Tweak for Auth Header */
@media (max-width: 768px) {
  .header-flex-container { flex-direction: column; align-items: flex-start; gap: 10px; }
  .auth-controls { margin-left: 0; width: 100%; justify-content: flex-end; margin-top: -30px; } 
  .header-title-group { max-width: 80%; }
}