/* =====================================================================
   AniChat AI — visual identity
   Palette:  #0B0D17 (void)  #12152A (panel)  #1B1F3B (panel-raised)
             #8B5CF6 -> #22D3EE (signal gradient, violet to cyan)
             #ECEDF8 (text)  #8A90B8 (muted)  #F2555A (danger) #34D399 (ok)
   Type: 'Sora' for display/headings, 'Inter' for body & UI
   Signature: the "signal" gradient thread — a 2px vertical gradient rule
   that runs down the left edge of every AI response, like a live feed.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@500;600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --void: #0B0D17;
  --panel: #12152A;
  --panel-raised: #1B1F3B;
  --border: #262B4D;
  --text: #ECEDF8;
  --muted: #8A90B8;
  --muted-2: #5C6288;
  --violet: #8B5CF6;
  --cyan: #22D3EE;
  --danger: #F2555A;
  --ok: #34D399;
  --amber: #FBBF24;
  --signal: linear-gradient(180deg, var(--violet), var(--cyan));
  --signal-h: linear-gradient(90deg, var(--violet), var(--cyan));
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--void);
  background-image:
    radial-gradient(ellipse 900px 500px at 15% -10%, rgba(139,92,246,0.16), transparent 60%),
    radial-gradient(ellipse 700px 500px at 100% 0%, rgba(34,211,238,0.10), transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand, .display { font-family: 'Sora', 'Inter', sans-serif; letter-spacing: -0.01em; }

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: 'JetBrains Mono', monospace; }

::selection { background: rgba(139,92,246,0.35); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------
   Auth pages (login/register)
   --------------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--signal-h);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.brand-mark .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--signal-h);
  box-shadow: 0 0 14px rgba(139,92,246,0.7);
}

.brand-mark span { font-weight: 700; font-size: 18px; }

.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }

.field input {
  width: 100%;
  background: var(--void);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--violet); outline: none; }

.remember-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; font-size: 13px; color: var(--muted); }
.remember-row label { display: flex; align-items: center; gap: 7px; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  background: var(--signal-h);
  color: #08090F;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:hover { opacity: 0.92; }
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger { background: var(--danger); color: #fff; }
.btn-outline-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }

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

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 18px;
  border: 1px solid;
}
.alert-error { background: rgba(242,85,90,0.1); border-color: rgba(242,85,90,0.4); color: #FF9A9E; }
.alert-ok { background: rgba(52,211,153,0.1); border-color: rgba(52,211,153,0.4); color: #7CF0C4; }

/* ---------------------------------------------------------------
   App shell
   --------------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

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

.new-chat-btn {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
}
.new-chat-btn:hover { border-color: var(--violet); }

.search-box { margin-top: 10px; position: relative; }
.search-box input {
  width: 100%;
  background: var(--void);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px 8px 30px;
  color: var(--text); font-size: 13px;
}
.search-box svg { position: absolute; left: 9px; top: 9px; opacity: 0.5; }

.conv-list { flex: 1; overflow-y: auto; padding: 10px 10px; }
.conv-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); padding: 10px 8px 6px; }

.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 2px;
  position: relative;
  group: item;
}
.conv-item:hover { background: var(--panel-raised); color: var(--text); }
.conv-item.active { background: var(--panel-raised); color: var(--text); }
.conv-item.active::before {
  content: '';
  position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px;
  background: var(--signal); border-radius: 2px;
}
.conv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-pin { opacity: 0.7; font-size: 12px; }
.conv-actions { display: none; gap: 4px; }
.conv-item:hover .conv-actions { display: flex; }
.conv-actions button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px 4px; font-size: 12px; }
.conv-actions button:hover { color: var(--text); }

.sidebar-bottom { border-top: 1px solid var(--border); padding: 14px 16px; }
.usage-bar-wrap { margin-bottom: 12px; }
.usage-label { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.usage-track { height: 5px; background: var(--void); border-radius: 4px; overflow: hidden; }
.usage-fill { height: 100%; background: var(--signal-h); border-radius: 4px; transition: width .3s; }

.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--signal-h);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #08090F;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.badge-premium {
  background: var(--signal-h); color: #08090F; font-weight: 700;
  font-size: 10px; padding: 1px 6px; border-radius: 20px; text-transform: uppercase; letter-spacing: .03em;
}
.user-chip .menu-btn { background: none; border: none; color: var(--muted); cursor: pointer; }

/* ---------------------------------------------------------------
   Chat area
   --------------------------------------------------------------- */
