*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --matcha-50: #F4F8EE;
  --matcha-100: #E8F1DD;
  --matcha-200: #DDE8C9;
  --matcha-300: #C5D9A6;
  --matcha-400: #A8C883;
  --matcha-500: #8FBF6A;
  --matcha-600: #7AB055;
  --matcha-700: #5F8D4E;
  --matcha-800: #4A6E3D;
  --matcha-900: #35502C;
  --cream: #FAF8EF;
  --cream-50: #FEFDFA;
  --cream-100: #FCFAF2;
  --cream-200: #FAF8EF;
  --cream-300: #F4F1DE;
  --ink-50: #E8EDE8;
  --ink-100: #C5CFC6;
  --ink-200: #9EAD9F;
  --ink-300: #778C78;
  --ink-400: #58735A;
  --ink-500: #3A5A3C;
  --ink-600: #304E32;
  --ink-700: #243025;
  --ink-800: #1A231B;
  --ink-900: #0F1510;
  --amber-50: #FFFBEB;
  --amber-100: #FEF3C7;
  --amber-200: #FDE68A;
  --amber-300: #FCD34D;
  --amber-400: #FBBF24;
  --amber-500: #F59E0B;
  --amber-600: #D97706;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(36, 48, 37, 0.04);
  --shadow: 0 1px 3px rgba(36, 48, 37, 0.06), 0 1px 2px rgba(36, 48, 37, 0.04);
  --shadow-card: 0 1px 3px rgba(36, 48, 37, 0.05), 0 0 0 1px rgba(143, 191, 106, 0.12);
  --shadow-btn: 2px 2px 0 #243025;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--cream);
  color: var(--ink-700);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--ink-700);
  color: #fff;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 8px;
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--matcha-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  color: #fff;
}

.sidebar-brand-sub {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--ink-200);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
  flex: 1;
}

.sidebar-nav-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-300);
  padding: 12px 16px 4px;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-200);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-btn::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-400);
  flex-shrink: 0;
  transition: background 0.15s;
}

.sidebar-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-btn:hover::before {
  background: var(--matcha-400);
}

.sidebar-btn:focus-visible {
  outline: 2px solid var(--matcha-500);
  outline-offset: -2px;
}

.sidebar-btn.active {
  background: rgba(143, 191, 106, 0.15);
  color: #fff;
}

.sidebar-btn.active::before {
  background: var(--matcha-500);
  box-shadow: 0 0 6px rgba(143, 191, 106, 0.5);
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.65rem;
  color: var(--ink-400);
  letter-spacing: 0.03em;
}

.page-shell {
  flex: 1;
  min-width: 0;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ---- Typography ---- */

.eyebrow {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--matcha-600);
  margin-bottom: 2px;
}

.subtitle {
  color: var(--ink-400);
  font-size: 0.925rem;
  max-width: 56ch;
  margin-top: 4px;
}

.muted {
  color: var(--ink-300);
  font-size: 0.825rem;
}

.text-body {
  color: var(--ink-600);
}

/* ---- Header ---- */

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

.dashboard-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink-700);
}

/* ---- Overall panel ---- */

.overall-panel {
  background: #fff;
  border: 1px solid var(--matcha-200);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 200px;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.panel-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-400);
  margin-bottom: 6px;
}

.overall-status {
  font-size: 1.25rem;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 4px;
  display: inline-block;
}

/* ---- Notification banner ---- */

.notification-banner {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 16px;
}

.notification-banner[hidden] {
  display: none;
}

.notification-banner.notification-info {
  background: var(--matcha-50);
  color: var(--matcha-700);
  border: 1px solid var(--matcha-200);
}

.notification-banner.notification-error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fecaca;
}

/* ---- Signal grid ---- */

.signal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  align-items: stretch;
}

/* ---- Signal card ---- */

.signal-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--matcha-200);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.card-heading {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-heading .status-pill {
  margin-left: auto;
  flex-shrink: 0;
}

.card-heading h2 {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--ink-600);
}

/* ---- Status pills ---- */

.status-pill {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-good {
  background: var(--matcha-100);
  color: var(--matcha-700);
}

.status-warning {
  background: var(--amber-100);
  color: var(--amber-600);
}

.status-critical {
  background: var(--red-bg);
  color: var(--red);
}

/* Keep legacy classes for compatibility with server-rendered content */
.status-green {
  background: var(--matcha-100);
  color: var(--matcha-700);
}

.status-yellow {
  background: var(--amber-100);
  color: var(--amber-600);
}

.status-red {
  background: var(--red-bg);
  color: var(--red);
}

/* ---- Status chip (table) ---- */

.status-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  text-transform: uppercase;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* ---- Metric display ---- */

.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink-700);
  margin-bottom: 2px;
}

#estimated-runtime-value {
  font-size: 3rem;
  font-weight: 800;
}

