:root {
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --sidebar-bg: #fbfbfc;
  --sidebar-text: #5b6472;
  --sidebar-text-active: #1a1d23;
  --sidebar-hover: #f0f1f4;
  --sidebar-active-bg: var(--accent-soft);
  --sidebar-border: #e8e9ed;
  --border: #e2e4e9;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-faint: #9aa0ab;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --input-border: #d7dae0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.06);
  --sidebar-width: 236px;
  --icon-eye: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M1 12s4-7 11-7 11 7 11 7-4 7-11 7-11-7-11-7z' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='12' cy='12' r='3' stroke='%23000' stroke-width='2'/%3E%3C/svg%3E");
  --icon-eye-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M17.94 17.94A10.94 10.94 0 0112 19c-7 0-11-7-11-7a20.6 20.6 0 015.06-5.94M9.9 4.24A10.4 10.4 0 0112 4c7 0 11 7 11 7a20.6 20.6 0 01-2.47 3.41M14.12 14.12a3 3 0 11-4.24-4.24' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M1 1l22 22' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

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

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

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }

.container { padding: 24px 28px 40px; max-width: 1100px; margin: 0 auto; width: 100%; }

.page.hidden { display: none !important; }

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 14px;
}

.logo-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.logo-mark svg { width: 100%; height: 100%; }
.logo-mark img { width: 100%; height: 100%; object-fit: contain; border-radius: 7px; }

.brand-text { min-width: 0; }
.brand-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub { font-size: 11px; color: var(--sidebar-text); margin-top: 1px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--sidebar-text);
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  margin-top: 0;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--text); }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--accent); }
.nav-item.active svg { color: var(--accent); }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 14px;
  margin-top: 14px;
}

.who-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 10px;
}

.who-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-footer .who { color: var(--text); font-size: 12.5px; font-weight: 500; }
.sidebar-footer button { width: 100%; margin-top: 0; }

/* ---------- Cards ---------- */

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

.card h2 { font-size: 13.5px; margin: 0 0 14px; font-weight: 700; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin: 8px 0 4px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  margin-top: 10px;
  transition: background 0.12s ease, transform 0.04s ease;
}
button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }
button.secondary { background: #fff; color: var(--text); border-color: var(--input-border); }
button.secondary:hover { background: #f3f4f6; }
button.danger { background: #fff; color: var(--danger); border-color: #f3c9c9; }
button.danger:hover { background: var(--danger-soft); }
button.small { padding: 5px 10px; font-size: 12px; margin-top: 0; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 520px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; background: #f9fafb; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.02em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f9fafb; }
td:nth-child(2) { white-space: normal; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: #ecfdf5; color: var(--success); }
.badge.expired { background: var(--warn-soft); color: var(--warn); }
.badge.revoked { background: var(--danger-soft); color: var(--danger); }
.badge.superseded { background: #f1f5f9; color: var(--text-faint); }

.muted { color: var(--text-faint); font-size: 12px; font-weight: 400; }
.error { color: var(--danger); font-size: 12.5px; margin-top: 8px; }
.success-msg { color: var(--success); font-size: 12.5px; margin-top: 8px; }

.token-box {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  word-break: break-all;
  font-size: 13px;
  flex: 1;
}

.token-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.token-row button {
  flex-shrink: 0;
}

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

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-card { width: 340px; box-shadow: var(--shadow-md); }
.login-card h2 { font-size: 15px; margin: 0 0 4px; font-weight: 700; }

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 16px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.login-brand .logo-mark { width: 40px; height: 40px; }
.login-brand-name { font-size: 14px; font-weight: 700; }

.hidden { display: none !important; }
.back-link { color: var(--accent); cursor: pointer; font-size: 15px; font-weight: 700; }
.back-link:hover { text-decoration: underline; }

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

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    gap: 14px;
  }
  .brand { border-bottom: none; margin-bottom: 0; padding: 0; }
  .nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .nav-item span { display: none; }
  .sidebar-footer { border-top: none; margin-top: 0; padding-top: 0; display: flex; align-items: center; }
  .who-box { padding: 0; }
  .sidebar-footer .who { display: none; }
  .sidebar-footer button { width: auto; }
  .container { padding: 18px 16px 32px; }
  .topbar { padding: 14px 16px; }
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-card { width: 340px; box-shadow: var(--shadow-md); margin: 0; }
.modal-card h2 { font-size: 14.5px; }

.btn-row-end {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.btn-row-end button { margin-top: 0; }

/* ---------- Password field with eye toggle ---------- */

.password-field { position: relative; }
.password-field input { padding-right: 38px; }

.eye-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.eye-toggle:hover { background: #f0f1f4; color: var(--text-muted); }

.eye-toggle::before {
  content: '';
  width: 18px;
  height: 18px;
  display: block;
  background-color: currentColor;
  -webkit-mask: var(--icon-eye) center / contain no-repeat;
  mask: var(--icon-eye) center / contain no-repeat;
}
.eye-toggle.showing::before {
  -webkit-mask-image: var(--icon-eye-off);
  mask-image: var(--icon-eye-off);
}

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

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.pagination:empty { display: none; }
.pagination .page-info { font-size: 12px; color: var(--text-faint); }
.pagination .page-btns { display: flex; gap: 6px; }
.pagination button.small { margin-top: 0; }
.pagination button.small:disabled { opacity: 0.4; cursor: not-allowed; }
