:root {
  --bg: #f9f9fb;
  --panel: #ffffff;
  --text: #1f2224;
  --muted: #6b7280;
  --accent: #d9a116;
  --accent-2: #b7830e;
  --border: #e5e7eb;
  --brand-primary: #d9a116;
  --brand-primary-dark: #b7830e;
  --brand-primary-light: #f4c64d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.6 'Roboto', system-ui, -apple-system, Segoe UI, Ubuntu, Cantarell, Noto Sans, Arial;
  background: var(--bg);
  color: var(--text);
}

/* Portal Navigation */
.portal-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--brand-primary-light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.625rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.nav-logo {
  height: 2.5rem;
  width: auto;
}
.nav-text {
  display: flex;
  flex-direction: column;
}
.nav-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  color: var(--text);
}
.nav-subtitle {
  font-size: 0.75rem;
  color: var(--brand-primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.nav-back {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  text-decoration: none;
  transition: all 0.2s;
}
.nav-back:hover {
  color: var(--brand-primary-dark);
  background: #f3f4f6;
}

.kb-header { 
  padding: 24px; 
  border-bottom: 1px solid var(--border); 
  background: linear-gradient(135deg, var(--brand-primary-light) 0%, var(--brand-primary) 55%, var(--brand-primary-dark) 120%);
  color: white;
}
.kb-header h1 { margin: 0; font-size: 24px; color: white; }
.kb-header .subtitle { margin: 4px 0 0; color: rgba(255, 255, 255, 0.9); }

.kb-controls { display: flex; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--panel); }
.kb-controls input, .kb-controls select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}
.kb-controls input { flex: 1; }

.kb-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; padding: 16px 24px; }
.kb-card { 
  border: 1px solid rgba(217, 161, 22, 0.6); 
  border-radius: 12px; 
  background: var(--panel); 
  padding: 14px; 
  display: flex; 
  flex-direction: column; 
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.25s, transform 0.25s;
}
.kb-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(-4px);
}
.kb-card-head { display: flex; align-items: baseline; justify-content: space-between; }
.kb-title { margin: 0; font-size: 18px; font-weight: 600; }
.kb-category { color: var(--muted); font-size: 12px; }
.kb-summary { margin: 0; color: var(--text); opacity: 0.85; }
.kb-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.kb-tag { 
  font-size: 12px; 
  color: var(--brand-primary-dark); 
  background: rgba(217, 161, 22, 0.1); 
  border: 1px solid rgba(217, 161, 22, 0.3); 
  border-radius: 999px; 
  padding: 2px 8px; 
}
.kb-actions { display: flex; gap: 8px; }
.kb-button { 
  cursor: pointer; 
  font-size: 13px; 
  padding: 6px 10px; 
  border-radius: 8px; 
  border: 1px solid var(--border); 
  background: var(--panel); 
  color: var(--text);
  transition: all 0.2s;
}
.kb-button:hover { 
  border-color: var(--accent); 
  color: white;
  background: var(--accent);
}

.kb-details summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.kb-details .kb-content { margin-top: 8px; color: var(--text); }

.kb-footer { 
  padding: 12px 24px; 
  border-top: 1px solid var(--border); 
  color: var(--muted);
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.status { font-size: 12px; }
.footer-info { font-size: 11px; opacity: 0.7; }

.kb-noscript { padding: 12px 24px; color: #ef4444; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; margin: 16px 24px; }

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
.modal.active { display: flex; align-items: center; justify-content: center; }
.modal-content {
  background: var(--panel);
  padding: 48px;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  max-width: 460px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
#loginModal .modal-content {
  text-align: center;
}
#loginModal h2 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: var(--text);
}
#loginModal form {
  text-align: left;
  margin-top: 24px;
}
.modal-large { max-width: 900px; }
.modal-close {
  position: absolute;
  right: 16px;
  top: 16px;
  font-size: 28px;
  font-weight: bold;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s;
}
.modal-close:hover { color: var(--text); }

/* Form Styles */
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #6b7280;
  font-size: 14px;
  text-align: left;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f3f4f6;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  transition: all 0.2s;
}
#loginModal .form-group input[type="text"],
#loginModal .form-group input[type="password"] {
  background: #f3f4f6;
  border: 2px solid transparent;
}
#loginModal .form-group input[type="text"]:focus,
#loginModal .form-group input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  background: white;
}
.form-group textarea {
  resize: vertical;
}
.form-group small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Button Styles */
.btn-primary, .btn-secondary, .btn-logout, .btn-upload, .btn-action {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--brand-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--brand-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(217, 161, 22, 0.3);
}
#loginModal .btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
  margin-top: 8px;
}
.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg);
}
.btn-logout {
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 6px 14px;
  font-size: 13px;
}
.btn-logout:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
}

/* Header Updates */
.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
}
.user-info span {
  font-weight: 500;
}

/* Action Bar */
.action-bar {
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-upload {
  background: var(--brand-primary);
  color: white;
}
.btn-upload:hover {
  background: var(--brand-primary-dark);
  box-shadow: 0 4px 12px rgba(217, 161, 22, 0.3);
}
.btn-action {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-action:hover {
  background: var(--bg);
  border-color: var(--brand-primary);
}
.btn-upload .icon,
.btn-action .icon {
  font-size: 16px;
}

/* Card Meta Info */
.kb-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0;
}
.kb-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Upload Progress */
.upload-progress {
  margin: 16px 0;
}
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--brand-primary);
  transition: width 0.3s;
  width: 0%;
}
#progressText {
  font-size: 13px;
  color: var(--muted);
}

/* Error Messages */
.error-message {
  color: #ef4444;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px;
  margin: 12px 0;
  font-size: 13px;
  display: none;
}
.error-message.active {
  display: block;
}

/* Admin Panel */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.tab-btn {
  padding: 10px 20px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.2s;
  margin-bottom: -2px;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
}
.admin-content {
  min-height: 300px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--brand-primary);
  margin: 8px 0;
}
.stat-label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.activity-list {
  max-height: 400px;
  overflow-y: auto;
}
.activity-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.activity-item:last-child {
  border-bottom: none;
}
.activity-username {
  font-weight: 600;
  color: var(--brand-primary);
}
.activity-time {
  font-size: 11px;
  color: var(--muted);
}

/* Responsive Design */
@media (max-width: 768px) {
  .kb-controls { flex-direction: column; }
  .header-content { flex-direction: column; align-items: flex-start; gap: 12px; }
  .user-info { width: 100%; justify-content: space-between; }
  .action-bar { flex-direction: column; }
  .btn-upload, .btn-action { width: 100%; }
  .modal-content { padding: 20px; }
  .kb-results { grid-template-columns: 1fr; }
}