/* ═══════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--card-hover); border-color: var(--muted-dark); }

.btn-danger {
  background: var(--danger-subtle);
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover:not(:disabled) { background: var(--danger); color: white; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--card); }

.btn-success {
  background: var(--success-subtle);
  color: var(--success);
  border-color: transparent;
}
.btn-success:hover:not(:disabled) { background: var(--success); color: white; }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }
.btn-full { width: 100%; }

.btn-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color var(--transition-fast);
}
.card:hover { border-color: var(--muted-dark); }
.card-flat { border-color: var(--border-light); }
.card-flat:hover { border-color: var(--border); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: var(--text-md);
  font-weight: 600;
}
.card-description {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text);
  margin-top: var(--space-2);
  letter-spacing: -0.03em;
}
.stat-meta {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--space-1);
}

/* ═══════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════ */

.form-group {
  margin-bottom: var(--space-5);
}
.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast);
  line-height: 1.5;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover, 
.form-input:-webkit-autofill:focus, 
.form-input:-webkit-autofill:active{
    -webkit-box-shadow: 0 0 0 30px var(--bg) inset !important;
    -webkit-text-fill-color: var(--text) !important;
    transition: background-color 5000s ease-in-out 0s;
}
.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--muted-dark);
}

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

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A1A1AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-error {
  color: var(--danger);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--danger-subtle);
  border-radius: var(--radius-md);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

.form-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}
.toggle-switch {
  display: block;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: var(--radius-full);
  position: relative;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text);
  border-radius: 50%;
  transition: transform var(--transition-fast);
}
.toggle-input {
  display: none;
}
.toggle-input:checked + .toggle-switch {
  background: var(--accent);
}
.toggle-input:checked + .toggle-switch::after {
  transform: translateX(16px);
}
.toggle-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge-stable { background: var(--channel-stable-bg); color: var(--channel-stable); }
.badge-beta { background: var(--channel-beta-bg); color: var(--channel-beta); }
.badge-internal { background: var(--channel-internal-bg); color: var(--channel-internal); }
.badge-draft { background: var(--status-draft-bg); color: var(--status-draft); }
.badge-published { background: var(--status-published-bg); color: var(--status-published); }
.badge-archived { background: var(--status-archived-bg); color: var(--status-archived); }
.badge-deprecated { background: var(--status-deprecated-bg); color: var(--status-deprecated); }
.badge-active { background: var(--channel-stable-bg); color: var(--channel-stable); }
.badge-info { background: var(--info-subtle); color: var(--info); }

/* ═══════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════ */

.table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.table th {
  background: var(--bg-elevated);
  font-weight: 500;
  color: var(--muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--card); }
.table td { color: var(--text-secondary); }

/* ═══════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-8);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}
.modal-title { font-size: var(--text-lg); font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text); }
.modal-close svg { width: 20px; height: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text);
  pointer-events: auto;
  animation: slideIn var(--transition-slow) ease;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast-success svg { color: var(--success); }
.toast-error svg { color: var(--danger); }
.toast-info svg { color: var(--info); }
.toast.fade-out { animation: slideOut var(--transition-slow) ease forwards; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slideOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* ═══════════════════════════════════════════════
   LOADING
   ═══════════════════════════════════════════════ */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
  color: var(--muted);
  gap: var(--space-3);
}

/* ═══════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
  color: var(--muted);
  text-align: center;
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: var(--space-4); color: var(--border); }
.empty-state h3 { color: var(--text-secondary); margin-bottom: var(--space-2); }
.empty-state p { font-size: var(--text-sm); max-width: 320px; }

/* ═══════════════════════════════════════════════
   SEARCH
   ═══════════════════════════════════════════════ */

.search-box {
  position: relative;
  max-width: 320px;
}
.search-box svg {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted-dark);
}
.search-box input {
  padding-left: 36px;
}

/* ═══════════════════════════════════════════════
   KEY DISPLAY
   ═══════════════════════════════════════════════ */

