:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2331;
  --text-muted: #6b7280;
  --primary: #3457d5;
  --primary-hover: #2a46b3;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --success: #1c8a4b;
  --success-bg: #e8f7ee;
  --warn: #b5750a;
  --warn-bg: #fdf3df;
  --sidebar-bg: #161b28;
  --sidebar-text: #c4c9d4;
  --sidebar-text-active: #ffffff;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

#app { min-height: 100vh; }

/* --- login --- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 24px;
}

/* --- shell layout --- */

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}

.sidebar h1 {
  font-size: 15px;
  color: #fff;
  margin: 0 12px 20px;
}

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

.sidebar a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13px;
}

.sidebar a:hover { background: rgba(255, 255, 255, 0.06); }
.sidebar a.active { background: var(--primary); color: #fff; }

.sidebar .user-info {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 12px;
}

.sidebar .user-info button {
  margin-top: 8px;
  width: 100%;
}

.main { padding: 28px 32px; overflow-x: auto; }

.main header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.main h2 { margin: 0; font-size: 20px; }

/* --- generic components --- */

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

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
tbody tr:hover { background: #fafbfc; }

/* Truncates long content with an ellipsis instead of stretching the table — pair with a `title`
   attribute on the same element so the full value is still available on hover. display:
   inline-block (not applied directly to a <td>, which auto table-layout can make unreliable) so
   max-width/overflow/text-overflow actually clip regardless of the table's layout algorithm. */
.truncate { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-neutral { background: #eef0f3; color: var(--text-muted); }

button, .btn {
  font: inherit;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--primary-hover); }
button.secondary, .btn.secondary { background: #eef0f3; color: var(--text); }
button.secondary:hover, .btn.secondary:hover { background: #e2e5ea; }
button.danger, .btn.danger { background: var(--danger); }
button.danger:hover, .btn.danger:hover { background: #b93a3a; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }

.error-text { color: var(--danger); font-size: 13px; margin: 8px 0; }
.success-text { color: var(--success); font-size: 13px; margin: 8px 0; }
.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

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

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 18, 26, 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal {
  background: #fff; border-radius: var(--radius); padding: 24px; width: 420px; max-width: 90vw;
  max-height: 85vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }
