:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --border: #E1E4E9;
  --ink: #1C2430;
  --ink-soft: #5B6472;
  --teal: #0F6B5C;
  --teal-dark: #0B5245;
  --teal-tint: #E5F1EE;
  --amber: #B9762C;
  --amber-tint: #FBF0DE;
  --red: #AE4038;
  --red-tint: #FBE9E7;
  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,36,48,0.04), 0 4px 12px rgba(28,36,48,0.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #12241F 0%, #0B5245 55%, #0F6B5C 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}
.login-brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.01em;
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.login-card p.sub {
  color: var(--ink-soft);
  margin: 0 0 28px;
  font-size: 13.5px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FBFBFC;
  transition: border-color 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--teal);
  background: white;
}
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14.5px;
  margin-top: 6px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--teal-dark); }
.login-error {
  background: var(--red-tint);
  color: var(--red);
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.demo-creds {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.9;
}
.demo-creds b { color: var(--ink); font-family: var(--font-mono); font-weight: 500; }
.demo-creds .role-tag {
  display: inline-block;
  font-weight: 600;
  color: var(--teal-dark);
  width: 60px;
}

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  background: #12211D;
  color: #E8EDEB;
  flex-shrink: 0;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 6px 22px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand-mark {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  color: white;
}
.sidebar-brand-name { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #C7D3CF;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.active { background: var(--teal); color: white; }
.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6E8580;
  margin: 18px 12px 8px;
  font-weight: 600;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user { padding: 8px 12px; font-size: 12.5px; color: #9FB0AB; }
.sidebar-user b { color: white; display: block; font-size: 13.5px; margin-bottom: 2px; }
.logout-btn {
  width: 100%;
  text-align: left;
  background: none; border: none;
  color: #C7D3CF; padding: 9px 12px;
  border-radius: 8px; font-size: 13px;
  margin-top: 4px;
}
.logout-btn:hover { background: rgba(255,255,255,0.06); color: white; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar-sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-user-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 14px 6px 6px;
  background: linear-gradient(135deg, #FAFBFC 0%, #F3F5F7 100%);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(28,36,48,0.04);
  max-width: 320px;
}
.topbar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(15,107,92,0.25);
}
.topbar-user-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.topbar-user-email {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  line-height: 1.2;
}
.topbar-role-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.topbar-role-badge.role-admin {
  background: var(--teal-tint);
  color: var(--teal-dark);
}
.topbar-role-badge.role-manager {
  background: var(--amber-tint);
  color: var(--amber);
}
.topbar-role-badge.role-staff {
  background: #E8EDF5;
  color: #4A5D7A;
}
.topbar-signout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.topbar-signout:hover {
  background: #FEF7F6;
  color: var(--red);
  border-color: #F0C9C5;
  box-shadow: 0 1px 3px rgba(174,64,56,0.08);
}
.topbar-signout svg { flex-shrink: 0; opacity: 0.75; }
.topbar-signout:hover svg { opacity: 1; }
.content { padding: 24px 28px; flex: 1; overflow-y: auto; }

/* ---------- Cards / stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .num {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--teal-dark);
}
.stat-card .label { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.panel-header h2 { font-family: var(--font-display); font-size: 16.5px; font-weight: 600; margin: 0; }
.panel-body { padding: 16px 20px; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--ink-soft);
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
td { padding: 12px 14px; border-bottom: 1px solid #F0F1F3; font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: #FAFBFC; cursor: pointer; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.badge-active { background: var(--teal-tint); color: var(--teal-dark); }
.badge-leave { background: var(--amber-tint); color: var(--amber); }
.badge-valid { background: var(--teal-tint); color: var(--teal-dark); }
.badge-expiring { background: var(--amber-tint); color: var(--amber); }
.badge-expired { background: var(--red-tint); color: var(--red); }
.badge-pending { background: var(--amber-tint); color: var(--amber); }
.badge-approved { background: var(--teal-tint); color: var(--teal-dark); }
.badge-rejected { background: var(--red-tint); color: var(--red); }

.search-bar {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px;
}
.search-bar input, .search-bar select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #FBFBFC; font-size: 13.5px;
}
.search-bar input { flex: 1; min-width: 180px; }

.btn-sm {
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--border);
  background: white; font-size: 12.5px; font-weight: 600; color: var(--ink);
}
.btn-sm:hover { background: #F5F6F8; }
.btn-sm.teal { background: var(--teal); color: white; border-color: var(--teal); }
.btn-sm.teal:hover { background: var(--teal-dark); }

.pagination { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 14px 20px; }
.pagination span { font-size: 12.5px; color: var(--ink-soft); }

/* Profile view */
.profile-header {
  display: flex; align-items: center; gap: 16px; margin-bottom: 20px;
}
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--teal); color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 20px; font-weight: 600;
}
.profile-header h2 { font-family: var(--font-display); font-size: 20px; margin: 0; }
.profile-header .role { color: var(--ink-soft); font-size: 13.5px; margin-top: 2px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  padding: 10px 4px; margin-right: 20px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-soft); border-bottom: 2px solid transparent; cursor: pointer;
}
.tab.active { color: var(--teal-dark); border-color: var(--teal); }

.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr));
  gap: 16px;
}
.detail-item .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); margin-bottom: 3px; }
.detail-item .v { font-size: 14px; font-weight: 500; }

.cert-num { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-soft); }

.empty-state {
  text-align: center; padding: 40px 20px; color: var(--ink-soft); font-size: 13.5px;
}

.loading { text-align: center; padding: 40px; color: var(--ink-soft); }

/* Ribbon signature element for expiring/expired items on profile */
.ribbon-card {
  position: relative;
  overflow: hidden;
}
.ribbon-card::before {
  content: attr(data-ribbon);
  position: absolute;
  top: 11px; right: -30px;
  background: var(--amber);
  color: white;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 34px;
  transform: rotate(45deg);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.ribbon-card[data-ribbon="EXPIRED"]::before { background: var(--red); }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 20; height: 100vh; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; flex-wrap: wrap; gap: 12px; }
  .topbar-user-card { max-width: 180px; padding-right: 10px; }
  .topbar-user-email { max-width: 110px; font-size: 11.5px; }
  .topbar-signout span { display: none; }
  .topbar-signout { padding: 8px 10px; }
  .mobile-menu-btn { display: inline-flex !important; }
}
.mobile-menu-btn {
  display: none;
  background: none; border: none; font-size: 20px; margin-right: 10px;
}