.metric-label {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink-400);
  line-height: 1.6;
  text-align: right;
  padding-right: 4px;
}
#battery-health-value strong,
#engine-health-value strong {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-700);
  line-height: 1.6;
}
.metric-line strong {
  font-weight: 700;
  color: var(--ink-700);
}

.metric-meta {
  font-size: 0.825rem;
  color: var(--ink-400);
  margin-top: auto;
  padding-top: 8px;
}

/* ---- Detail panel ---- */

.detail-panel {
  background: #fff;
  border: 1px solid var(--matcha-200);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink-700);
}

/* ---- Usage details (DL grid) ---- */

.usage-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.usage-details div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.usage-details dt {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-300);
}

.usage-details dd {
  font-size: 0.925rem;
  color: var(--ink-600);
}

/* ---- Table ---- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: var(--matcha-50);
  border-bottom: 2px solid var(--matcha-300);
}

th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--matcha-700);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--matcha-200);
  color: var(--ink-600);
}

tbody tr {
  background: var(--cream-100);
}

tbody tr:hover {
  background: var(--matcha-50);
}

.empty-state {
  text-align: center;
  color: var(--ink-300);
  padding: 24px 12px !important;
  font-style: italic;
}

/* ---- Pagination ---- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  row-gap: 8px;
}

.pagination button {
  padding: 6px 16px;
  font-size: 0.825rem;
  font-weight: 500;
  border: 1px solid var(--matcha-700);
  border-radius: var(--radius-sm);
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-btn);
}

.pagination button:hover:not(:disabled) {
  background: var(--matcha-700);
}

.pagination button:active:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--matcha-700);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---- History grid (split layout) ---- */

.history-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ---- History dot grid ---- */

.history-dot-grid {
  display: grid;
  grid-template-columns: repeat(var(--history-dot-count, 20), minmax(0, 1fr));
  gap: 3px;
  margin-top: 12px;
  padding: 4px;
  background: var(--matcha-50);
  border-radius: 6px;
  overflow-x: hidden;
}

.history-dot {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  padding: 0;
  margin: 0;
  background: var(--matcha-200);
  transition: transform 0.1s, box-shadow 0.1s;
  flex-shrink: 0;
}

.history-dot:hover {
  transform: scale(1.4);
  box-shadow: 0 0 0 2px rgba(95, 141, 78, 0.4);
}

.history-dot:focus-visible {
  outline: 2px solid var(--matcha-700);
  outline-offset: 1px;
}

.history-dot-empty-slot {
  aspect-ratio: 1;
  border-radius: 50%;
  background: transparent;
  border: 1px dashed var(--matcha-200);
}

.dot-good {
  background: var(--matcha-500);
}

.dot-warning {
  background: var(--amber-400);
}

.dot-critical {
  background: #ef4444;
}

.history-dots-empty {
  font-size: 0.8rem;
  color: var(--ink-300);
  font-style: italic;
  margin: 8px 0 2px;
}

.history-dots-label {
  font-size: 11px;
  color: var(--ink-300);
  margin-top: 4px;
}

/* ---- Icon-only button ---- */

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-700);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.15s;
}

.icon-button:hover {
  background: var(--cream-200);
}

.icon-button:focus-visible {
  outline: 2px solid var(--matcha-500);
  outline-offset: 1px;
}

/* ---- Detail views ---- */

.detail-view {
  animation: fadeIn 0.15s ease;
}

.detail-view[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.detail-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink-700);
}

.detail-back {
  padding: 6px 14px;
  font-size: 0.825rem;
  font-weight: 500;
  border: 1px solid var(--matcha-700);
  border-radius: var(--radius-sm);
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-btn);
}

.detail-back:hover {
  background: var(--matcha-700);
}

.detail-back:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.detail-card {
  background: #fff;
  border: 1px solid var(--matcha-200);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.detail-card h3 {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--matcha-700);
  margin-bottom: 12px;
}

/* ---- Field list ---- */

.field-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.field-list .field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--matcha-50);
}

.field-list .field-label {
  font-size: 0.725rem;
  font-weight: 600;
  color: var(--ink-300);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.field-list .field-value {
  font-size: 0.875rem;
  color: var(--ink-600);
  text-align: right;
  word-break: break-word;
}

/* ---- Evidence list ---- */

.evidence-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.evidence-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--cream-100);
  border: 1px solid var(--matcha-200);
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  word-break: break-all;
}

.evidence-download {
  padding: 4px 12px;
  font-size: 0.775rem;
  font-weight: 500;
  border: 1px solid var(--matcha-700);
  border-radius: var(--radius-sm);
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s;
}

.evidence-download:hover {
  background: var(--matcha-700);
}

