/* ============================================================
   UI Generator — application stylesheet
   Light + dark theme via html[data-theme], vanilla CSS only.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-active: #1d4ed8;
  --primary-soft: rgba(59, 130, 246, 0.12);
  --on-primary: #ffffff;

  --bg: #f3f5f9;
  --bg-soft: #eceff4;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef1f6;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --info: #0284c7;
  --info-soft: rgba(2, 132, 199, 0.12);

  --sidebar-bg: #0f1e33;
  --sidebar-bg-2: #16283f;
  --sidebar-text: #c3cfdf;
  --sidebar-text-dim: #7d8ea8;
  --sidebar-active-bg: rgba(59, 130, 246, 0.18);
  --sidebar-active-text: #ffffff;
  --sidebar-border: rgba(255, 255, 255, 0.08);

  --topbar-bg: rgba(255, 255, 255, 0.9);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --sidebar-width: 264px;
  --sidebar-collapsed-width: 78px;
  --topbar-height: 64px;

  --input-bg: #ffffff;
  --viewer-stage-bg: #0f172a;
  --code-bg: #f1f5f9;

  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

html[data-theme="dark"] {
  --bg: #0d1420;
  --bg-soft: #111a29;
  --surface: #151f31;
  --surface-2: #1a2539;
  --surface-3: #212d45;

  --border: #263449;
  --border-strong: #35486a;

  --text: #e6ecf5;
  --text-muted: #9aa9c2;
  --text-faint: #64748f;

  --primary: #5b97f7;
  --primary-hover: #7cabf9;
  --primary-active: #9dc0fa;
  --primary-soft: rgba(91, 151, 247, 0.16);

  --sidebar-bg: #0b1220;
  --sidebar-bg-2: #111a2c;

  --topbar-bg: rgba(21, 31, 49, 0.9);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);

  --input-bg: #1a2539;
  --viewer-stage-bg: #05090f;
  --code-bg: #1a2539;

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.14);
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5em;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.55rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 0.75em; }

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

img { max-width: 100%; }

button { font-family: inherit; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

::selection {
  background: var(--primary);
  color: #fff;
}

/* ---------- App shell ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}

body.sidebar-collapsed .main {
  margin-left: var(--sidebar-collapsed-width);
}

.content {
  flex: 1;
  padding: 26px 30px 48px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.content-wide {
  max-width: 1500px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-head h1 .fa-solid,
.page-head h1 .fa-regular {
  color: var(--primary);
  font-size: 1.25rem;
}

.page-sub {
  color: var(--text-muted);
  margin: 6px 0 0;
  font-size: 0.92rem;
}

.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: width 0.2s ease, transform 0.25s ease;
  border-right: 1px solid var(--sidebar-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: var(--topbar-height);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.brand-text {
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}

.brand-text strong {
  display: block;
  color: #fff;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 0.72rem;
  color: var(--sidebar-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 20px;
}

.nav-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-text-dim);
  padding: 14px 12px 7px;
  white-space: nowrap;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.92rem;
  margin-bottom: 2px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  box-shadow: inset 2px 0 0 var(--primary);
}

.nav-link .nav-icon {
  width: 22px;
  text-align: center;
  font-size: 0.95rem;
  flex-shrink: 0;
  opacity: 0.9;
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: 9px;
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
}

.sidebar-user-meta {
  min-width: 0;
  line-height: 1.3;
}

.sidebar-user-meta strong {
  display: block;
  color: #fff;
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-meta span {
  font-size: 0.74rem;
  color: var(--sidebar-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* Collapsed sidebar (desktop) */
