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

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --bg4: #30363d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --primary: #3fb950;
  --primary-dim: #238636;
  --primary-bg: rgba(63,185,80,.12);
  --accent: #58a6ff;
  --accent-bg: rgba(88,166,255,.10);
  --danger: #f85149;
  --danger-bg: rgba(248,81,73,.12);
  --warning: #e3b341;
  --code-bg: #161b22;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 260px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

.hidden { display: none !important; }

/* ─────────────── AUTH ─────────────── */
#auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.auth-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 40%, rgba(63,185,80,.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 70%, rgba(88,166,255,.10) 0%, transparent 50%),
              var(--bg);
}
.auth-container {
  position: relative; z-index: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  width: 100%; max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.logo-icon { font-size: 2.5rem; margin-bottom: 8px; }
.auth-logo h1 { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.auth-logo p { color: var(--text2); font-size: .875rem; margin-top: 4px; }

.auth-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1; padding: 10px; border: none; background: transparent;
  color: var(--text2); cursor: pointer; font-size: .9rem; font-family: var(--font);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all .2s;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .8rem; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select, .field textarea {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 10px 12px; font-size: .9rem; font-family: var(--font);
  outline: none; transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 70px; }
.field select option { background: var(--bg3); }

.form-error {
  background: var(--danger-bg); border: 1px solid var(--danger);
  border-radius: var(--radius); padding: 10px 12px;
  color: var(--danger); font-size: .875rem;
}

.btn-primary {
  background: var(--primary); color: #000; border: none; border-radius: var(--radius);
  padding: 11px 20px; font-size: .9rem; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: opacity .2s, transform .1s;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: scale(.98); }
.btn-primary.full-width { width: 100%; }

/* ─────────────── APP LAYOUT ─────────────── */
#app {
  display: flex; height: 100vh; overflow: hidden;
}

/* ─────────────── SIDEBAR ─────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-top {
  padding: 16px 12px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px 12px;
}
.logo-icon-sm { font-size: 1.2rem; }
.logo-text { font-weight: 700; font-size: .95rem; color: var(--primary); }
.btn-new-chat {
  width: 100%; background: var(--primary-bg);
  border: 1px solid var(--primary-dim); border-radius: var(--radius);
  color: var(--primary); padding: 9px 12px; font-size: .85rem;
  font-weight: 500; cursor: pointer; font-family: var(--font);
  transition: background .2s;
}
.btn-new-chat:hover { background: rgba(63,185,80,.2); }

.sidebar-conversations {
  flex: 1; overflow-y: auto; padding: 12px 8px;
}
.conv-section-title {
  font-size: .7rem; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 0 8px 8px;
}
.conv-item {
  padding: 10px 12px; border-radius: var(--radius);
  cursor: pointer; transition: background .15s;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 2px;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); }
.conv-item-title {
  flex: 1; font-size: .84rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item-del {
  opacity: 0; border: none; background: transparent;
  color: var(--danger); cursor: pointer; padding: 2px 4px;
  font-size: .85rem; border-radius: 4px; transition: opacity .15s;
}
.conv-item:hover .conv-item-del { opacity: 1; }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px;
}
.daily-stats { margin-bottom: 12px; }
.stats-label { font-size: .72rem; color: var(--text3); margin-bottom: 6px; }
.stats-bar-wrap { background: var(--bg3); border-radius: 4px; height: 4px; margin-bottom: 4px; overflow: hidden; }
.stats-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width .5s; }
.stats-count { font-size: .75rem; color: var(--text2); text-align: right; }

.user-info {
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px; background: var(--primary-dim);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-name { flex: 1; font-size: .85rem; font-weight: 500; color: var(--text); }
.btn-logout {
  border: none; background: transparent; color: var(--text3);
  cursor: pointer; font-size: 1rem; padding: 4px 6px;
  border-radius: 4px; transition: color .2s;
}
.btn-logout:hover { color: var(--danger); }

/* ─────────────── MAIN CONTENT ─────────────── */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

/* ─────────────── WELCOME ─────────────── */
.welcome-screen {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 20px; text-align: center;
}
.welcome-logo { font-size: 3.5rem; margin-bottom: 16px; }
.welcome-screen h2 { font-size: 1.8rem; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.welcome-screen p { color: var(--text2); font-size: .95rem; line-height: 1.6; margin-bottom: 24px; }

.welcome-cores { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 32px; }
.core-badge {
  padding: 6px 14px; border-radius: 20px; font-size: .78rem;
  font-weight: 600; letter-spacing: .02em;
}
.core-badge.pmmp   { background: rgba(63,185,80,.15);  color: var(--primary);  border: 1px solid rgba(63,185,80,.3); }
.core-badge.nukkit { background: rgba(88,166,255,.12); color: var(--accent);   border: 1px solid rgba(88,166,255,.3); }
.core-badge.power  { background: rgba(227,179,65,.12); color: var(--warning);  border: 1px solid rgba(227,179,65,.3); }
.core-badge.cloud  { background: rgba(248,81,73,.10);  color: #ff7b72;          border: 1px solid rgba(248,81,73,.3); }

.welcome-suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 600px; }
.suggestion-btn {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
  color: var(--text); font-size: .84rem; cursor: pointer;
  font-family: var(--font); transition: border-color .2s, background .2s;
}
.suggestion-btn:hover { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }

/* ─────────────── CHAT ─────────────── */
.chat-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-title { font-size: .95rem; font-weight: 600; color: var(--text); }

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

.message {
  display: flex; gap: 12px; max-width: 100%; animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.message-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; margin-top: 2px;
}
.message.user .message-avatar { background: var(--primary-dim); color: #fff; margin-left: auto; order: 1; }
.message.assistant .message-avatar { background: var(--bg3); border: 1px solid var(--border); }
.message.assistant .message-avatar::after { content: '⛏'; font-size: .7rem; }

.message.user { flex-direction: row-reverse; }
.message-bubble {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px 16px;
  max-width: min(680px, 80%);
  font-size: .9rem; line-height: 1.65;
}
.message.user .message-bubble {
  background: var(--primary-bg); border-color: var(--primary-dim); color: var(--text);
}

/* Markdown in messages */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  color: var(--text); margin: 12px 0 6px; font-weight: 600;
}
.message-bubble p { margin: 6px 0; }
.message-bubble strong { color: var(--primary); }
.message-bubble ul, .message-bubble ol { margin: 8px 0 8px 20px; }
.message-bubble li { margin: 3px 0; }
.message-bubble table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: .84rem; }
.message-bubble th, .message-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.message-bubble th { background: var(--bg3); color: var(--text2); }
.message-bubble code:not(pre code) {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px;
  font-family: var(--mono); font-size: .82rem; color: var(--accent);
}
.message-bubble pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; overflow-x: auto;
  margin: 10px 0; position: relative;
}
.message-bubble pre code {
  font-family: var(--mono); font-size: .82rem; color: var(--text);
  background: none; border: none; padding: 0;
}
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg3); border: 1px solid var(--border);
  border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
  padding: 6px 14px;
}
.code-lang { font-size: .75rem; color: var(--text3); font-family: var(--mono); }
.copy-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 4px; color: var(--text2); cursor: pointer;
  padding: 3px 8px; font-size: .72rem; transition: all .2s; font-family: var(--font);
}
.copy-btn:hover { color: var(--primary); border-color: var(--primary); }
.code-block-wrap pre { border-radius: 0 0 var(--radius) var(--radius); margin-top: 0; }

