:root {
  --bg: #05060a;
  --bg-2: #0d1018;
  --panel: #121722;
  --panel-2: #181f2e;
  --text: #f5f8ff;
  --muted: #95a1b8;
  --accent: #4f8cff;
  --accent-2: #2d6bff;
  --border: #27324a;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  background: radial-gradient(
    circle at 8% 8%,
    #172744 0%,
    #0a0c12 40%,
    #05060a 100%
  );
  font-family: "Inter", "Cairo", "Segoe UI", Tahoma, sans-serif;
}

a {
  color: #9ec1ff;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition:
    transform 0.12s ease,
    opacity 0.12s ease;
}

button:hover {
  opacity: 0.92;
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: #232c3f;
}

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

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.error-text {
  color: #fda4af;
}

.brand-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(79, 140, 255, 0.2);
  border: 1px solid rgba(79, 140, 255, 0.5);
  color: #cde0ff;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.lang-switch {
  min-width: 56px;
}

.lang-switch.floating {
  position: fixed;
  top: 14px;
  inset-inline-end: 14px;
  z-index: 9;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(520px, 100%);
  background: linear-gradient(
    180deg,
    rgba(18, 23, 34, 0.96),
    rgba(13, 16, 24, 0.96)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
}

.auth-card h1 {
  margin: 12px 0 4px;
  font-size: 30px;
}

.auth-card p {
  margin: 0 0 16px;
}

.auth-card form {
  display: grid;
  gap: 10px;
}

.auth-card label {
  color: #d3dcf0;
  font-size: 14px;
}

.auth-card input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0c111b;
  color: var(--text);
  padding: 12px;
}

.auth-card input:focus,
.composer-form textarea:focus,
.inline-form input:focus,
.limit-input:focus,
select:focus {
  outline: 1px solid #3e7cf5;
  border-color: #3e7cf5;
}

.auth-footer {
  margin-top: 12px !important;
}

.chat-page {
  min-height: 100vh;
}

.chat-main {
  max-width: 1150px;
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 14px;
}

.ai-shell {
  backdrop-filter: blur(6px);
}

.chat-header {
  background: linear-gradient(
    180deg,
    rgba(18, 23, 34, 0.94),
    rgba(12, 16, 26, 0.94)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.chat-header h1 {
  margin: 8px 0 2px;
  font-size: 28px;
}

.header-credit {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.header-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  min-width: 200px;
  background: #111726;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.menu-credit {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.menu-link {
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  background: #232c3f;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.menu-link:hover {
  text-decoration: none;
  opacity: 0.94;
}

.chat-messages {
  background: linear-gradient(
    180deg,
    rgba(15, 19, 29, 0.92),
    rgba(10, 12, 18, 0.95)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 62vh;
  max-height: 68vh;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  border: 1px solid #30405e;
  border-radius: 14px;
  background: var(--panel-2);
  padding: 12px 14px;
  max-width: min(880px, 100%);
}

.message.user {
  align-self: flex-end;
  background: #112a50;
  border-color: #355b98;
}

.message-role {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.message-content pre {
  overflow-x: auto;
  border-radius: 10px;
  padding: 10px;
}

.composer {
  background: linear-gradient(
    180deg,
    rgba(18, 23, 34, 0.96),
    rgba(12, 16, 26, 0.96)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.file-label {
  cursor: pointer;
  background: #222c3f;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
}

.file-input-hidden {
  display: none;
}

.files-label {
  color: var(--muted);
  font-size: 13px;
}

.composer-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.composer-form textarea {
  background: #0c111b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  resize: vertical;
}

.admin-page {
  max-width: 1240px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 14px;
}

.site-footer {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.site-footer a {
  color: #acc8ff;
}

.auth-footer-line {
  position: fixed;
  bottom: 10px;
  inset-inline: 0;
}

.admin-header {
  background: linear-gradient(
    180deg,
    rgba(18, 23, 34, 0.96),
    rgba(12, 16, 26, 0.96)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.admin-header h1 {
  margin: 8px 0 2px;
}

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

.stat-card {
  background: linear-gradient(
    180deg,
    rgba(18, 23, 34, 0.96),
    rgba(12, 16, 26, 0.96)
  );
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

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

.stat-card p {
  margin: 12px 0 0;
  font-size: 24px;
  font-weight: 800;
}

.admin-panel {
  margin-top: 12px;
  background: linear-gradient(
    180deg,
    rgba(18, 23, 34, 0.96),
    rgba(12, 16, 26, 0.96)
  );
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: start;
  border-bottom: 1px solid var(--border);
  padding: 10px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.inline-form input,
select,
.limit-input {
  background: #0c111b;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px;
}

@media (max-width: 980px) {
  .chat-main,
  .admin-page {
    padding: 10px;
  }

  .chat-header,
  .admin-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .account-menu {
    inset-inline-end: auto;
    inset-inline-start: 0;
    width: 100%;
  }

  .chat-header h1,
  .admin-header h1 {
    font-size: 24px;
  }

  .chat-messages {
    min-height: 56vh;
    max-height: 62vh;
    padding: 12px;
  }

  .composer-form {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

  button,
  .inline-form input,
  select,
  .limit-input,
  .auth-card input {
    min-height: 44px;
  }
}
