/* CSS Variables */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #64748b;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --background: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --radius: 8px;
  --transition: all 0.2s ease;
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Auth Pages */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--background) 0%, #1e1b4b 100%);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-header h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.auth-header p {
  color: var(--text-muted);
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface-light);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  padding: 6px;
  background: transparent;
  font-size: 16px;
}

.btn-icon:hover {
  background: var(--surface-light);
}

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

/* Messages */
.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 16px;
  padding: 10px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius);
  display: none;
}

.error-message.show {
  display: block;
}

.success-message {
  color: var(--success);
  font-size: 14px;
  margin-bottom: 16px;
  padding: 10px;
  background: rgba(34, 197, 94, 0.1);
  border-radius: var(--radius);
  display: none;
}

.success-message.show {
  display: block;
}

/* Auth Footer */
.auth-footer {
  text-align: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
}

.auth-footer a {
  color: var(--primary);
  text-decoration: none;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 20px;
  margin-bottom: 12px;
}

.sidebar-nav {
  padding: 8px;
  display: flex;
  gap: 4px;
}

.nav-item {
  flex: 1;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  color: var(--text-muted);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
}

.nav-item:hover {
  background: var(--surface-light);
  color: var(--text);
}

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

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-item {
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 4px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item:hover {
  background: var(--surface-light);
}

.chat-item.active {
  background: var(--primary);
}

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

.user-info {
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-muted);
  word-break: break-all;
}

/* Main Content */
.main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.section {
  display: none;
  height: 100%;
}

.section.active {
  display: block;
}

/* Chat Section */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.chat-header h2 {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.welcome-message {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.welcome-message h3 {
  color: var(--text);
  margin-bottom: 8px;
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--primary);
}

.message.assistant .message-avatar {
  background: var(--success);
}

.message-content {
  flex: 1;
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 80%;
}

.message.user .message-content {
  background: var(--primary);
}

.message-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.chat-input-container {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.chat-form {
  display: flex;
  gap: 12px;
}

.chat-form textarea {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  resize: none;
  min-height: 48px;
  max-height: 120px;
}

.chat-form textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Cron Section */
.cron-container {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.cron-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.cron-list {
  display: grid;
  gap: 12px;
  margin-bottom: 32px;
}

.cron-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.cron-status {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cron-status.enabled {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.cron-status.disabled {
  background: var(--secondary);
}

.cron-info {
  flex: 1;
}

.cron-info h4 {
  font-size: 16px;
  margin-bottom: 4px;
}

.cron-info p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.cron-actions {
  display: flex;
  gap: 8px;
}

.cron-history {
  margin-top: 32px;
}

.cron-history h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.history-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.history-item:last-child {
  border-bottom: none;
}

.history-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 12px;
}

.history-status.success {
  background: var(--success);
}

.history-status.failure {
  background: var(--danger);
}

.history-status.running {
  background: var(--warning);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h3 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

.modal form {
  padding: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 16px;
}

/* Admin Section */
.admin-container {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.user-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.user-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.user-item:last-child {
  border-bottom: none;
}

.user-info {
  flex: 1;
}

.user-info h4 {
  font-size: 16px;
  margin-bottom: 4px;
}

.user-info p {
  font-size: 13px;
  color: var(--text-muted);
}

.admin-badge {
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-left: 8px;
}

/* GeBIZ Section */
.gebiz-container {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.gebiz-header {
  margin-bottom: 24px;
}

.gebiz-header h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.gebiz-subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

.gebiz-search-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.gebiz-form .form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.gebiz-form .form-group {
  margin-bottom: 0;
}

.gebiz-form .form-group.flex-2 {
  flex: 2;
}

.gebiz-form .form-group.flex-1 {
  flex: 1;
}

.gebiz-form .form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.gebiz-results {
  background: var(--surface);
  border-radius: var(--radius);
  min-height: 200px;
  margin-bottom: 24px;
}

.gebiz-result-item {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.gebiz-result-item:last-child {
  border-bottom: none;
}

.gebiz-result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.gebiz-result-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.gebiz-result-title:hover {
  text-decoration: underline;
}

.gebiz-result-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.gebiz-result-description {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

.gebiz-cron-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

.gebiz-cron-section h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.criteria-display {
  background: var(--background);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 14px;
}

.criteria-display .criteria-item {
  margin-bottom: 4px;
}

.criteria-display .criteria-item:last-child {
  margin-bottom: 0;
}

.criteria-display .criteria-label {
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .gebiz-form .form-row {
    flex-direction: column;
    gap: 12px;
  }
  
  .gebiz-form .form-actions {
    flex-direction: column;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--background);
}

::-webkit-scrollbar-thumb {
  background: var(--surface-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 240px;
  }
  
  .message-content {
    max-width: 90%;
  }
}

@media (max-width: 640px) {
  .app-container {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 200px;
  }
  
  .chat-list {
    display: none;
  }
  
  .sidebar:hover .chat-list {
    display: block;
  }
}