body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .brand {
  padding: 18px 0 16px;
  justify-content: center;
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-link .nav-text,
body.sidebar-collapsed .sidebar-user-meta {
  display: none;
}

body.sidebar-collapsed .nav-link {
  justify-content: center;
  padding: 10px 0;
}

body.sidebar-collapsed .sidebar-user {
  justify-content: center;
  padding: 8px 0;
}

.sidebar-overlay {
  display: none;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
}

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer { flex: 1; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}

.hamburger { display: none; }
.collapse-btn { display: inline-flex; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  cursor: pointer;
  color: var(--text);
  max-width: 230px;
}

.user-chip:hover { border-color: var(--border-strong); }

.user-chip .avatar { width: 28px; height: 28px; font-size: 0.7rem; }

.user-chip span {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 80;
}

.dropdown.open .dropdown-menu { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 7px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
}

.dropdown-item:hover {
  background: var(--surface-3);
  text-decoration: none;
}

.dropdown-item.danger { color: var(--danger); }
.dropdown-item .fa-solid { width: 18px; text-align: center; opacity: 0.8; }

.dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

.dropdown-head {
  padding: 8px 11px;
  line-height: 1.35;
}

.dropdown-head strong { display: block; font-size: 0.88rem; }
.dropdown-head span { font-size: 0.78rem; color: var(--text-muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-pad { padding: 22px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.card-head h2, .card-head h3 { margin: 0; }

.card-body { padding: 22px; }
.card-body.flush { padding: 0; }

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 26px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-soft); color: var(--primary); }
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-icon.cyan { background: var(--info-soft); color: var(--info); }

.stat-meta strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-meta span {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------- Project cards ---------- */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 16px;
  flex-wrap: wrap;
}

.section-title h2 { margin: 0; }

.project-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.project-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

.project-cover {
  height: 150px;
  background: var(--surface-3);
  position: relative;
  overflow: hidden;
}

.project-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.project-cover-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f, #3b82f6);
  color: rgba(255, 255, 255, 0.9);
  font-size: 2rem;
}

html[data-theme="dark"] .project-cover-fallback {
  background: linear-gradient(135deg, #16283f, #274b7a);
}

.project-status {
  position: absolute;
  top: 10px;
  left: 10px;
}

.project-body {
  padding: 16px 16px 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex: 1;
}

.project-meta { flex: 1; min-width: 0; }

.project-meta h3 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-meta p {
  margin: 0 0 10px;
  font-size: 0.83rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}

.project-counts {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.project-counts i { margin-right: 5px; opacity: 0.8; }

.project-go {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

a.project-card-link:hover { text-decoration: none; }
a.project-card-link:hover .project-go {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-primary:active { background: var(--primary-active); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--border-strong); background: var(--surface-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(0.92); color: #fff; }

.btn-danger-ghost {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-danger-ghost:hover { background: var(--danger); color: #fff; }

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
  border-radius: 7px;
}

.btn-lg {
  padding: 12px 22px;
  font-size: 0.95rem;
}

.btn-block { width: 100%; }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-3); color: var(--text-muted); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- Alerts ---------- */
.alert {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.alert i { margin-top: 2px; }

.alert-success { background: var(--success-soft); border-color: var(--success); color: var(--text); }
.alert-success i { color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: var(--danger); color: var(--text); }
.alert-error i { color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: var(--info); color: var(--text); }
.alert-info i { color: var(--info); }

.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 18px;
}

.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
.form-full { grid-column: 1 / -1; }

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.form-label .required { color: var(--danger); }

.form-control {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control::placeholder { color: var(--text-faint); }

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

textarea.form-control { min-height: 110px; resize: vertical; }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

input[type="file"].form-control { padding: 8px 12px; }

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.form-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin-top: 5px;
  font-weight: 500;
}

.form-control.invalid { border-color: var(--danger); }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.check-row:hover { border-color: var(--border-strong); background: var(--surface-2); }
.check-row input { margin-top: 3px; accent-color: var(--primary); width: 16px; height: 16px; }
.check-row strong { display: block; font-size: 0.88rem; }
.check-row small { color: var(--text-muted); font-size: 0.78rem; }

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}
.check-inline input { accent-color: var(--primary); width: 16px; height: 16px; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.image-preview {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 320px;
  background: var(--surface-2);
}

.image-preview img { display: block; width: 100%; height: auto; }
.image-preview.tall { max-width: 180px; }

.upload-drop {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.upload-drop:hover { border-color: var(--primary); }
.upload-drop i { font-size: 1.4rem; margin-bottom: 6px; display: block; }

/* Search bar */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search-box { position: relative; flex: 1; min-width: 220px; max-width: 380px; }
.search-box i {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 0.85rem;
}
.search-box .form-control { padding-left: 36px; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 640px;
}

.table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: var(--surface-2); }

.table .cell-main { font-weight: 600; }
.table .cell-sub { font-size: 0.78rem; color: var(--text-muted); }

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

.pagination a,
.pagination span {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
}

.pagination a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .disabled { opacity: 0.45; }

.pagination-meta {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 10px;
}

/* ---------- Empty states ---------- */
.empty {
  text-align: center;
  padding: 56px 24px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--text-muted); margin-bottom: 18px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 28, 0.55);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 18px;
  overflow-y: auto;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  animation: modal-in 0.18s ease;
}

.modal-sm { max-width: 420px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ---------- Manager (admin project show) ---------- */
.manager-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  align-items: start;
}

.manager-sections .card-body { padding: 12px; }

.manager-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--surface);
  overflow: hidden;
}

.manager-section.active { border-color: var(--primary); box-shadow: var(--focus-ring); }
.manager-section:last-child { margin-bottom: 0; }

.manager-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  background: var(--surface-2);
}

.manager-section-head .grip { color: var(--text-faint); font-size: 0.8rem; }

.manager-section-head strong {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manager-section-head .count {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface-3);
  border-radius: 999px;
  padding: 2px 9px;
  font-weight: 700;
  flex-shrink: 0;
}

.mini-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mini-btn:hover { color: var(--primary); border-color: var(--primary); }
.mini-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.component-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.component-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

.component-thumb {
  width: 64px;
  height: 44px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--surface-3);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.component-thumb-fallback {
  width: 64px;
  height: 44px;
  border-radius: 7px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-faint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.component-row-meta { flex: 1; min-width: 0; }
.component-row-meta strong { display: block; font-size: 0.92rem; }
.component-row-meta span {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.component-flags { display: flex; gap: 6px; flex-shrink: 0; }

.flag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.flag.on { background: var(--primary-soft); color: var(--primary); }

/* ---------- Viewer ---------- */
.viewer {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  min-height: 70vh;
}

.viewer-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.viewer-title { font-weight: 700; font-size: 1rem; min-width: 0; }
.viewer-title small { display: block; font-weight: 500; color: var(--text-muted); font-size: 0.78rem; }

.segmented {
  display: inline-flex;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.segmented a,
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.83rem;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.segmented a:hover, .segmented button:hover { color: var(--text); text-decoration: none; }
.segmented a.active, .segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin: -1px;
}

.segmented a.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.viewer-body { display: flex; flex: 1; min-height: 0; }

.viewer-side {
  width: 290px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 260px);
  min-height: 420px;
}

.viewer-side-search { padding: 12px 12px 6px; }

.viewer-nav { flex: 1; overflow-y: auto; padding: 6px 12px 14px; }

.viewer-section { margin-bottom: 4px; }

.viewer-section-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 10px 6px;
}

.viewer-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
}

