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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

/* ===== CHAT PAGE ===== */
.chat-container {
  max-width: 800px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: white;
  box-shadow: var(--shadow-lg);
}

.chat-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header .logo {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.chat-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.chat-header .subtitle {
  font-size: 13px;
  opacity: 0.85;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

.message.assistant { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

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

.message.assistant .avatar {
  background: var(--primary-light);
  color: var(--primary);
}

.message.user .avatar {
  background: var(--gray-200);
  color: var(--gray-600);
}

.message .bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 15px;
  white-space: pre-wrap;
}

.message.assistant .bubble {
  background: var(--gray-100);
  color: var(--gray-800);
  border-bottom-left-radius: 4px;
}

.message.user .bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--gray-100);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  gap: 4px;
  align-items: center;
  margin-left: 42px;
}

.typing-indicator.active { display: flex; }

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.file-preview {
  display: none;
  padding: 8px 20px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  flex-wrap: wrap;
  gap: 8px;
}

.file-preview.active { display: flex; }

.file-preview .file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: 20px;
  font-size: 12px;
  color: var(--gray-700);
}

.file-preview .file-chip .remove {
  cursor: pointer;
  color: var(--gray-400);
  font-size: 14px;
  line-height: 1;
}

.file-preview .file-chip .remove:hover { color: var(--danger); }

.attach-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--gray-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: all 0.2s;
}

.attach-btn:hover { background: var(--gray-100); color: var(--primary); }

.chat-footer {
  padding: 8px 20px 12px;
  text-align: center;
  flex-shrink: 0;
  background: white;
}

.chat-footer button {
  background: none;
  border: 1px solid var(--gray-300);
  color: var(--gray-500);
  padding: 6px 20px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.chat-footer button:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #fef2f2;
}

.chat-footer button:disabled {
  display: none;
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-shrink: 0;
  background: white;
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input-area textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-input-area button {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-input-area button:hover { background: var(--primary-dark); }
.chat-input-area button:disabled { background: var(--gray-300); cursor: not-allowed; }

/* ===== ADMIN PAGE ===== */
.admin-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.admin-header h1 {
  font-size: 20px;
  color: var(--gray-800);
}

.admin-header .btn-logout {
  padding: 8px 16px;
  border: 1px solid var(--gray-300);
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--gray-600);
}

.admin-header .btn-logout:hover { background: var(--gray-50); }

.admin-body { padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.login-card h2 {
  text-align: center;
  margin-bottom: 8px;
  color: var(--gray-800);
}

.login-card .subtitle {
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 24px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-full { width: 100%; justify-content: center; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-outline { background: white; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }

.error-msg {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  margin-top: 12px;
  display: none;
}

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

.stat-card {
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-800);
}

.stat-card.highlight .value { color: var(--primary); }

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filters select {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  background: white;
  outline: none;
}

/* Table */
.orders-table {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.orders-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.orders-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
}

.orders-table tr { cursor: pointer; transition: background 0.15s; }
.orders-table tbody tr:hover { background: var(--gray-50); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-new { background: #dbeafe; color: #1d4ed8; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-low { background: var(--gray-100); color: var(--gray-600); }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #991b1b; }

/* Detail View */
.detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
}

.detail-overlay.active { display: flex; }

.detail-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}

.detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.detail-header h2 { font-size: 18px; color: var(--gray-800); }
.detail-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--gray-400);
  padding: 4px;
}
.detail-close:hover { color: var(--gray-600); }

.detail-body { padding: 24px; }

.detail-section {
  margin-bottom: 24px;
}

.detail-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-field .label {
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 2px;
}

.detail-field .value {
  font-size: 14px;
  color: var(--gray-800);
}

.conversation-log {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.conversation-log .msg {
  font-size: 14px;
  line-height: 1.5;
}

.conversation-log .msg .role {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.conversation-log .msg.user .role { color: var(--primary); }
.conversation-log .msg.assistant .role { color: var(--success); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* Landing Page */
.landing-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
}

.landing-card {
  background: white;
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
}

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

.landing-header .logo {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  margin: 0 auto 16px;
}

.landing-header h1 {
  font-size: 24px;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.landing-header .subtitle {
  color: var(--gray-500);
  font-size: 14px;
}

.landing-desc {
  font-size: 14px;
  color: var(--gray-600);
  line-height: 1.6;
  margin-bottom: 20px;
  text-align: center;
}

.success-icon {
  width: 64px;
  height: 64px;
  background: #d1fae5;
  color: #065f46;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 16px;
}

.pending-icon {
  background: #fef3c7;
  color: #92400e;
}

#successMsg, #pendingMsg {
  text-align: center;
}

#successMsg h2, #pendingMsg h2 {
  margin-bottom: 8px;
  color: var(--gray-800);
}

#successMsg p, #pendingMsg p {
  color: var(--gray-600);
  font-size: 14px;
  line-height: 1.6;
}

.hint {
  margin-top: 12px;
  font-size: 13px !important;
  color: var(--gray-400) !important;
}

/* Badge additions */
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }

.tab-btn {
  padding: 8px 20px;
  border: 1px solid var(--gray-300);
  background: white;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--gray-600);
  transition: all 0.2s;
}

.tab-btn:hover { background: var(--gray-50); }
.tab-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }

/* Responsive */
@media (max-width: 768px) {
  .chat-container { max-width: 100%; }
  .message { max-width: 92%; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-body { padding: 16px; }
  .filters { flex-direction: column; }
  .filters select { width: 100%; }
}
