:root {
  /* Kept alongside the palette above (which matches the Annual Leave system)
     for a couple of spots this app needs that Annual Leave doesn't: a
     slightly darker mid-grey for disabled controls / placeholders, and a
     near-black body-text shade. */
  --gray-400: #9aa4b2;
  --gray-800: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--gray-800);
  font-size: 14px;
  line-height: 1.45;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

.muted { color: var(--grey); }

/* ---------- Top bar ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  flex-shrink: 0;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar .brand-logo img { height: 34px; display: block; }
.topbar .brand-title { font-weight: 700; color: var(--navy); font-size: 15px; }
.topbar .brand-subtitle { font-size: 12px; color: var(--grey); }
.topbar .user-block { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.topbar .user-block .role-pill {
  background: var(--blue-light);
  color: var(--navy);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.topbar .user-block span:first-child { color: var(--grey); }

/* ---------- Nav tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  flex-shrink: 0;
  overflow-x: auto;
}
.tabs button {
  border: none;
  background: transparent;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--grey);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tabs button:hover { color: var(--navy); }
.tabs button.active { color: var(--action); border-bottom-color: var(--action); }

main { flex: 1; padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------- Sign-in screen ---------- */
.login-screen {
  flex: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-dark) 100%);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.login-logo { max-width: 160px; max-height: 70px; margin-bottom: 12px; }
.login-card h1 { font-size: 1.1em; margin: 0 0 2px; color: var(--navy); }
.login-card h2 { margin: 18px 0 4px; color: var(--gray-800); }
.login-card p { margin: 0 0 4px; }
.login-card .btn-block { margin-top: 18px; }

/* Kept for the fatal-error screen, which reuses this layout without the card. */
.signin-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  text-align: center;
  padding: 24px;
}
.signin-screen h1 { font-size: 22px; margin: 0; color: var(--navy); }
.signin-screen p { color: var(--grey); max-width: 380px; margin: 0; }

/* ---------- Cards / layout ---------- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 4px; font-size: 16px; color: var(--navy); }
.card .subtle { color: var(--grey); font-size: 12.5px; margin: 0 0 14px; }
.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey);
  margin: 26px 0 10px;
}
.section-title:first-child { margin-top: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.stat-card .stat-value { font-size: 1.7em; font-weight: 700; color: var(--navy); }
.stat-card .stat-label { font-size: 0.82em; color: var(--grey); margin-top: 4px; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  background: var(--grey-light);
  color: #444;
  font-weight: 600;
  padding: 8px 10px;
}
td { padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover td { background: var(--blue-light); }
.empty-row td { color: var(--gray-400); text-align: center; padding: 28px 10px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.badge.Draft { background: var(--grey-light); color: var(--grey); }
.badge.Submitted { background: var(--amber-bg); color: var(--amber); }
.badge.Approved { background: var(--green-bg); color: var(--green); }
.badge.Rejected { background: var(--red-bg); color: var(--red); }
.badge.Ordered { background: var(--blue-light); color: var(--navy); }
.badge.Delivered { background: var(--blue-light); color: var(--navy-dark); }
.badge.Received { background: var(--green-bg); color: var(--green); }
.badge.Cancelled { background: var(--grey-light); color: var(--grey); }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; font-weight: 600; color: var(--grey); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--gray-800);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy); outline-offset: 0; border-color: var(--navy); }
.field { margin-bottom: 14px; }
.field-checkbox label { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; color: var(--gray-800); margin-bottom: 0; }
.field-checkbox input[type="checkbox"] { width: 16px; height: 16px; }
textarea { resize: vertical; min-height: 60px; }

.line-items-table th, .line-items-table td { padding: 6px 6px; }
.line-items-table input { padding: 6px 8px; font-size: 13px; }
.line-items-table td.num-col { width: 110px; }
.line-items-table td.total-col { width: 100px; text-align: right; font-weight: 600; }
.line-items-table td.remove-col { width: 34px; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px;
}

.totals-row { display: flex; justify-content: flex-end; gap: 10px; padding: 10px 0; font-size: 15px; font-weight: 700; color: var(--navy); }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--action); color: #fff; }
.btn-primary:hover { background: var(--action-hover); }
.btn-primary:disabled { background: var(--gray-400); cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--navy); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--grey-light); }
.btn-approve { background: var(--green-bg); color: var(--green); }
.btn-approve:hover { background: #d7eedd; }
.btn-reject { background: var(--red-bg); color: var(--red); }
.btn-reject:hover { background: #f6d9d5; }
.btn-dashed {
  background: #fff;
  border: 1px dashed var(--gray-400);
  color: var(--grey);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-ms {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--action);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-ms:hover { background: var(--action-hover); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 37, 68, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(20, 37, 68, 0.3);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; color: var(--navy); }
.modal-header button { background: transparent; border: none; font-size: 20px; cursor: pointer; color: var(--grey); }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.kv-grid { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 13px; margin-bottom: 16px; }
.kv-grid dt { color: var(--grey); font-weight: 600; }
.kv-grid dd { margin: 0; }

.banner { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.banner.info { background: var(--blue-light); color: var(--navy); }
.banner.error { background: var(--red-bg); color: var(--red); }
.banner.success { background: var(--green-bg); color: var(--green); }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.toolbar .filters { display: flex; gap: 8px; }
.toolbar select { width: auto; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px;
}
.spinner.dark { border-color: var(--blue-light); border-top-color: var(--navy); }
@keyframes spin { to { transform: rotate(360deg); } }

.full-loading {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--grey);
}

@media (max-width: 640px) {
  main { padding: 14px; }
  .topbar { padding: 10px 14px; }
}
