@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg-dark: #0f1117;
  --bg-card: #181b25;
  --bg-sidebar: #13151f;
  --bg-hover: #1e2133;
  --border: #252836;
  --border-light: #2e3249;
  --text: #e8eaf0;
  --text-muted: #7a7f9a;
  --text-dim: #4a4f6a;
  --accent: #4f8ef7;
  --accent-hover: #3a79e6;
  --accent-soft: rgba(79,142,247,0.12);
  --green: #3ecf8e;
  --green-soft: rgba(62,207,142,0.12);
  --orange: #f7a94f;
  --orange-soft: rgba(247,169,79,0.12);
  --red: #f76f6f;
  --red-soft: rgba(247,111,111,0.12);
  --yellow: #f7d94f;
  --sidebar-width: 240px;
  --header-h: 60px;
  --radius: 10px;
  --shadow: 0 2px 16px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* SIDEBAR */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.sidebar-logo .logo-icon { font-size: 1.6rem; }
.sidebar-logo .logo-text { font-size: 1rem; font-weight: 700; color: var(--text); letter-spacing: 0.02em; }
.sidebar-logo .logo-sub { font-size: 0.7rem; color: var(--text-muted); }

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  padding: 0.75rem 0.75rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item .nav-icon { font-size: 1.1rem; width: 1.4rem; text-align: center; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  background: var(--bg-hover);
}
.user-chip .avatar {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-chip .user-info { flex: 1; min-width: 0; }
.user-chip .user-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .user-role { font-size: 0.7rem; color: var(--text-muted); }
.btn-logout {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1rem; padding: 0.2rem; border-radius: 6px; transition: color 0.15s;
}
.btn-logout:hover { color: var(--red); }

/* MAIN */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  flex-shrink: 0;
}
.topbar-title { font-size: 1.05rem; font-weight: 700; flex: 1; }
.btn-menu { display: none; background: none; border: none; color: var(--text); font-size: 1.4rem; cursor: pointer; padding: 0.25rem; }

#page-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.action-review-panel {
  flex-shrink: 0;
  margin: 1rem 1.5rem 0;
  background: rgba(247,169,79,0.08);
  border: 1px solid rgba(247,169,79,0.35);
  border-radius: 10px;
  overflow: hidden;
}
.action-review-panel[hidden] { display: none; }
.action-review-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid rgba(247,169,79,0.2);
}
.action-review-header > div { flex: 1; min-width: 0; }
.action-review-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}
.action-review-subtitle {
  margin-top: 0.1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.action-review-list {
  display: flex;
  flex-direction: column;
}
.action-review-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(247,169,79,0.14);
}
.action-review-item:first-child { border-top: none; }
.action-review-main { flex: 1; min-width: 0; }
.action-review-name {
  font-size: 0.9rem;
  font-weight: 700;
}
.action-review-meta,
.action-review-error,
.action-review-more {
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.action-review-error { color: var(--orange); }
.action-review-more {
  padding: 0 1rem 0.75rem;
}

.connection-banner {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  z-index: 1000;
  display: none;
  padding: 0.7rem 1rem;
  background: #3a1818;
  border-bottom: 1px solid rgba(247,111,111,0.45);
  color: #ffd7d7;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.connection-banner.is-visible { display: block; }
.connection-banner[data-state="degraded"] {
  background: #3a2a13;
  border-bottom-color: rgba(247,169,79,0.55);
  color: #ffe3bd;
}

/* ── CARDS & STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
}
.stat-card .stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; margin-top: 0.25rem; font-family: 'DM Mono', monospace; }
.stat-card .stat-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem; }
.stat-blue .stat-value { color: var(--accent); }
.stat-green .stat-value { color: var(--green); }
.stat-orange .stat-value { color: var(--orange); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.card-title { font-size: 0.92rem; font-weight: 700; flex: 1; }
.card-body { padding: 1.25rem; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--green); color: #0f1117; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #e55555; }
.btn-ghost { background: var(--bg-hover); color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-light); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
.td-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--accent-soft); color: var(--accent); }
.badge-gray { background: rgba(122,127,154,0.15); color: var(--text-muted); }

/* ── FORMS ── */
.form-row { display: grid; gap: 1rem; margin-bottom: 1rem; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
label.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
select, textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
select option { background: var(--bg-dark); }
textarea { resize: vertical; min-height: 80px; }

/* Search / filter bar */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.filter-bar input, .filter-bar select { max-width: 220px; margin: 0; }
.filter-bar .spacer { flex: 1; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.modal-title { font-size: 1rem; font-weight: 700; flex: 1; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.3rem; cursor: pointer; padding: 0.2rem; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.75rem; justify-content: flex-end; }

/* ── TOAST ── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 0.75rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toastIn 0.25s ease;
  min-width: 220px;
}
@keyframes toastIn {
  from { opacity:0; transform: translateX(20px); }
  to   { opacity:1; transform: none; }
}
.toast.success { border-color: var(--green); }
.toast.success::before { content: '✓'; color: var(--green); font-weight: 800; }
.toast.error { border-color: var(--red); }
.toast.error::before { content: '✕'; color: var(--red); font-weight: 800; }
.toast.info { border-color: var(--accent); }
.toast.info::before { content: 'ℹ'; color: var(--accent); font-weight: 800; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* Checkbox */
input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Drag handle */
.drag-handle {
  cursor: grab;
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 0 0.25rem;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 240px;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.5); }
  .btn-menu { display: block; }
  .connection-banner { left: 0; font-size: 0.82rem; }
  .action-review-panel { margin: 0.75rem 1rem 0; }
  .action-review-header { align-items: flex-start; flex-direction: column; }
  #page-content { padding: 1rem; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select { max-width: none; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { max-width: 100%; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  td, th { padding: 0.6rem 0.75rem; }
}
