/* MGSP — ShadCN-inspired Design System */
:root {
  --background: #ffffff;
  --foreground: #0a0a0a;
  --card: #ffffff;
  --card-foreground: #0a0a0a;
  --popover: #ffffff;
  --popover-foreground: #0a0a0a;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --secondary: #f4f4f5;
  --secondary-foreground: #18181b;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --accent: #f4f4f5;
  --accent-foreground: #18181b;
  --destructive: #ef4444;
  --destructive-foreground: #fafafa;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --ring: #18181b;
  --radius: 8px;
  --sidebar-width: 240px;
  --header-height: 64px;

  /* Status colors */
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-info: #3b82f6;
  --color-purple: #8b5cf6;
}

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

html { font-size: 14px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ─── Layout ─────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 50;
  overflow-y: auto;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px;
  min-height: 100vh;
  background: #fafafa;
}

/* ─── Sidebar ─────────────────────────────────── */
.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: var(--primary-foreground);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted-foreground);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--accent);
  color: var(--accent-foreground);
}

.nav-item.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
}

.nav-label { flex: 1; }

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

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: var(--primary-foreground);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted-foreground); margin-top: 1px; }

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
}

/* ─── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1;
}

.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}
.btn-primary:hover { background: #27272a; }

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: var(--border);
}
.btn-secondary:hover { background: #e4e4e7; }

.btn-outline {
  background: transparent;
  color: var(--foreground);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--foreground);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--accent); }

.btn-danger {
  background: var(--destructive);
  color: white;
  border-color: var(--destructive);
}
.btn-danger:hover { background: #dc2626; }

.btn-success {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  text-decoration: none;
}

.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--accent); color: var(--foreground); }

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--destructive);
  color: white;
  font-size: 9px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 4px;
  min-width: 16px;
  text-align: center;
}

/* ─── Cards ─────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-description {
  font-size: 13px;
  color: var(--muted-foreground);
  margin-top: 2px;
}

.card-content {
  padding: 20px 24px;
}

.card-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Stats Cards ─────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat-desc {
  font-size: 12px;
  color: var(--muted-foreground);
  margin-top: 4px;
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-icon svg { width: 18px; height: 18px; }
.stat-icon-blue { background: #eff6ff; color: var(--color-info); }
.stat-icon-green { background: #f0fdf4; color: var(--color-success); }
.stat-icon-yellow { background: #fffbeb; color: var(--color-warning); }
.stat-icon-red { background: #fef2f2; color: var(--color-danger); }
.stat-icon-purple { background: #f5f3ff; color: var(--color-purple); }

/* ─── Tables ─────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--accent); }

tbody td {
  padding: 12px 16px;
  font-size: 13.5px;
  vertical-align: middle;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}

/* ─── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-primary   { background: #eff6ff; color: #1d4ed8; }
.badge-success   { background: #f0fdf4; color: #15803d; }
.badge-warning   { background: #fffbeb; color: #b45309; }
.badge-danger    { background: #fef2f2; color: #b91c1c; }
.badge-info      { background: #f0f9ff; color: #0369a1; }
.badge-secondary { background: var(--secondary); color: var(--muted-foreground); }

/* ─── Forms ─────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group:last-child { margin-bottom: 0; }

label {
  font-size: 13.5px;
  font-weight: 500;
}

.label-required::after {
  content: ' *';
  color: var(--destructive);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13.5px;
  background: var(--background);
  color: var(--foreground);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(24,24,27,0.08);
}

textarea { resize: vertical; min-height: 100px; }

select { cursor: pointer; }

.form-hint {
  font-size: 12px;
  color: var(--muted-foreground);
}

.form-error {
  font-size: 12px;
  color: var(--destructive);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* ─── Page Header ─────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.page-description {
  font-size: 13.5px;
  color: var(--muted-foreground);
  margin-top: 4px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ─── Alerts ─────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ─── Auth ─────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 13.5px;
  color: var(--muted-foreground);
  margin-bottom: 24px;
}

/* ─── Grid layouts ─────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

@media (max-width: 1024px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ─── Tabs ─────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-bottom: 20px;
}

.tab {
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted-foreground);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  margin-bottom: -1px;
}

.tab:hover { color: var(--foreground); }
.tab.active { color: var(--foreground); border-bottom-color: var(--primary); }

/* ─── Modal ─────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 17px; font-weight: 600; }

.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted-foreground);
  padding: 4px;
  border-radius: 4px;
  display: flex;
}

.modal-close:hover { background: var(--accent); }
.modal-close svg { width: 18px; height: 18px; }

/* ─── Empty state ─────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  color: var(--muted-foreground);
}

.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.6; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--foreground); margin-bottom: 6px; }
.empty-state-desc { font-size: 13px; max-width: 320px; }

/* ─── Task board ─────────────────────────────── */
.kanban {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  align-items: start;
}

