:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #d1d5db;
  --danger: #dc2626;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.card {
  background: var(--card);
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 420px;
}

.card h1 {
  margin-top: 0;
  text-align: center;
  color: var(--primary);
}

.tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
}

.auth-form input,
.auth-form button {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 15px;
}

.auth-form button,
button {
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}

.auth-form button:hover,
button:hover {
  background: var(--primary-dark);
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 4px;
  min-height: 20px;
}

.guest-divider {
  text-align: center;
  margin: 16px 0;
  color: var(--text-muted);
  position: relative;
}

.guest-divider::before,
.guest-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 35%;
  height: 1px;
  background: var(--border);
}

.guest-divider::before { left: 0; }
.guest-divider::after { right: 0; }

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #eef2ff;
}

.hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
}

.guest-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.guest-banner a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.locked-overlay {
  position: relative;
}

.locked-overlay::after {
  content: '🔒 Đăng nhập để sử dụng';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--primary);
  border-radius: 8px;
  z-index: 10;
}

.hidden {
  display: none !important;
}

/* Dashboard layout */
.dashboard {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: #111827;
  color: white;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.sidebar h2 {
  margin-top: 0;
  margin-bottom: 24px;
}

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

.nav-btn {
  background: transparent;
  color: #d1d5db;
  text-align: left;
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}

.nav-btn.active,
.nav-btn:hover {
  background: var(--primary);
  color: white;
}

.user-info {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid #374151;
}

.user-info p {
  margin: 4px 0;
}

.user-info .badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  margin-bottom: 12px;
}

.user-info button,
.user-info a {
  display: block;
  width: 100%;
  margin-top: 8px;
  text-align: center;
  text-decoration: none;
  font-size: 14px;
}

.user-info a {
  background: #374151;
  color: white;
  padding: 10px;
  border-radius: 8px;
}

.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.model-selector,
.lang-row,
.inline-form {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.model-selector label {
  font-weight: 600;
}

select,
input[type="text"],
textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}

textarea {
  width: 100%;
  resize: vertical;
}

.result-box {
  background: white;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  min-height: 80px;
  white-space: pre-wrap;
  margin-top: 16px;
}

.limit-info {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Chat */
.chat-layout {
  display: flex;
  gap: 16px;
  height: calc(100vh - 160px);
}

.chat-sidebar {
  width: 240px;
  background: white;
  border-radius: 12px;
  padding: 16px;
  overflow-y: auto;
}

.chat-sidebar button {
  width: 100%;
  margin-bottom: 12px;
}

.session-item {
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 6px;
  background: #f9fafb;
  border: 1px solid var(--border);
}

.session-item.active,
.session-item:hover {
  background: #e0e7ff;
  border-color: var(--primary);
}

.session-item small {
  color: var(--text-muted);
  font-size: 12px;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 12px;
  padding: 16px;
}

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

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
}

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

.message.assistant {
  align-self: flex-start;
  background: #f3f4f6;
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.chat-input-row input {
  flex: 1;
}

/* Tables / Lists */
.table {
  width: 100%;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  border-collapse: collapse;
  margin-top: 16px;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: #f9fafb;
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: none;
}

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

.actions button {
  padding: 6px 10px;
  font-size: 13px;
}

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

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  text-align: center;
}

.stat-card h3 {
  margin: 0;
  font-size: 32px;
  color: var(--primary);
}

.stat-card p {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.history-item {
  background: white;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.history-item p {
  margin: 4px 0;
}

.history-item .meta {
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .dashboard {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
  }
  .chat-layout {
    flex-direction: column;
    height: auto;
  }
  .chat-sidebar {
    width: 100%;
  }
}