/* ---- Modal ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 21, 16, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(36, 48, 37, 0.2);
  max-width: 480px;
  width: calc(100% - 32px);
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--matcha-200);
}

.modal-header {
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-700);
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--matcha-100);
}

.modal-close {
  padding: 8px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--matcha-700);
  border-radius: var(--radius-sm);
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-close:hover {
  background: var(--matcha-700);
}

.modal-link-btn {
  padding: 8px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--matcha-700);
  border-radius: var(--radius-sm);
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-btn);
}

.modal-link-btn:hover {
  background: var(--matcha-700);
}

.modal-loading {
  text-align: center;
  color: var(--ink-300);
  font-style: italic;
  padding: 20px 0;
}

/* ---- Responsive ---- */

@media (max-width: 800px) {
  .history-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 16px 12px 32px;
  }

  .dashboard-header {
    flex-direction: column;
  }

  .overall-panel {
    width: 100%;
  }

  .usage-details {
    grid-template-columns: 1fr 1fr;
  }

  .signal-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .procurement-summary-grid {
    grid-template-columns: 1fr;
  }

  .procurement-year-select {
    max-width: 100%;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .procurement-chart-wrap {
    height: 240px;
  }

  .procurement-chart-panel {
    padding: 16px;
  }

  .modal-panel {
    width: calc(100% - 16px);
    padding: 16px;
  }

  .login-overlay {
    padding: 16px;
  }

  .login-card {
    padding: 24px 20px;
  }

  .login-input,
  .login-submit {
    min-height: 44px;
  }

  .login-brand-text,
  .login-title {
    overflow-wrap: break-word;
    word-break: break-word;
  }

  /* R6: action buttons tappable on mobile */
  #procurement-list-content .icon-button,
  #pending-approvals-section .icon-button,
  #pending-approvals-section .approval-approve-btn,
  #pending-approvals-section .approval-reject-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* R8: type breakdown responsive */
  #type-breakdown-section {
    width: 100%;
  }

  #type-breakdown-section table {
    min-width: 280px;
  }
}

@media (max-width: 480px) {
  .usage-details {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px), (max-height: 560px) {
  .login-overlay {
    align-items: flex-start;
  }
}

/* ---- Dot popup ---- */
.dot-popup {
  position: fixed;
  z-index: 1000;
  background: #fff;
  border: 1px solid var(--matcha-200);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(36, 48, 37, 0.12);
  font-size: 0.8rem;
  min-width: 220px;
  pointer-events: none;
}
.popup-date {
  font-weight: 600;
  color: var(--ink-700);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--matcha-100);
}
.popup-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  gap: 12px;
}
.popup-label { color: var(--ink-400); }
.popup-value { font-weight: 500; color: var(--ink-600); text-align: right; }

/* ---- Procurement dashboard ---- */

.procurement-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.procurement-summary-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink-700);
}

.procurement-year-select {
  padding: 6px 32px 6px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-700);
  background: #fff;
  border: 1px solid var(--matcha-300);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%2712%27 height=%2712%27 viewBox=%270 0 12 12%27%3E%3Cpath fill=%27%2358735A%27 d=%27M6 8L1 3h10z%27/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.procurement-year-select:hover {
  border-color: var(--matcha-500);
}

.procurement-year-select:focus-visible {
  outline: 2px solid var(--matcha-500);
  outline-offset: 1px;
}

.procurement-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.procurement-summary-error {
  font-size: 0.75rem;
  padding: 4px 0;
}

.procurement-chart-panel {
  margin-top: 20px;
}

.procurement-chart-wrap {
  position: relative;
  height: 300px;
  overflow: hidden;
}

.procurement-cost-cell {
  white-space: nowrap;
}

.procurement-action-button {
  border-color: transparent;
  background: transparent;
  color: var(--ink-600);
  box-shadow: none;
}

.procurement-action-button:hover {
  background: transparent;
  color: var(--matcha-700);
}

/* ---- Procurement table horizontal scroll (R6) ---- */

#procurement-list-content table,
#pending-approvals-section table {
  min-width: 600px;
}

/* Keep date, priority, cost, action cells from wrapping awkwardly */
#procurement-list-content td:nth-child(2),
#procurement-list-content td:nth-child(4),
#procurement-list-content td:nth-child(6),
#procurement-list-content td:nth-child(7),
#pending-approvals-section td:nth-child(2),
#pending-approvals-section td:nth-child(4),
#pending-approvals-section td:nth-child(6),
#pending-approvals-section td:nth-child(7) {
  white-space: nowrap;
}

/* Allow longer requester and type text to wrap */
#procurement-list-content td:nth-child(3),
#procurement-list-content td:nth-child(5),
#pending-approvals-section td:nth-child(3),
#pending-approvals-section td:nth-child(5) {
  white-space: normal;
  word-break: break-word;
}

/* R8: type breakdown table — allow type labels to wrap, keep spend/count tight */
#type-breakdown-section td:first-child {
  white-space: normal;
  word-break: break-word;
}