.chat-main { display: flex; flex-direction: column; height: 100vh; min-width: 0; }

.chat-topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}
.chat-topbar .conv-name { font-weight: 600; font-size: 14.5px; }
.chat-topbar .model-pill {
  font-size: 11.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 20px;
}

.messages { flex: 1; overflow-y: auto; padding: 28px 0 10px; }
.messages-inner { max-width: 760px; margin: 0 auto; padding: 0 24px; }

.msg { display: flex; gap: 14px; margin-bottom: 26px; }
.msg .avatar-sm { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.msg.user .avatar-sm { background: var(--panel-raised); border: 1px solid var(--border); color: var(--text); }
.msg.assistant .avatar-sm { background: var(--signal-h); color: #08090F; }

.msg-body { flex: 1; min-width: 0; padding-top: 4px; }
.msg.assistant .msg-body { border-left: 2px solid transparent; border-image: var(--signal) 1; padding-left: 14px; }
.msg-role { font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.msg-text { font-size: 14.5px; line-height: 1.65; white-space: pre-wrap; word-wrap: break-word; }
.msg-text p { margin: 0 0 12px; }
.msg-text pre {
  background: var(--void); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; overflow-x: auto; margin: 10px 0; position: relative;
}
.msg-text code { font-size: 13px; }
.msg-text :not(pre) > code { background: var(--panel-raised); padding: 2px 5px; border-radius: 4px; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; background: var(--panel-raised); border: 1px solid var(--border);
  color: var(--muted); font-size: 11px; padding: 3px 8px; border-radius: 6px; cursor: pointer;
}
.copy-btn:hover { color: var(--text); }

.msg-actions { display: flex; gap: 10px; margin-top: 8px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
}
.msg-actions button:hover { color: var(--text); }

.typing-cursor { display: inline-block; width: 7px; height: 15px; background: var(--cyan); margin-left: 2px; animation: blink 1s step-start infinite; vertical-align: text-bottom; }
@keyframes blink { 50% { opacity: 0; } }

.limit-banner {
  max-width: 760px; margin: 0 auto 16px; padding: 12px 16px;
  background: rgba(251,191,36,0.08); border: 1px solid rgba(251,191,36,0.3);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--amber);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.limit-banner a.upgrade-link { color: var(--amber); font-weight: 700; text-decoration: underline; }

.composer-wrap { padding: 14px 24px 22px; border-top: 1px solid var(--border); }
.composer {
  max-width: 760px; margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  display: flex; align-items: flex-end; gap: 10px;
  transition: border-color .15s;
}
.composer:focus-within { border-color: var(--violet); }

.composer textarea {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-family: inherit; font-size: 14.5px; resize: none; max-height: 200px;
  padding: 8px 0; line-height: 1.5;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--muted-2); }

.send-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: var(--signal-h); color: #08090F; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.stop-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-raised); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

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

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; text-align: center; color: var(--muted); padding: 40px; }
.empty-state .signal-dot { width: 44px; height: 44px; border-radius: 12px; background: var(--signal-h); margin-bottom: 16px; }
.empty-state h2 { color: var(--text); margin: 0 0 6px; }
.suggestion-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; max-width: 480px; }
.suggestion-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; text-align: left; font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.suggestion-card:hover { border-color: var(--violet); color: var(--text); }

/* ---------------------------------------------------------------
   Pricing / upgrade page
   --------------------------------------------------------------- */