.download-card {
  background: var(--primary-bg); border: 1px solid var(--primary-dim);
  border-radius: var(--radius); padding: 14px 16px; margin-top: 12px;
  display: flex; align-items: center; gap: 12px;
}
.download-card svg { color: var(--primary); flex-shrink: 0; }
.download-card-info { flex: 1; }
.download-card-title { font-weight: 600; color: var(--primary); font-size: .9rem; }
.download-card-sub { color: var(--text2); font-size: .8rem; margin-top: 2px; }
.btn-download {
  background: var(--primary); color: #000;
  border: none; border-radius: var(--radius); padding: 8px 16px;
  font-size: .84rem; font-weight: 600; cursor: pointer;
  font-family: var(--font); text-decoration: none; transition: opacity .2s;
  display: inline-block;
}
.btn-download:hover { opacity: .85; }

.typing-indicator {
  display: flex; gap: 5px; align-items: center; padding: 6px 0;
}
.typing-indicator span {
  width: 7px; height: 7px; background: var(--text3); border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(1); opacity: .5; }
  40% { transform: scale(1.3); opacity: 1; }
}

.progress-message {
  background: var(--accent-bg); border: 1px solid rgba(88,166,255,.25);
  border-radius: var(--radius); padding: 10px 14px; font-size: .84rem;
  color: var(--accent); display: flex; align-items: center; gap: 8px;
}
.progress-spinner {
  width: 14px; height: 14px; border: 2px solid rgba(88,166,255,.3);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .6s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────── INPUT AREA ─────────────── */
.input-area {
  border-top: 1px solid var(--border);
  background: var(--bg2); padding: 16px 20px;
}
.input-mode-tabs {
  display: flex; gap: 6px; margin-bottom: 12px;
}
.mode-tab {
  padding: 6px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text2); font-size: .8rem; cursor: pointer;
  font-family: var(--font); transition: all .2s;
}
.mode-tab.active {
  background: var(--primary-bg); border-color: var(--primary-dim); color: var(--primary);
}
.mode-tab:hover:not(.active) { border-color: var(--text3); color: var(--text); }

.input-panel { display: flex; flex-direction: column; gap: 12px; }

.textarea-wrap { position: relative; }
#chat-input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-lg); color: var(--text); padding: 12px 52px 12px 16px;
  font-size: .9rem; font-family: var(--font); outline: none;
  resize: none; max-height: 160px; min-height: 48px; overflow-y: auto;
  line-height: 1.5; transition: border-color .2s;
}
#chat-input:focus { border-color: var(--primary); }
.send-btn {
  position: absolute; right: 10px; bottom: 10px;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #000; transition: opacity .2s;
}
.send-btn svg { width: 15px; height: 15px; }
.send-btn:hover { opacity: .85; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

.gen-form, .upload-form { display: flex; flex-direction: column; gap: 10px; }
.gen-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gen-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.limit-info { font-size: .78rem; color: var(--text2); }
.btn-generate {
  background: var(--primary); color: #000;
  border: none; border-radius: var(--radius); padding: 10px 20px;
  font-size: .88rem; font-weight: 600; cursor: pointer;
  font-family: var(--font); display: flex; align-items: center; gap: 8px;
  transition: opacity .2s;
}
.btn-generate svg { width: 16px; height: 16px; }
.btn-generate:hover { opacity: .9; }
.btn-generate:disabled { opacity: .4; cursor: not-allowed; }

.upload-drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-drop-zone:hover, .upload-drop-zone.drag-over {
  border-color: var(--primary); background: var(--primary-bg);
}
.drop-content { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text2); }
.drop-content svg { width: 28px; height: 28px; }
.drop-content span { font-size: .85rem; }

/* ─────────────── SCROLLBAR ─────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