#type-breakdown-section td:nth-child(3) {
  white-space: nowrap;
}

/* ---- Evidence grid ---- */
.evidence-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 12px;
}
.evidence-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.evidence-thumb {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--matcha-200);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.evidence-thumb:hover {
  transform: scale(1.05);
  border-color: var(--matcha-400);
}
.evidence-file-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 140px;
  background: var(--matcha-50);
  border: 1px solid var(--matcha-200);
  border-radius: 8px;
  color: var(--matcha-500);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.evidence-file-placeholder:hover {
  border-color: var(--matcha-400);
}
.evidence-name {
  font-size: 0.75rem;
  color: var(--ink-500);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* ---- Evidence preview ---- */
.preview-panel {
  background: #fff;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-header, .preview-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--matcha-50);
}
.preview-header { border-bottom: 1px solid var(--matcha-200); font-weight: 600; color: var(--ink-700); }
.preview-footer { border-top: 1px solid var(--matcha-200); font-size: 0.8rem; }
.preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}
.preview-body img {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
}

/* ---- Login ---- */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  overflow-y: auto;
}

.login-overlay[hidden] {
  display: none;
}

.login-card {
  background: #fff;
  border: 1px solid var(--matcha-200);
  border-radius: 12px;
  padding: 36px 32px;
  max-width: 400px;
  width: calc(100% - 32px);
  box-shadow: 0 4px 24px rgba(36, 48, 37, 0.08);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--matcha-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.login-brand-text {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink-700);
  line-height: 1.2;
}

.login-brand-sub {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--ink-300);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink-700);
  margin-bottom: 20px;
}

.login-field {
  display: block;
  margin-bottom: 14px;
}

.login-field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-500);
  margin-bottom: 4px;
}

.login-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.9rem;
  border: 1px solid var(--matcha-200);
  border-radius: var(--radius-sm);
  background: var(--cream-50);
  color: var(--ink-700);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-input:focus {
  border-color: var(--matcha-500);
  box-shadow: 0 0 0 3px rgba(143, 191, 106, 0.15);
}

.login-error {
  font-size: 0.8rem;
  color: var(--red);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--red-bg);
  border-radius: var(--radius-sm);
}

.login-error[hidden] {
  display: none;
}

.login-submit {
  width: 100%;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--matcha-700);
  border-radius: var(--radius-sm);
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-btn);
  margin-top: 4px;
}

.login-submit:hover {
  background: var(--matcha-700);
}

.login-submit:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

.login-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ---- Logout ---- */

#sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.65rem;
  color: var(--ink-400);
  letter-spacing: 0.03em;
}

.logout-btn {
  padding: 6px 14px;
  font-size: 0.7rem;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-200);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.logout-btn:hover {
  background: rgba(220, 38, 38, 0.15);
  color: #f87171;
}

.logout-btn[hidden] {
  display: none;
}

/* ---- Approval ---- */

.approval-card-urgent {
  border-color: var(--amber-400);
  box-shadow: 0 1px 3px rgba(251, 191, 36, 0.08), 0 0 0 1px rgba(251, 191, 36, 0.15);
}

.approval-status-chip {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.approval-status-submitted {
  background: var(--amber-100);
  color: var(--amber-600);
}

.approval-status-approved {
  background: var(--matcha-100);
  color: var(--matcha-700);
}

.approval-status-rejected {
  background: var(--red-bg);
  color: var(--red);
}

.approval-approve-btn {
  padding: 4px 12px;
  font-size: 0.725rem;
  font-weight: 600;
  border: 1px solid var(--matcha-700);
  border-radius: 9999px;
  background: var(--matcha-600);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  margin-right: 4px;
}

.approval-approve-btn:hover:not(:disabled) {
  background: var(--matcha-700);
}

.approval-approve-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.approval-reject-btn {
  padding: 4px 12px;
  font-size: 0.725rem;
  font-weight: 600;
  border: 1px solid #ef4444;
  border-radius: 9999px;
  background: transparent;
  color: #ef4444;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.approval-reject-btn:hover:not(:disabled) {
  background: #fef2f2;
}

.approval-reject-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.approval-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

.approval-action-error {
  font-size: 0.75rem;
  color: var(--red);
  margin-top: 4px;
}

.approval-action-error[hidden] {
  display: none;
}

#pending-approvals-section .pagination {
  margin-top: 12px;
}

/* ---- Mobile header ---- */

.mobile-header {
  display: none;
}

.mobile-menu-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 21, 16, 0.5);
  z-index: 500;
}

.sidebar-backdrop[hidden] {
  display: none;
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: var(--ink-700);
    padding: 0 12px;
    z-index: 600;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    z-index: 550;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop:not([hidden]) {
    display: block;
  }

  .page-shell {
    padding-top: 72px;
  }
}