.viewer-link:hover { background: var(--surface-3); text-decoration: none; }
.viewer-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.viewer-link i { font-size: 0.75rem; opacity: 0.6; width: 16px; text-align: center; }

.viewer-link .v-thumb {
  width: 34px;
  height: 24px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.viewer-stage {
  flex: 1;
  min-width: 0;
  background: var(--viewer-stage-bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.viewer-stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  color: #cbd5e1;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-wrap: wrap;
}

.viewer-stage-head .mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 600;
}

.viewer-canvas {
  flex: 1;
  overflow: auto;
  padding: 26px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.viewer-canvas img.shot {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  object-fit: contain;
  background: #fff;
}

.viewer-canvas img.shot.mobile {
  max-width: 400px;
  width: 100%;
}

.viewer-empty {
  color: #94a3b8;
  text-align: center;
  padding: 60px 20px;
  margin: auto;
}

.viewer-empty i { font-size: 2.4rem; opacity: 0.5; margin-bottom: 14px; display: block; }

/* Fullscreen viewer mode */
.viewer-fullbar { display: none; }

body.viewer-fullscreen {
  overflow: hidden;
}

body.viewer-fullscreen .sidebar,
body.viewer-fullscreen .topbar {
  display: none;
}

body.viewer-fullscreen .main { margin-left: 0; }
body.viewer-fullscreen .content { max-width: none; padding: 0; }
body.viewer-fullscreen .viewer { border: 0; border-radius: 0; min-height: 100vh; height: 100vh; }
body.viewer-fullscreen .viewer-side { display: none; }

body.viewer-fullscreen .viewer-fullbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #0b1220;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-wrap: wrap;
}

body.viewer-fullscreen .viewer-topbar { display: none; }

.viewer-fullbar select {
  background: #16202f;
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.83rem;
  max-width: 220px;
}

.viewer-fullbar .segmented {
  background: #16202f;
  border-color: rgba(255, 255, 255, 0.14);
}

.viewer-fullbar .segmented a,
.viewer-fullbar .segmented button { color: #94a3b8; }

.viewer-fullbar .segmented a.active,
.viewer-fullbar .segmented button.active {
  background: #243349;
  color: #fff;
  border-color: transparent;
  box-shadow: none;
  margin: 0;
}

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 18px;
  background:
    radial-gradient(700px 320px at 15% 10%, rgba(59, 130, 246, 0.14), transparent 60%),
    radial-gradient(700px 320px at 85% 90%, rgba(99, 102, 241, 0.12), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 34px 32px 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-brand .brand-mark { width: 44px; height: 44px; font-size: 1.2rem; }

.auth-brand strong { display: block; font-size: 1.08rem; }
.auth-brand span { font-size: 0.78rem; color: var(--text-muted); }

.auth-card h1 { font-size: 1.35rem; margin-bottom: 4px; }
.auth-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 22px; }

.auth-alt {
  text-align: center;
  margin-top: 20px;
  font-size: 0.87rem;
  color: var(--text-muted);
}

.auth-demo {
  margin-top: 18px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.79rem;
  color: var(--text-muted);
}

.auth-demo code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.76rem;
}

/* ---------- Profile / misc ---------- */
.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 0.9rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 500; }