.key-display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.key-display .key-value { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.key-display button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}
.key-display button:hover { color: var(--text); }
.key-display button svg { width: 14px; height: 14px; }

/* ═══════════════════════════════════════════════
   FILE UPLOAD
   ═══════════════════════════════════════════════ */

.file-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--muted);
}
.file-upload:hover, .file-upload.drag-over {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--text);
}
.file-upload svg { width: 32px; height: 32px; margin: 0 auto var(--space-3); }
.file-upload p { font-size: var(--text-sm); }
.file-upload .file-name {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--accent);
}

.upload-progress {
  margin-top: var(--space-3);
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
  width: 0%;
}

/* ═══════════════════════════════════════════════
   MARKDOWN EDITOR
   ═══════════════════════════════════════════════ */

.md-editor-container {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.md-editor-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.md-toolbar-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}
.md-toolbar-btn:hover { color: var(--text); background: var(--card); }
.md-toolbar-btn svg { width: 16px; height: 16px; }
.md-toolbar-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 var(--space-1);
}

.md-editor-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 300px;
}

.md-editor-input {
  resize: none;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  outline: none;
}

.md-editor-preview {
  padding: var(--space-4);
  overflow-y: auto;
  background: var(--card);
  font-size: var(--text-sm);
  line-height: 1.7;
}
.md-editor-preview h1 { font-size: var(--text-xl); margin-bottom: var(--space-4); }
.md-editor-preview h2 { font-size: var(--text-lg); margin: var(--space-6) 0 var(--space-3); }
.md-editor-preview h3 { font-size: var(--text-md); margin: var(--space-5) 0 var(--space-2); }
.md-editor-preview p { margin-bottom: var(--space-3); color: var(--text-secondary); }
.md-editor-preview ul, .md-editor-preview ol { padding-left: var(--space-6); margin-bottom: var(--space-3); color: var(--text-secondary); }
.md-editor-preview li { margin-bottom: var(--space-1); }
.md-editor-preview pre { margin-bottom: var(--space-4); position: relative; }
.md-editor-preview table { width: 100%; border-collapse: collapse; margin-bottom: var(--space-4); }
.md-editor-preview table th, .md-editor-preview table td {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
}
.md-editor-preview table th { background: var(--bg-elevated); font-weight: 500; }

.md-editor-preview .code-block-wrapper {
  position: relative;
  margin-bottom: var(--space-4);
}
.copy-code-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.code-block-wrapper:hover .copy-code-btn { opacity: 1; }
.copy-code-btn:hover { color: var(--text); }

@media (max-width: 768px) {
  .md-editor-body { grid-template-columns: 1fr; }
  .md-editor-preview { border-top: 1px solid var(--border); }
  .md-editor-input { border-right: none; }
}

/* ═══════════════════════════════════════════════
   ACTIVITY LIST
   ═══════════════════════════════════════════════ */

.activity-list {
  display: flex;
  flex-direction: column;
}
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-light);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.activity-icon svg { width: 16px; height: 16px; }
.activity-text { font-size: var(--text-sm); color: var(--text-secondary); }
.activity-text strong { color: var(--text); font-weight: 500; }
.activity-time { font-size: var(--text-xs); color: var(--muted-dark); margin-top: 2px; }

/* ═══════════════════════════════════════════════
   DETAIL VIEW
   ═══════════════════════════════════════════════ */

.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}
.detail-label {
  color: var(--muted);
  font-weight: 500;
}
.detail-value {
  color: var(--text-secondary);
  word-break: break-all;
}

/* ═══════════════════════════════════════════════
   TABS
   ═══════════════════════════════════════════════ */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-6);
}
.tab {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ═══════════════════════════════════════════════
   FILTER BAR
   ═══════════════════════════════════════════════ */

.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.filter-bar .form-select,
.filter-bar .form-input {
  width: auto;
  min-width: 150px;
}
