:root {
  --primary: #1a1a2e;
  --primary-light: #16213e;
  --accent: #0f3460;
  --highlight: #e94560;
  --highlight-light: #ff6b81;
  --bg: #0d0d1a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #22224a;
  --text: #e8e8e8;
  --text-muted: #999;
  --border: #2a2a4a;
  --shadow: rgba(0,0,0,0.3);
  --radius: 12px;
  --transition: 0.3s ease;
}

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

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

a { color: var(--highlight); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--highlight-light); }

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* ---- NAV ---- */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(26,26,46,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.navbar .container { display: flex; align-items: center; justify-content: space-between; }
.navbar-brand { display: flex; align-items: center; gap: 10px; font-size: 1.4rem; font-weight: 700; color: var(--text); }
.navbar-brand i { color: var(--highlight); font-size: 1.6rem; }
.navbar-links { display: flex; gap: 24px; align-items: center; }
.navbar-links a { color: var(--text-muted); font-weight: 500; }
.navbar-links a:hover { color: var(--highlight); }

/* ---- HERO ---- */
.hero {
  text-align: center;
  padding: 80px 20px 60px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 50%, var(--highlight) 100%);
  background-size: 200% 200%;
  animation: gradientShift 8s ease infinite;
}
@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.hero h1 { font-size: 2.8rem; margin-bottom: 16px; }
.hero p { font-size: 1.2rem; color: var(--text-muted); max-width: 600px; margin: 0 auto 32px; }
.hero .btn { display: inline-block; }
.hero-icon { font-size: 4rem; color: var(--highlight); margin-bottom: 16px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 28px; border-radius: var(--radius); font-weight: 600; font-size: 1rem;
  transition: all var(--transition); border: none; cursor: pointer;
}
.btn-primary { background: var(--highlight); color: #fff; }
.btn-primary:hover { background: var(--highlight-light); color: #fff; transform: translateY(-2px); box-shadow: 0 4px 20px rgba(233,69,96,0.4); }
.btn-secondary { background: transparent; color: var(--highlight); border: 2px solid var(--highlight); }
.btn-secondary:hover { background: var(--highlight); color: #fff; }
.btn-sm { padding: 8px 18px; font-size: 0.85rem; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover { background: #c82333; }

/* ---- SECTIONS ---- */
.section { padding: 60px 0; }
.section-title {
  text-align: center; font-size: 2rem; margin-bottom: 12px;
  position: relative;
}
.section-title i { color: var(--highlight); margin-right: 10px; }
.section-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 40px; }

/* ---- CARDS GRID ---- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  transition: all var(--transition);
  display: flex; flex-direction: column;
}
.card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-4px);
  box-shadow: 0 8px 30px var(--shadow);
  border-color: var(--highlight);
}
.card-icon {
  font-size: 2rem; color: var(--highlight); margin-bottom: 16px;
  width: 56px; height: 56px; border-radius: 12px;
  background: rgba(233,69,96,0.12); display: flex; align-items: center; justify-content: center;
}
.card h3 { font-size: 1.15rem; margin-bottom: 8px; }
.card p { color: var(--text-muted); font-size: 0.92rem; flex: 1; }
.card-footer { margin-top: 16px; }
.card-footer a { font-weight: 600; font-size: 0.9rem; }

/* ---- FEATURES ---- */
.features {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 40px;
  margin: 40px 0;
}
.features-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 30px; margin-top: 24px;
}
.feature-item { text-align: center; padding: 20px; }
.feature-item i { font-size: 2rem; color: var(--highlight); margin-bottom: 12px; display: block; }
.feature-item h4 { margin-bottom: 6px; }
.feature-item p { color: var(--text-muted); font-size: 0.88rem; }

/* ---- ITEM PAGE ---- */
.item-page { padding: 40px 0 80px; }
.item-page h1 { font-size: 2.2rem; margin-bottom: 8px; }
.item-page .item-icon { font-size: 2rem; color: var(--highlight); margin-right: 10px; }
.item-page .item-meta { color: var(--text-muted); margin-bottom: 32px; }
.item-content { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; }
.item-content h2 { margin: 24px 0 12px; color: var(--text); }
.item-content p { margin-bottom: 16px; }
.item-content ul, .item-content ol { margin: 0 0 16px 24px; }
.item-content code { background: var(--primary-light); padding: 2px 8px; border-radius: 4px; font-size: 0.9em; }

/* ---- FOOTER ---- */
.footer {
  text-align: center; padding: 40px 0; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.9rem;
}
.footer i { color: var(--highlight); }

/* ---- FAB CHAT ---- */
.chat-fab {
  position: fixed; bottom: 28px; right: 28px; z-index: 9999;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--highlight); color: #fff; border: none;
  font-size: 1.5rem; cursor: pointer;
  box-shadow: 0 4px 20px rgba(233,69,96,0.5);
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.chat-fab:hover { transform: scale(1.1); box-shadow: 0 6px 30px rgba(233,69,96,0.6); }
.chat-fab.open i::before { content: '\f00d'; }

.chat-panel {
  position: fixed; bottom: 100px; right: 28px; z-index: 9998;
  width: 380px; max-width: calc(100vw - 40px); height: 500px; max-height: calc(100vh - 140px);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  display: none; flex-direction: column; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.chat-panel.open { display: flex; }

.chat-header {
  background: var(--primary-light); padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.chat-header i { color: var(--highlight); font-size: 1.3rem; }
.chat-header span { font-weight: 600; }
.chat-token-bar {
  height: 4px; background: var(--accent); position: relative; flex-shrink: 0;
}
.chat-token-bar-fill {
  height: 100%; transition: width 0.4s ease, background 0.4s ease;
  background: var(--highlight);
}
.chat-token-bar-label {
  position: absolute; right: 0; top: -14px;
  font-size: 0.55rem; font-weight: 600; color: var(--text-muted);
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: 0.92rem; line-height: 1.5; }
.chat-msg.user { background: var(--highlight); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.assistant { background: var(--primary-light); color: var(--text); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.assistant p { margin-bottom: 8px; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant ul, .chat-msg.assistant ol { margin: 4px 0 8px 18px; }
.chat-msg.assistant li { margin-bottom: 2px; }
.chat-msg.assistant pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; font-size: 0.85rem; }
.chat-msg.assistant code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; font-family: 'Fira Code', 'Cascadia Code', monospace; }
.chat-msg.assistant pre code { background: none; padding: 0; }
.chat-msg.assistant strong { color: var(--highlight-light); }
.chat-msg.assistant blockquote { border-left: 3px solid var(--highlight); margin: 8px 0; padding: 4px 12px; color: var(--text-muted); }
.chat-msg.chat-tool-result { background: rgba(15,52,96,0.4); border: 1px solid var(--accent); }
.chat-msg.typing { color: var(--text-muted); font-style: italic; }

.chat-msg.system, .chat-msg.system-info {
  align-self: stretch; max-width: 100%;
  background: linear-gradient(135deg, rgba(233,69,96,0.15), rgba(233,69,96,0.05));
  border: 1px solid rgba(233,69,96,0.3); border-radius: 12px;
  padding: 14px 16px; text-align: center;
}
.chat-msg.system-info {
  background: linear-gradient(135deg, rgba(0,180,80,0.15), rgba(0,180,80,0.05));
  border-color: rgba(0,180,80,0.3);
  color: #00b450; font-size: 0.9rem; padding: 8px 14px;
}
.chat-msg.system .system-icon { font-size: 1.5rem; margin-bottom: 8px; }
.chat-msg.system .system-title { font-weight: 700; font-size: 1rem; margin-bottom: 6px; color: var(--highlight-light); }
.chat-msg.system .system-text { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 14px; }
.chat-token-packs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chat-token-packs button {
  background: var(--highlight); color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
}
.chat-token-packs button:hover { background: var(--highlight-light); transform: translateY(-1px); }
.chat-token-packs button .pack-price { display: block; font-size: 0.7rem; opacity: 0.8; font-weight: 400; }

.chat-scroll-btn {
  display: none; position: absolute; bottom: 68px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--primary-light); color: var(--highlight); cursor: pointer; z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5); font-size: 1rem;
  align-items: center; justify-content: center;
  transition: background 0.2s, opacity 0.3s, transform 0.2s;
}
.chat-scroll-btn.visible { display: flex; }
.chat-scroll-btn:hover { background: var(--highlight); color: #fff; transform: translateX(-50%) scale(1.1); }

.chat-input {
  display: flex; border-top: 1px solid var(--border); padding: 12px; gap: 8px;
}
.chat-input input {
  flex: 1; background: var(--primary); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; color: var(--text); font-size: 0.92rem; outline: none;
}
.chat-input input:focus { border-color: var(--highlight); }
.chat-input button {
  background: var(--highlight); color: #fff; border: none; border-radius: 8px;
  padding: 10px 16px; cursor: pointer; font-size: 1rem; transition: background var(--transition);
}
.chat-input button:hover { background: var(--highlight-light); }

.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); animation: bounce 1.4s infinite both; }
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* ---- APP DRAWER ---- */
.app-drawer-overlay {
  position: fixed; inset: 0; z-index: 9990;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.app-drawer-overlay.open { opacity: 1; visibility: visible; }

.app-drawer {
  position: fixed; top: 0; right: -100%; z-index: 9991;
  width: 100%; height: 100%;
  background: var(--bg);
  display: flex; flex-direction: column;
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.app-drawer.open { right: 0; }

.app-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-drawer-header .drawer-title {
  display: flex; align-items: center; gap: 12px;
  font-size: 1.1rem; font-weight: 600;
}
.app-drawer-header .drawer-title i { color: var(--highlight); font-size: 1.3rem; }
.app-drawer-close {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: var(--text); border: 1px solid var(--border);
  font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.app-drawer-close:hover { background: var(--highlight); color: #fff; border-color: var(--highlight); }

.app-drawer-body {
  flex: 1; position: relative; overflow: hidden;
}
.app-drawer-body iframe {
  width: 100%; height: 100%; border: none; display: block;
  background: #fff;
}

.app-drawer-back {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 0.9rem;
  transition: color var(--transition); cursor: pointer;
  background: none; border: none; padding: 4px 0;
}
.app-drawer-back:hover { color: var(--highlight); }

/* ---- PLAYGROUND CANVAS ---- */
.playground-overlay {
  position: fixed; inset: 0; z-index: 9995;
  background: rgba(0,0,0,0.8);
  opacity: 0; visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  display: flex; align-items: center; justify-content: center;
}
.playground-overlay.open { opacity: 1; visibility: visible; }

.playground-panel {
  width: 95vw; max-width: 1400px; height: 90vh;
  background: var(--bg-card);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.playground-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.playground-bar-left { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.playground-bar-left i { color: var(--highlight); }
.playground-bar-right { display: flex; gap: 8px; }

.playground-action-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--text); border: 1px solid var(--border);
  font-size: 0.85rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.playground-action-btn:hover { background: var(--highlight); color: #fff; border-color: var(--highlight); }

#playgroundFrame {
  flex: 1; width: 100%; border: none; display: block;
  background: #fff; border-radius: 0 0 var(--radius) var(--radius);
}

/* ---- CHAT PLAYGROUND CARD ---- */
.chat-playground-msg { max-width: 90% !important; }
.playground-card {
  background: var(--accent); border: 1px solid var(--highlight);
  border-radius: 10px; overflow: hidden;
}
.playground-card-header {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 10px 14px; background: rgba(233,69,96,0.15);
}
.playground-card-header i { color: var(--highlight); margin-right: 6px; }
.playground-open-btn {
  background: var(--highlight); color: #fff; border: none;
  padding: 5px 14px; border-radius: 6px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all var(--transition);
}
.playground-open-btn:hover { background: var(--highlight-light); transform: translateY(-1px); }

.chat-tool-call {
  background: var(--accent) !important; border-left: 3px solid var(--highlight);
  padding: 8px 14px !important; border-radius: 6px !important;
  font-size: 0.85rem; color: var(--text-muted);
}
.chat-tool-call i { color: var(--highlight); margin-right: 6px; }

/* ---- ADMIN ---- */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 260px; background: var(--primary); padding: 24px 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.admin-sidebar .brand { padding: 0 20px 24px; font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 10px; color: var(--text); }
.admin-sidebar .brand i { color: var(--highlight); }
.admin-sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px; color: var(--text-muted);
  transition: all var(--transition);
}
.admin-sidebar nav a:hover, .admin-sidebar nav a.active { background: var(--accent); color: var(--text); border-left: 3px solid var(--highlight); }

.admin-main { flex: 1; padding: 32px; background: var(--bg); overflow-y: auto; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; }
.admin-header h1 { font-size: 1.6rem; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { background: var(--primary-light); font-weight: 600; font-size: 0.88rem; color: var(--text-muted); text-transform: uppercase; }
.admin-table td { font-size: 0.92rem; }
.admin-table tr:hover td { background: var(--bg-card-hover); }
.admin-table .icon-cell i { font-size: 1.2rem; }

.admin-form { max-width: 700px; }
.admin-form .form-group { margin-bottom: 20px; }
.admin-form label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.admin-form input, .admin-form select, .admin-form textarea {
  width: 100%; background: var(--primary); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; color: var(--text); font-size: 0.95rem; outline: none;
}
.admin-form input:focus, .admin-form select:focus, .admin-form textarea:focus { border-color: var(--highlight); }
.admin-form textarea { min-height: 300px; resize: vertical; font-family: 'Fira Code', monospace; font-size: 0.88rem; }
.admin-form .form-actions { display: flex; gap: 12px; margin-top: 24px; }

/* ---- LOGIN ---- */
.login-wrapper { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; width: 100%; max-width: 400px; }
.login-box h2 { text-align: center; margin-bottom: 8px; }
.login-box .logo { text-align: center; font-size: 2.5rem; color: var(--highlight); margin-bottom: 16px; }
.login-box .form-group { margin-bottom: 16px; }

/* ---- TOAST ---- */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 10000;
  padding: 14px 24px; border-radius: 8px; font-size: 0.92rem; font-weight: 500;
  background: var(--highlight); color: #fff; transform: translateX(120%); transition: transform 0.3s ease;
}
.toast.show { transform: translateX(0); }
.toast.success { background: #28a745; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .hero h1 { font-size: 2rem; }
  .navbar-links { gap: 14px; font-size: 0.9rem; }
  .cards-grid { grid-template-columns: 1fr; }
  .features-grid { grid-template-columns: 1fr 1fr; }
  .chat-panel { width: calc(100vw - 32px); right: 16px; bottom: 90px; }
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; padding: 12px 0; }
  .admin-sidebar nav { display: flex; overflow-x: auto; }
  .admin-sidebar nav a { white-space: nowrap; padding: 8px 16px; }
  .app-drawer { transition: none; }
}