.pricing-wrap { max-width: 1080px; margin: 0 auto; padding: 60px 24px; }
.pricing-head { text-align: center; margin-bottom: 44px; }
.pricing-head h1 { font-size: 32px; margin-bottom: 8px; }
.pricing-head p { color: var(--muted); }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; }
.plan-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 20px; position: relative; display: flex; flex-direction: column;
}
.plan-card.featured { border-color: var(--violet); box-shadow: 0 0 0 1px var(--violet), var(--shadow); }
.plan-card.featured::before {
  content: 'MOST POPULAR'; position: absolute; top: -11px; left: 50%; transform: translateX(-50%);
  background: var(--signal-h); color: #08090F; font-size: 10px; font-weight: 800; letter-spacing: .05em;
  padding: 4px 10px; border-radius: 20px;
}
.plan-name { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.plan-price { font-size: 30px; font-weight: 800; margin: 10px 0 2px; font-family: 'Sora', sans-serif; }
.plan-price small { font-size: 13px; color: var(--muted); font-weight: 500; }
.plan-features { list-style: none; padding: 0; margin: 18px 0; flex: 1; }
.plan-features li { font-size: 13px; color: var(--muted); padding: 6px 0; display: flex; gap: 8px; }
.plan-features li::before { content: '✓'; color: var(--ok); font-weight: 700; }

.payment-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.payment-modal-overlay.open { display: flex; }
.payment-modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.method-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.method-tab {
  flex: 1; text-align: center; padding: 9px; border-radius: var(--radius-sm); font-size: 12.5px;
  border: 1px solid var(--border); cursor: pointer; color: var(--muted);
}
.method-tab.active { border-color: var(--violet); color: var(--text); background: var(--panel-raised); }

/* ---------------------------------------------------------------
   Admin
   --------------------------------------------------------------- */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.admin-nav { background: var(--panel); border-right: 1px solid var(--border); padding: 20px 14px; }
.admin-nav a { display: block; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13.5px; margin-bottom: 2px; }
.admin-nav a:hover, .admin-nav a.active { background: var(--panel-raised); color: var(--text); text-decoration: none; }
.admin-content { padding: 28px 32px; overflow-y: auto; }
.admin-content h1 { font-size: 22px; margin-bottom: 22px; }

.card-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 24px; font-weight: 800; font-family: 'Sora', sans-serif; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
th, td { text-align: left; padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; background: var(--panel-raised); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
thead tr:first-child th:first-child { border-top-left-radius: var(--radius); }
thead tr:first-child th:last-child { border-top-right-radius: var(--radius); }
tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
/* allow row-menu dropdowns to escape the table's bounding box */
td { position: relative; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.pill-pending { background: rgba(251,191,36,0.12); color: var(--amber); }
.pill-approved, .pill-active { background: rgba(52,211,153,0.12); color: var(--ok); }
.pill-rejected, .pill-error, .pill-disabled { background: rgba(242,85,90,0.12); color: var(--danger); }

.inline-actions { display: flex; gap: 8px; }
.btn-sm { padding: 6px 12px; font-size: 12px; width: auto; border-radius: 7px; }

/* Three-dot row action menu */
.row-menu { position: relative; display: inline-block; }
.row-menu-trigger {
  background: none; border: 1px solid transparent; color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px; cursor: pointer;
  font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.row-menu-trigger:hover { background: var(--panel-raised); color: var(--text); border-color: var(--border); }
.row-menu-dropdown {
  display: none;
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 190px; z-index: 40; padding: 6px; overflow: hidden;
}
.row-menu.open .row-menu-dropdown { display: block; }
.row-menu-dropdown form { margin: 0; }
.row-menu-dropdown button,
.row-menu-dropdown .row-menu-item {
  width: 100%; text-align: left; background: none; border: none; color: var(--text);
  font-size: 12.5px; padding: 8px 10px; border-radius: 7px; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.row-menu-dropdown button:hover, .row-menu-dropdown .row-menu-item:hover { background: var(--void); }
.row-menu-dropdown button.danger { color: var(--danger); }
.row-menu-dropdown .row-menu-divider { height: 1px; background: var(--border); margin: 5px 4px; }
.row-menu-dropdown select {
  width: 100%; background: var(--void); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; margin-bottom: 6px;
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; width: 280px; height: 100vh; transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.5); }
  .admin-shell { grid-template-columns: 1fr; }
  .admin-nav { display: none; }
  .mobile-menu-btn, .mobile-new-chat-btn { display: inline-flex !important; }
  .sidebar-backdrop.open { display: block; }
}

.mobile-menu-btn, .mobile-new-chat-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; flex-shrink: 0;
}
.mobile-menu-btn:hover, .mobile-new-chat-btn:hover { border-color: var(--violet); }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 55;
}
.sidebar-backdrop.open { display: block; }
