/* ========================================
   PEN AI — Premium Dark Interface
   ======================================== */

:root {
  --bg: #080b14;
  --sidebar: #0c1120;
  --panel: #111a2d;
  --panel-hover: #18233b;
  --border: rgba(148, 163, 184, 0.13);
  --text: #f3f6ff;
  --muted: #8c9ab5;
  --blue: #438cff;
  --cyan: #50d8f5;
  --purple: #8871ff;
  --gradient: linear-gradient(135deg, #48d9f5, #397cff 55%, #9270ff);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

button,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.app {
  display: flex;
  width: 100%;
  height: 100dvh;
  min-height: 480px;
  overflow: hidden;
}

/* Sidebar */

.sidebar {
  width: 265px;
  min-width: 265px;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 16px;
  background: var(--sidebar);
  border-left: 1px solid var(--border);
  transition: transform 0.25s ease;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 7px;
  margin-bottom: 32px;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.8px;
}

.brand b,
.top-brand b {
  color: #78a6ff;
}

.logo,
.mini-logo {
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  background: var(--gradient);
  box-shadow: 0 0 24px rgba(61, 129, 255, 0.22);
}

.logo {
  width: 39px;
  height: 39px;
  border-radius: 13px;
  font-size: 25px;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 15px;
  margin-bottom: 29px;
  border: 1px solid rgba(89, 145, 255, 0.25);
  border-radius: 13px;
  background: linear-gradient(
    115deg,
    rgba(55, 111, 226, 0.19),
    rgba(126, 92, 255, 0.09)
  );
  transition: 0.2s;
}

.new-chat:hover {
  background: rgba(63, 119, 237, 0.22);
  border-color: rgba(89, 145, 255, 0.5);
}

.new-chat span {
  font-size: 21px;
  color: #82b2ff;
}

.side-label {
  padding: 0 11px;
  margin-bottom: 11px;
  color: #667590;
  font-size: 11px;
  letter-spacing: 1px;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  margin-bottom: 5px;
  text-align: right;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  transition: 0.2s;
}

.side-item span {
  width: 21px;
  font-size: 19px;
  text-align: center;
}

.side-item:hover,
.side-item.active {
  color: var(--text);
  background: rgba(65, 111, 208, 0.12);
}

.side-item.active {
  border-color: rgba(86, 133, 233, 0.13);
}

.sidebar-bottom {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: auto;
  padding: 15px 4px 3px;
  border-top: 1px solid var(--border);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  border-radius: 50%;
  background: linear-gradient(135deg, #263d66, #51408d);
  color: #dce8ff;
  font-weight: 700;
}

.user-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.user-info strong {
  font-size: 13px;
}

.user-info small {
  color: var(--muted);
  font-size: 11px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
}

.icon-btn:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.close-menu,
.menu-btn {
  display: none;
}

/* Main area */

.main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background:
    radial-gradient(
      ellipse at 50% 34%,
      rgba(31, 73, 145, 0.10),
      transparent 48%
    ),
    var(--bg);
}.topbar {
  height: 75px;
  min-height: 75px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  border-bottom: 1px solid var(--border);
}

.top-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 750;
}

.mini-logo {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  font-size: 18px;
}

#language {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

/* Chat */

.chat-area {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow-y: auto;
  padding: 30px 24px 20px;
  scrollbar-width: thin;
  scrollbar-color: #273650 transparent;
}

.welcome {
  width: 100%;
  max-width: 850px;
  margin: auto 0;
  padding: 28px 0;
  text-align: center;
}

.welcome-logo {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 25px;
  border: 1px solid rgba(99, 153, 255, 0.3);
  border-radius: 24px;
  background: linear-gradient(
    145deg,
    #172c54,
    #10172e 65%,
    #24204b
  );
  color: #80caff;
  font-size: 48px;
  font-weight: 800;
  box-shadow:
    0 0 45px rgba(48, 114, 255, 0.12),
    inset 0 1px rgba(255, 255, 255, 0.07);
}

.eyebrow {
  margin: 0 0 14px;
  color: #83a9ef;
  font-size: 12px;
  letter-spacing: 1.4px;
}

.welcome h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 39px);
  line-height: 1.45;
  letter-spacing: -1px;
}

.welcome h1 span {
  color: #81aaff;
}

