:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #2454ff;
  --primary-hover: #1a3fd6;
  --danger: #d92d20;
  --danger-bg: #fef3f2;
  --success: #12805c;
  --success-bg: #ecfdf5;
  --sidebar-bg: #14172b;
  --sidebar-text: #c7cbe0;
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: #262a49;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}
.sidebar-brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #fff;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidebar-nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13.5px;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.06); }
.sidebar-nav a.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); font-weight: 600; }
.sidebar-footer { padding: 12px 20px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); margin-top: 12px; }
.sidebar-footer .staff-name { color: #fff; font-weight: 600; display: block; font-size: 13px; }
.sidebar-footer .staff-role { color: var(--text-muted); font-size: 12px; text-transform: capitalize; }
.sidebar-footer button {
  margin-top: 10px; width: 100%; background: transparent; border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--sidebar-text); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px;
}
.sidebar-footer button:hover { background: rgba(255, 255, 255, 0.06); }

main { flex: 1; padding: 24px 32px; min-width: 0; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 20px; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filters input, .filters select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px; background: var(--surface); color: var(--text);
}
.filters input[type="text"] { min-width: 220px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #eef1ff; color: #29408a; white-space: nowrap;
}
.badge-inactive { background: #f3f4f6; color: #6b7280; }

/* Compact invoice/payment marks are distinct from the operational status. */
.package-billing-badge {
  display: flex; align-items: center; gap: 5px; width: fit-content;
  margin-top: 5px; padding: 2px 6px; border: 1px solid transparent; border-radius: 5px;
  font-family: system-ui, sans-serif; font-size: 11px; line-height: 1.4; font-weight: 600; white-space: nowrap;
}
.package-billing-dot { width: 5px; height: 5px; flex: 0 0 5px; border-radius: 50%; background: currentColor; }
.package-billing-not_invoiced { color: #854d0e; background: #fefce8; border-color: #fde68a; }
.package-billing-unpaid { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.package-billing-part_paid { color: #9a3412; background: #fff7ed; border-color: #fed7aa; }
.package-billing-paid { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.package-billing-needs_review { color: #475569; background: #f1f5f9; border-color: #cbd5e1; }
.package-billing-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12px; margin: 0 0 14px; }
.package-billing-legend .package-billing-badge { display: inline-flex; margin: 0; }

.pagination { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 13px; color: var(--text-muted); }
.pagination button {
  padding: 5px 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: 13px;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn {
  display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.btn:hover { background: #f5f6f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger-bg); border-color: #f4a49c; color: var(--danger); }
.btn-danger:hover { background: #fde3e0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
#verification-confirmation[hidden] { display: none; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.field input, .field select, .field textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px; background: var(--surface); color: var(--text); font-family: inherit;
}
.field .readonly { padding: 7px 0; color: var(--text); font-size: 13.5px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 700; margin: 22px 0 10px; }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item { border-left: 2px solid var(--border); padding: 2px 0 2px 14px; position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline-item .ts { font-size: 12px; color: var(--text-muted); }
.timeline-item .what { font-size: 13.5px; margin-top: 2px; }

.alert { padding: 10px 14px; border-radius: 6px; font-size: 13.5px; margin-bottom: 14px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f4a49c; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a7e3cb; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar-bg); }
.login-card { background: var(--surface); border-radius: 10px; padding: 32px 28px; width: 320px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
.login-card h1 { font-size: 17px; margin: 0 0 4px; }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card button { width: 100%; margin-top: 6px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 18, 33, 0.5); display: none;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: 10px; padding: 22px 24px; width: 420px; max-width: 90vw; }
.modal h2 { font-size: 16px; margin: 0 0 8px; }
.modal p { font-size: 13.5px; color: var(--text-muted); margin: 0 0 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* Staff lifecycle controls stay within their table cell on narrow screens. */
.staff-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 180px; }
.staff-role-select { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fff; }
.global-search { padding: 12px 16px 4px; }
.global-search label { display: block; color: #c8cada; font-size: 12px; margin-bottom: 6px; }
.global-search > div { display: flex; gap: 4px; }
.global-search input { min-width: 0; width: 100%; padding: 9px; border: 1px solid #666a85; border-radius: 6px; background: #fff; color: #202332; }
.global-search button { padding: 6px; border-radius: 6px; cursor: pointer; }
#package-search-form { align-items: end; }
#package-search-form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
#package-search-form .search-query-label { flex: 1; min-width: 240px; }
#package-search-query { width: 100%; box-sizing: border-box; }
#search-results[hidden], #search-error[hidden] { display: none !important; }
