/* ==========================================
   ShadowClaw AI Control Center 🖤
   Complete Style System
   ========================================== */

/* === CSS Variables / Design Tokens === */
:root {
  --primary: #1a0533;
  --secondary: #2d1b69;
  --accent: #7c3aed;
  --accent-hover: #8b5cf6;
  --accent-light: #a78bfa;
  --accent-glow: #c4b5fd;
  --blue-accent: #667eea;
  --bg-base: #08081a;
  --bg-surface: #0d0d24;
  --bg-card: #111128;
  --bg-elevated: #16163a;
  --bg-hover: rgba(124, 58, 237, 0.08);
  --border: rgba(196, 181, 253, 0.12);
  --border-hover: rgba(196, 181, 253, 0.25);
  --text-primary: #e0e7ff;
  --text-secondary: #c4b5fd;
  --text-muted: #8b8fa3;
  --text-dim: #5c6080;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-card: 0 4px 24px rgba(26, 5, 51, 0.4);
  --shadow-glow: 0 0 40px rgba(124, 58, 237, 0.08);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-arabic: 'Cairo', 'Segoe UI', system-ui, sans-serif;
  --sidebar-width: 260px;
  --header-height: 60px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font-arabic);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  direction: rtl;
}
a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--accent-glow); }
::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* === Typography === */
h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: 1.3; }
h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); }
h2 { font-size: clamp(1.2rem, 3vw, 1.6rem); }

/* === Login Screen === */
.login-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-base);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(124,58,237,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(102,126,234,0.06) 0%, transparent 50%);
}
.login-card {
  width: min(420px, 92vw); padding: 40px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card), var(--shadow-glow);
  text-align: center;
  position: relative; overflow: hidden;
}
.login-card::before {
  content: ''; position: absolute; top: -80px; right: -80px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(124,58,237,0.1), transparent 70%);
  border-radius: 50%;
}
.login-logo { width: 72px; height: 72px; margin: 0 auto 16px; display: block; }
.login-title { font-size: 1.5rem; color: var(--text-primary); margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 28px; }
.login-error { color: var(--danger); font-size: 0.85rem; margin-top: 12px; display: none; }
.login-error.show { display: block; }

.form-group { margin-bottom: 16px; text-align: right; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 6px; font-weight: 600; }
.form-input {
  width: 100%; padding: 12px 16px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); color: var(--text-primary);
  font-size: 0.95rem; font-family: inherit;
  transition: var(--transition); outline: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); }
.form-input::placeholder { color: var(--text-dim); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: var(--radius-md);
  font-size: 0.95rem; font-weight: 700; font-family: inherit;
  cursor: pointer; transition: var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--secondary));
  color: #fff; width: 100%;
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), var(--accent));
  box-shadow: 0 0 24px rgba(124,58,237,0.3); transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); border: none; cursor: pointer; transition: var(--transition); }
.btn-icon:hover { background: var(--bg-hover); color: var(--accent-light); }

/* === App Layout === */
.app-layout { display: none; height: 100vh; }
.app-layout.active { display: flex; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 100;
  transition: var(--transition);
}
.sidebar-header {
  padding: 16px 20px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border); height: var(--header-height);
}
.sidebar-logo { width: 36px; height: 36px; border-radius: var(--radius-sm); }
.sidebar-brand { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.sidebar-brand span { color: var(--accent-light); }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: var(--radius-md);
  color: var(--text-muted); cursor: pointer; transition: var(--transition);
  font-size: 0.9rem; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-secondary); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(45,27,105,0.15));
  color: var(--accent-light); font-weight: 600;
}
.nav-item .nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.nav-item .nav-badge {
  margin-right: auto; background: var(--accent); color: #fff;
  font-size: 0.7rem; padding: 2px 8px; border-radius: 10px;
  font-weight: 700; min-width: 20px; text-align: center;
}