.welcome-desc {
  margin: 13px 0 36px;
  color: var(--muted);
  font-size: 15px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  text-align: right;
}

.suggestion {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 132px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17, 26, 45, 0.72);
  transition: 0.2s;
}

.suggestion:hover {
  transform: translateY(-3px);
  border-color: rgba(81, 146, 255, 0.45);
  background: var(--panel-hover);
}

.suggestion > span {
  color: #82b5ff;
  font-size: 23px;
}

.suggestion strong {
  font-size: 13px;
}

.suggestion small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

/* Messages */

.messages {
  width: 100%;
  max-width: 850px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: appear 0.25s ease;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: #91baff;
  font-weight: 700;
}

.message.user .message-avatar {
  background: #1a3158;
  color: #d9e7ff;
}

.message-content {
  max-width: min(82%, 720px);
  padding: 14px 17px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(17, 26, 45, 0.8);
  line-height: 1.9;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user .message-content {
  background: linear-gradient(
    135deg,
    rgba(48, 91, 170, 0.30),
    rgba(42, 49, 91, 0.28)
  );
  border-color: rgba(91, 139, 230, 0.22);
}

.message-content p {
  margin: 0;
}

.message-content pre {
  direction: ltr;
  text-align: left;
  padding: 13px;
  border-radius: 10px;
  background: #080d18;
  overflow-x: auto;
}

.message-content code {
  font-family: Consolas, monospace;
}

.typing {
  color: var(--muted);
  animation: pulse 1.2s infinite;
}

/* Composer */

.composer-wrap {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 24px 18px;
}

.composer {
  padding: 13px 15px 11px;
  border: 1px solid rgba(112, 139, 191, 0.25);
  border-radius: 19px;
  background: #101827;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.13);
  transition: border-color 0.2s, box-shadow 0.2s;
}.composer:focus-within {
  border-color: rgba(76, 143, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(65, 130, 255, 0.07);
}

#messageInput {
  display: block;
  width: 100%;
  min-height: 35px;
  max-height: 180px;
  resize: none;
  padding: 5px 3px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.7;
}

#messageInput::placeholder {
  color: #74829b;
}

.composer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.composer-note {
  color: #71819e;
  font-size: 11px;
}

.send-btn {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 13px;
  background: var(--gradient);
  color: white;
  font-size: 25px;
  font-weight: 600;
  box-shadow: 0 5px 20px rgba(54, 113, 255, 0.18);
  transition: 0.2s;
}

.send-btn:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.disclaimer {
  margin: 11px 0 0;
  color: #68758b;
  font-size: 10px;
  text-align: center;
  line-height: 1.7;
}

/* Mobile */

.overlay {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    width: 235px;
    min-width: 235px;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .suggestion {
    min-height: auto;
    display: grid;
    grid-template-columns: 30px 1fr;
    gap: 5px 10px;
  }

  .suggestion > span {
    grid-row: span 2;
  }

  .suggestion small {
    grid-column: 2;
  }

  .welcome {
    max-width: 600px;
  }
}

@media (max-width: 650px) {
  body {
    font-size: 13px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(290px, 85vw);
    min-width: 0;
    transform: translateX(105%);
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.3);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .close-menu {
    display: grid;
    margin-right: auto;
  }

  .menu-btn {
    display: grid;
  }

  .overlay.visible {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
  }

  .topbar {
    height: 62px;
    min-height: 62px;
    padding: 0 13px;
    gap: 10px;
  }

  .top-brand {
    font-size: 15px;
  }

  .mini-logo {
    width: 25px;
    height: 25px;
  }

  #language {
    max-width: 115px;
    padding: 8px;
    font-size: 12px;
  }

  .chat-area {
    padding: 18px 15px 12px;
  }

  .welcome {
    padding: 20px 0;
  }

  .welcome-logo {
    width: 60px;
    height: 60px;
    border-radius: 20px;
    font-size: 39px;
    margin-bottom: 22px;
  }

  .welcome h1 {
    font-size: 27px;
  }

  .welcome-desc {
    margin-bottom: 25px;
  }

  .suggestions {
    gap: 9px;
  }

  .suggestion {
    padding: 13px;
    border-radius: 13px;
  }

  .composer-wrap {
    padding: 10px 12px 12px;
  }

  .composer {
    border-radius: 16px;
    padding: 10px 11px;
  }

  .message-content {
    max-width: 88%;
    padding: 11px 13px;
  }

  .message {
    gap: 8px;
  }

  .message-avatar {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
  }

  .disclaimer {
    font-size: 9px;
  }
}

