:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #17212b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

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

button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  background: #2481cc;
  color: white;
}

button.secondary {
  background: #e9eef3;
  color: #17212b;
}

button.danger {
  background: #e5484d;
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

input, textarea, select {
  width: 100%;
  border: 1px solid #d8e0e8;
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
  color: #17212b;
  outline: none;
}

textarea {
  resize: vertical;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(380px, 100%);
  background: white;
  padding: 24px;
  border-radius: 18px;
  box-shadow: 0 10px 30px rgb(15 23 42 / 10%);
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 24px;
}

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
  padding-bottom: 112px;
}

.sidebar {
  border-right: 1px solid #d8e0e8;
  background: #ffffffcc;
  padding: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.main {
  padding: 20px 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
  margin-bottom: 16px;
}

.folder-list {
  display: grid;
  gap: 8px;
}

.folder-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  border-radius: 14px;
  padding: 9px;
  background: #f5f8fb;
}

.folder-item.active {
  background: #dff0ff;
}

.folder-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.folder-more {
  color: #6f8295;
}

.icon-btn {
  padding: 5px 8px;
  border-radius: 8px;
}

.folder-form {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.chat-panel {
  background: linear-gradient(180deg, #f7fbff 0%, #eef4f8 100%);
  border: 1px solid #dde7ef;
  border-radius: 24px;
  padding: 16px;
  min-height: 68vh;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 55%);
}

.messages {
  display: grid;
  gap: 12px;
}

.card {
  background: white;
  border: 1px solid #e0e6ed;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgb(15 23 42 / 5%);
}

.message-row {
  display: grid;
  gap: 6px;
}

.message-row.incoming {
  justify-items: start;
}

.message-row.outgoing {
  justify-items: end;
}

.message-date {
  color: #7c8ea1;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-line;
  text-align: center;
}

.message-bubble {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 10px;
  align-items: start;
  padding: 14px 16px;
}

.message-row.incoming .message-bubble {
  border-top-left-radius: 8px;
}

.message-row.outgoing .message-bubble {
  background: linear-gradient(180deg, #dff0ff 0%, #cfe8ff 100%);
  border-color: #bfdcf7;
  border-top-right-radius: 8px;
}

.message-main {
  min-width: 0;
}

.message-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.6;
  word-break: break-word;
}

.message-note {
  margin-top: 8px;
  color: #445566;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: #7a8c9e;
  font-size: 12px;
}

.message-meta span {
  background: #f3f6f9;
  border-radius: 999px;
  padding: 4px 8px;
}

.more-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: #7a8c9e;
  font-size: 24px;
  line-height: 1;
}

.more-btn:hover {
  background: #eef3f7;
}

.context-menu {
  position: fixed;
  z-index: 999;
  width: 220px;
  padding: 8px;
  border: 1px solid #d8e0e8;
  border-radius: 16px;
  background: #ffffffee;
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 40px rgb(15 23 42 / 14%);
}

.context-menu button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #17212b;
  padding: 10px 12px;
  border-radius: 10px;
}

.context-menu button:hover {
  background: #f3f6f9;
}

.context-menu .danger-text {
  color: #d8343a;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(15 23 42 / 36%);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(460px, 100%);
  background: white;
  border: 1px solid #d8e0e8;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 24px 60px rgb(15 23 42 / 18%);
}

.modal-card h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px 18px;
  background: #ffffffee;
  border-top: 1px solid #d8e0e8;
  backdrop-filter: blur(10px);
}

.composer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 12px;
  max-width: 1280px;
  margin: 0 auto;
}

#sendText {
  min-height: 52px;
  border-radius: 18px;
  font-size: 16px;
  padding: 14px 16px;
}

#sendForm button {
  border-radius: 18px;
  font-size: 16px;
}

.empty, .error {
  color: #66788a;
  padding: 18px;
  text-align: center;
}

.error {
  color: #e5484d;
}

@media (max-width: 760px) {
  .app {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid #d8e0e8;
  }

  .topbar,
  .composer-inner,
  .folder-form {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    padding: 12px;
    border-radius: 18px;
  }

  .message-bubble {
    width: 100%;
    grid-template-columns: 1fr 32px;
    padding: 12px 14px;
  }

  .message-date {
    text-align: left;
  }

  .modal-actions {
    flex-direction: column;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    background: #0e1621;
    color: #eef5fb;
  }

  input, textarea, select, .login-card, .card, .modal-card {
    background: #17212b;
    color: #eef5fb;
    border-color: #2b3a48;
  }

  .sidebar, .composer, .context-menu {
    background: #17212be8;
    border-color: #2b3a48;
  }

  .chat-panel {
    background: linear-gradient(180deg, #101b27 0%, #0e1621 100%);
    border-color: #2b3a48;
  }

  .modal-mask {
    background: rgb(2 8 23 / 56%);
  }

  .message-row.outgoing .message-bubble {
    background: linear-gradient(180deg, #1d4f7a 0%, #173f63 100%);
    border-color: #28618f;
  }

  .folder-item, button.secondary, .message-meta span {
    background: #22303c;
    color: #eef5fb;
  }

  .folder-item.active {
    background: #1d4f7a;
  }

  .meta, .empty, .message-date, .message-meta, .folder-more {
    color: #9fb1c1;
  }

  .message-note {
    color: #cfdae5;
  }

  .more-btn {
    color: #9fb1c1;
  }

  .more-btn:hover,
  .context-menu button:hover {
    background: #22303c;
  }

  .context-menu button {
    color: #eef5fb;
  }
}