.role-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.perm-group { margin-bottom: 20px; }
.perm-group:last-child { margin-bottom: 0; }
.perm-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.perm-group-head h4 { margin: 0; font-size: 0.9rem; }
.perm-group-head h4 i { color: var(--primary); margin-right: 8px; }

.code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: 0.5; font-size: 0.7rem; }

.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ---------- Utilities ---------- */
.d-flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.min-w-0 { min-width: 0; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 18px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 18px; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm { font-size: 0.83rem; }
.text-center { text-align: center; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-100 { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .project-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .manager-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(10, 16, 28, 0.5);
    z-index: 55;
  }
  .main, body.sidebar-collapsed .main { margin-left: 0; }
  body.sidebar-collapsed .brand-text,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .nav-link .nav-text,
  body.sidebar-collapsed .sidebar-user-meta { display: block; }
  body.sidebar-collapsed .nav-link { justify-content: flex-start; padding: 9px 12px; }
  body.sidebar-collapsed .sidebar-user { justify-content: flex-start; }
  .hamburger { display: inline-flex; }
  .collapse-btn { display: none; }
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 0 14px; }
  .project-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
  .user-chip span { display: none; }
  .user-chip { padding: 5px; border-radius: 50%; }
  .viewer-body { flex-direction: column; }
  .viewer-side { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); max-height: 300px; min-height: 0; }
  .viewer-canvas { padding: 14px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 8px; }
  .auth-card { padding: 26px 22px; }
}

@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 1.25rem; }
}