.sidebar-footer {
  padding: 12px 10px; border-top: 1px solid var(--border);
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-md);
  background: var(--bg-card); cursor: pointer;
  transition: var(--transition);
}
.user-card:hover { background: var(--bg-elevated); }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--blue-accent));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem; color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: 0.75rem; color: var(--text-muted); }

/* Main Content */
.main-content {
  flex: 1; margin-right: var(--sidebar-width);
  display: flex; flex-direction: column;
  min-width: 0;
}
.main-header {
  height: var(--header-height);
  padding: 0 24px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(8,8,26,0.8); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
}
.header-title { font-size: 1rem; font-weight: 600; flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; }

/* Page Content */
.page-content {
  flex: 1; padding: 24px; overflow-y: auto;
}
.page { display: none; }
.page.active { display: block; }

/* === Dashboard Widgets === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  padding: 20px; border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: var(--transition); position: relative; overflow: hidden;
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow-card); }
.stat-card::before {
  content: ''; position: absolute; top: -30px; left: -30px;
  width: 80px; height: 80px; border-radius: 50%;
  opacity: 0.06;
}
.stat-card.purple::before { background: var(--accent); }
.stat-card.blue::before { background: var(--blue-accent); }
.stat-card.green::before { background: var(--success); }
.stat-card.gold::before { background: var(--warning); }

.stat-icon { font-size: 1.5rem; margin-bottom: 12px; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.stat-change { font-size: 0.8rem; margin-top: 8px; padding: 2px 8px; border-radius: 4px; display: inline-block; }
.stat-change.up { color: var(--success); background: rgba(34,197,94,0.1); }
.stat-change.down { color: var(--danger); background: rgba(239,68,68,0.1); }

/* === Cards === */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  margin-bottom: 16px;
}
.card-header {
  padding: 16px 20px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border); gap: 12px;
}
.card-title { flex: 1; font-size: 0.95rem; font-weight: 600; }
.card-body { padding: 20px; }

/* === Chat View === */
.chat-container {
  display: flex; flex-direction: column; height: 100%;
  max-width: 900px; margin: 0 auto; width: 100%;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 0;
  display: flex; flex-direction: column; gap: 12px;
}
.msg {
  display: flex; gap: 10px; max-width: 85%;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
}
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--blue-accent)); }
.msg.assistant .msg-avatar { background: var(--bg-elevated); border: 1px solid var(--border); }
.msg-bubble {
  padding: 10px 16px; border-radius: var(--radius-lg);
  font-size: 0.9rem; line-height: 1.7;
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--accent), var(--secondary));
  color: #fff; border-bottom-left-radius: var(--radius-sm);
}
.msg.assistant .msg-bubble {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); border-bottom-right-radius: var(--radius-sm);
}
.msg-time { font-size: 0.7rem; color: var(--text-dim); margin-top: 4px; }
.msg.user .msg-time { text-align: left; }

.chat-input-area {
  display: flex; gap: 8px; padding: 12px 0;
  border-top: 1px solid var(--border); margin-top: auto;
}
.chat-input {
  flex: 1; padding: 12px 16px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); color: var(--text-primary);
  font-size: 0.95rem; font-family: inherit; outline: none;
  resize: none; min-height: 48px; max-height: 150px;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--secondary));
  border: none; color: #fff; font-size: 1.2rem;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-send:hover { transform: scale(1.05); box-shadow: 0 0 20px rgba(124,58,237,0.3); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* === Teams View === */
.teams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.team-card {
  padding: 20px; border-radius: var(--radius-lg);
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; transition: var(--transition);
}
.team-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-card); }
.team-card .team-emoji { font-size: 2rem; margin-bottom: 12px; }
.team-card .team-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.team-card .team-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 12px; }
.team-card .team-count { font-size: 0.8rem; color: var(--text-dim); }
.member-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.member-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--bg-surface); font-size: 0.85rem;
}