@media (max-height: 650px) {
  .welcome {
    margin: 0;
  }

  .welcome-logo {
    width: 52px;
    height: 52px;
    margin-bottom: 14px;
    font-size: 34px;
  }

  .welcome-desc {
    margin-bottom: 18px;
  }

  .suggestion {
    min-height: 100px;
    padding: 12px;
  }

  .chat-area {
    padding-top: 14px;
  }
}

/* Light theme */

body.light {
  --bg: #f4f7fc;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --panel-hover: #edf2fb;
  --border: rgba(35, 55, 90, 0.13);
  --text: #17233b;
  --muted: #687791;
}

body.light .main {
  background:
    radial-gradient(
      ellipse at 50% 34%,
      rgba(92, 139, 226, 0.09),
      transparent 50%
    ),
    var(--bg);
}

body.light .composer {
  background: #ffffff;
}

body.light .message-content {
  background: rgba(255, 255, 255, 0.85);
}

body.light .message.user .message-content {
  background: #e8efff;
}body.light .message-content pre {
  background: #111827;
  color: #f3f6ff;
}

body.light #language {
  background: #ffffff;
}

body.light .welcome-logo {
  background: linear-gradient(145deg, #e6efff, #f4f0ff);
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(7px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

#deleteAllBtn {
  color: #c27e85;
}

#deleteAllBtn:hover,
.history-delete:hover {
  color: #ff8f96;
  background: rgba(239, 68, 68, 0.1);
}

.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 12px -4px 16px;
  padding: 0 4px;
  scrollbar-width: thin;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 3px;
}

.history-open {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.history-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  display: grid;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.history-list + #deleteAllBtn {
  flex: 0 0 auto;
}

.clear-current-btn {
  flex: 0 0 38px;
  border-color: var(--border);
}

.message,
.messages {
  min-width: 0;
}

.message-content {
  min-width: 0;
}

.message-content p {
  margin: 0;
  white-space: pre-wrap;
}

.message-content p + p {
  margin-top: 10px;
}

.code-frame {
  max-width: 100%;
  min-width: 0;
  margin: 10px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #080d18;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 2px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  color: #94a3b8;
  font-size: 11px;
}

.code-frame pre {
  max-width: 100%;
  max-height: 360px;
  margin: 0;
  padding: 12px;
  direction: ltr;
  text-align: left;
  overflow: auto;
  white-space: pre;
}

.code-frame code {
  display: block;
  color: #e2e8f0;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  overflow-wrap: normal;
}

.copy-code-btn,
.message-action {
  display: grid;
  width: 32px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #a9bad4;
  font-size: 16px;
}

.copy-code-btn:hover,
.message-action:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.14);
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 3px;
  margin: 7px -5px -6px;
}

.message-error .message-content {
  border-color: rgba(239, 116, 116, 0.25);
}

.retry-btn {
  display: block;
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-hover);
  color: var(--text);
  font-size: 12px;
}

.stop-btn {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(244, 114, 114, 0.35);
  border-radius: 13px;
  background: rgba(153, 48, 58, 0.22);
  color: #ff9b9b;
}

.stop-btn:hover {
  background: rgba(153, 48, 58, 0.4);
}

[hidden] {
  display: none !important;
}

body {
  overscroll-behavior: none;
}

.composer-wrap {
  z-index: 2;
}

@media (max-width: 650px) {
  .app {
    height: 100dvh;
    min-height: 0;
  }

  .chat-area {
    padding: 13px 11px 8px;
    overscroll-behavior: contain;
  }

  .messages {
    gap: 15px;
  }

  .message-content {
    max-width: calc(100% - 36px);
    padding: 10px 11px;
    line-height: 1.75;
  }

  .code-frame pre {
    max-height: 280px;
    padding: 10px;
  }

  .code-frame code {
    font-size: 11px;
  }

  #messageInput {
    font-size: 16px;
  }

  .composer-wrap {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .history-delete {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
  }
}

body.light .code-frame {
  background: #111827;
}