.kanban-col { background: var(--muted); border-radius: var(--radius); padding: 12px; }
.kanban-col-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.kanban-card:last-child { margin-bottom: 0; }
.kanban-card-title { font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.kanban-card-meta { display: flex; align-items: center; justify-content: space-between; }

/* ─── File upload ─────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--muted-foreground);
}

.upload-area:hover, .upload-area.drag-over {
  border-color: var(--ring);
  background: var(--accent);
  color: var(--foreground);
}

.upload-area input[type="file"] { display: none; }

/* ─── Comment thread ─────────────────────────── */
.comments { display: flex; flex-direction: column; gap: 16px; }

.comment {
  display: flex;
  gap: 12px;
}

.comment-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.comment-body {
  flex: 1;
  background: var(--muted);
  border-radius: 8px;
  padding: 10px 14px;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.comment-author { font-size: 13px; font-weight: 600; }
.comment-time { font-size: 11px; color: var(--muted-foreground); }
.comment-text { font-size: 13.5px; line-height: 1.6; }

/* ─── Token box ─────────────────────────────── */
.token-box {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: 'Courier New', monospace;
  font-size: 12.5px;
  word-break: break-all;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* ─── Separator ─────────────────────────────── */
.separator {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ─── Breadcrumb ─────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted-foreground);
  margin-bottom: 16px;
}

.breadcrumb a:hover { color: var(--foreground); }
.breadcrumb-sep { opacity: 0.4; }
.breadcrumb-current { color: var(--foreground); font-weight: 500; }

/* ─── Progress ─────────────────────────────── */
.progress {
  height: 6px;
  background: var(--muted);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.3s;
}

.progress-bar.bar-success { background: var(--color-success); }
.progress-bar.bar-warning { background: var(--color-warning); }
.progress-bar.bar-danger  { background: var(--color-danger); }

/* ─── Utility ─────────────────────────────── */
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--muted-foreground); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full { width: 100%; }

/* ─── Notifications panel ─────────────────────── */
.notif-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 360px;
  height: 100vh;
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 200;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
}

.notif-panel.open { right: 0; }

.notif-panel-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.notif-panel-title { font-size: 16px; font-weight: 600; }

.notif-list { flex: 1; overflow-y: auto; }

.notif-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.notif-item:hover { background: var(--accent); }
.notif-item.unread { background: #eff6ff; }
.notif-item.unread:hover { background: #dbeafe; }

.notif-title { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.notif-msg { font-size: 12.5px; color: var(--muted-foreground); }
.notif-time { font-size: 11px; color: var(--muted-foreground); margin-top: 4px; }

.notif-overlay {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: none;
}

.notif-overlay.open { display: block; }

/* ─── Spec content ─────────────────────────── */
.spec-content {
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  font-family: inherit;
}

/* ─── Loading ─────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Copy button ─────────────────────────────── */
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  color: var(--muted-foreground);
  transition: all 0.15s;
  white-space: nowrap;
}

.copy-btn:hover { background: var(--accent); color: var(--foreground); }
.copy-btn.copied { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