/* === Control Panel === */
.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.control-item {
  padding: 16px; border-radius: var(--radius-md);
  background: var(--bg-surface); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: var(--transition);
}
.control-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.control-icon { font-size: 1.3rem; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--bg-card); }
.control-info { flex: 1; }
.control-name { font-size: 0.9rem; font-weight: 600; }
.control-status { font-size: 0.8rem; color: var(--text-muted); }

/* === Toggle Switch === */
.toggle {
  width: 44px; height: 24px; border-radius: 12px;
  background: var(--text-dim); cursor: pointer;
  position: relative; transition: var(--transition);
  flex-shrink: 0;
}
.toggle.active { background: var(--accent); }
.toggle::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: var(--transition);
}
.toggle.active::after { right: 22px; }

/* === Badges === */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-accent { background: rgba(124,58,237,0.15); color: var(--accent-light); }

/* === Quick Actions === */
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.action-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 20px;
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 0.85rem;
  cursor: pointer; transition: var(--transition);
}
.action-chip:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent-light); }

/* === System Logs === */
.log-viewer {
  background: #050510; border-radius: var(--radius-md);
  padding: 16px; font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.8rem; max-height: 300px; overflow-y: auto;
  direction: ltr; text-align: left;
}
.log-line { padding: 2px 0; color: var(--text-dim); }
.log-line.info { color: var(--info); }
.log-line.success { color: var(--success); }
.log-line.warn { color: var(--warning); }
.log-line.error { color: var(--danger); }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  width: min(600px, 100%); max-height: 80vh;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-xl); overflow: hidden;
  animation: modalIn 0.3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { padding: 16px 20px; display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.modal-title { flex: 1; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.3rem; cursor: pointer; padding: 4px; }
.modal-body { padding: 20px; overflow-y: auto; max-height: calc(80vh - 120px); }

/* === Loading === */
.loading-spinner {
  width: 24px; height: 24px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-dots::after { content: '...'; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots { 0%, 20% { content: ''; } 40% { content: '.'; } 60% { content: '..'; } 80%, 100% { content: '...'; } }

/* === Empty State === */
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { color: var(--text-muted); }

/* === Auth / Settings === */
.access-log {
  display: flex; flex-direction: column; gap: 6px;
}
.access-entry {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--bg-surface); font-size: 0.85rem;
}
.access-entry .entry-time { color: var(--text-dim); font-size: 0.75rem; min-width: 60px; }
.access-entry .entry-action { flex: 1; }
.access-entry .entry-ip { color: var(--text-muted); font-size: 0.8rem; }

/* === Mobile Sidebar Overlay === */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,0.5);
}
.sidebar-overlay.show { display: block; }

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    right: -280px; transition: right 0.3s ease;
  }
  .sidebar.open { right: 0; box-shadow: 0 0 40px rgba(0,0,0,0.5); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-right: 0; }
  .menu-toggle { display: flex; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .teams-grid { grid-template-columns: 1fr; }
  .control-grid { grid-template-columns: 1fr; }
  .msg { max-width: 95%; }
  .login-card { padding: 28px 20px; }
  .chat-container { max-width: 100%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .header-title { font-size: 0.85rem; }
  .page-content { padding: 12px; }
  .stat-value { font-size: 1.4rem; }
}

/* === Badge Error === */
.badge-error {
  background: rgba(239,68,68,0.15);
  color: var(--danger, #ef4444);
  border: 1px solid rgba(239,68,68,0.25);
}

/* === API Key Cards === */
.api-key-card {
  transition: all 0.2s ease;
}
.api-key-card:hover {
  border-color: var(--border-hover, rgba(196,181,253,0.25));
  background: var(--bg-elevated, #16163a);
  box-shadow: 0 2px 12px rgba(124,58,237,0.1);
}

.api-key-card .btn-ghost {
  font-size: 0.78rem;
  padding: 4px 10px;
}

/* === Tablet / iPad === */
@media (min-width: 769px) and (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .teams-grid { grid-template-columns: repeat(2, 1fr); }
  .control-grid { grid-template-columns: repeat(2, 1fr); }
}
