:root {
  color-scheme: dark;
  --page: #070b12;
  --panel: #101722;
  --panel-soft: #151e2b;
  --surface: #1a2433;
  --surface-strong: #202c3d;
  --text: #edf3fb;
  --muted: #95a3b8;
  --line: #273447;
  --line-strong: #3a4a60;
  --accent: #20c7b1;
  --accent-strong: #6ee7d8;
  --accent-soft: #123832;
  --amber: #fbbf24;
  --danger: #fb7185;
  --danger-soft: #3b1720;
  --ink: #e7eef8;
  --shadow: 0 32px 90px rgba(0, 0, 0, 0.42);
  --soft-shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(32, 199, 177, 0.18), rgba(7, 11, 18, 0) 40%),
    linear-gradient(315deg, rgba(99, 102, 241, 0.14), rgba(7, 11, 18, 0) 36%),
    var(--page);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  line-height: 1;
  touch-action: manipulation;
}

.file-input {
  display: none;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.chat-panel {
  width: min(1180px, 100%);
  height: min(860px, calc(100vh - 56px));
  height: min(860px, calc(100dvh - 56px));
  min-height: 680px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 8px;
  background: rgba(16, 23, 34, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #2dd4bf);
  color: #06201d;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(15, 159, 143, 0.25);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 850;
  line-height: 1.1;
}

.status {
  max-width: min(520px, 58vw);
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status.is-online {
  color: #8ff5e8;
}

.status.is-error {
  color: var(--danger);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.copy-button,
.delete-button,
.settings button,
.composer button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 21px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  display: block;
  margin: auto;
  stroke: currentColor;
}

.icon-button:hover {
  background: var(--surface-strong);
  transform: translateY(-1px);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  transition: grid-template-columns 0.22s ease;
}

.chat-panel.is-connected .workspace {
  grid-template-columns: 0 minmax(0, 1fr);
}

.control-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(21, 30, 43, 0.98), rgba(16, 23, 34, 0.96)),
    var(--panel-soft);
  overflow: hidden;
  transition: opacity 0.16s ease, padding 0.22s ease, border-color 0.22s ease;
}

.chat-panel.is-connected .control-panel {
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
  pointer-events: none;
}

.control-heading h2 {
  font-size: 16px;
  font-weight: 850;
}

.control-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.settings {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #0d1420;
  outline: none;
  box-shadow: 0 1px 0 rgba(23, 32, 51, 0.03);
}

input {
  height: 43px;
  padding: 0 12px;
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1420;
  padding: 3px;
  box-shadow: 0 1px 0 rgba(23, 32, 51, 0.03);
}

.password-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.16);
}

.password-field input {
  height: 35px;
  padding: 0 9px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.password-field input:focus {
  box-shadow: none;
}

.field-button {
  width: 34px;
  height: 35px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.field-button:hover {
  background: var(--surface);
  color: var(--ink);
}

.password-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

.field-button svg,
.clipboard-button svg,
.send-button svg {
  width: 17px;
  height: 17px;
  display: block;
  margin: auto;
  stroke: currentColor;
}

.field-button,
.clipboard-button,
.send-button {
  justify-content: center;
  align-content: center;
}

textarea {
  min-height: 76px;
  max-height: 180px;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.16);
}

.settings button,
.composer button {
  min-height: 43px;
  padding: 0 16px;
  background: var(--accent);
  color: #06201d;
  font-weight: 850;
  box-shadow: 0 12px 24px rgba(32, 199, 177, 0.18);
}

.clipboard-button,
.send-button {
  width: 52px;
  display: grid;
  place-items: center;
  padding: 0;
}

.clipboard-button svg,
.send-button svg {
  transform: none;
}

.settings button:hover,
.composer button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.conversation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #0b111b;
}

.messages {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 24px;
  background:
    radial-gradient(circle at 18px 18px, rgba(71, 85, 105, 0.28) 1px, transparent 1.5px),
    linear-gradient(180deg, #0b111b, #0d1420);
  background-size: 18px 18px, auto;
  scrollbar-color: var(--line-strong) transparent;
  overscroll-behavior: contain;
}

.messages.is-dragging {
  outline: 2px solid var(--accent);
  outline-offset: -10px;
}

.drop-hint {
  position: absolute;
  inset: 18px;
  z-index: 2;
  display: none;
  place-items: center;
  border: 1px dashed rgba(15, 159, 143, 0.58);
  border-radius: 8px;
  background: rgba(18, 56, 50, 0.9);
  color: #9ff7eb;
  font-weight: 850;
  pointer-events: none;
}

.messages.is-dragging .drop-hint {
  display: grid;
}

.empty {
  margin: auto;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.message {
  position: relative;
  width: min(760px, 100%);
  padding: 15px 104px 15px 16px;
  border: 1px solid rgba(71, 85, 105, 0.7);
  border-radius: 8px;
  background: rgba(19, 28, 42, 0.96);
  box-shadow: var(--soft-shadow);
}

.message.is-encrypted {
  border-color: rgba(32, 199, 177, 0.34);
  background: linear-gradient(180deg, #10241f, var(--accent-soft));
}

.message.is-failed {
  border-color: rgba(251, 113, 133, 0.32);
  background: var(--danger-soft);
}

.message-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
}

.sender {
  max-width: 260px;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lock-state {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  color: #facc15;
  font-size: 12px;
  font-weight: 800;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #e7eef8;
  font-size: 15px;
  line-height: 1.62;
}

.message-text:empty,
.attachment:empty {
  display: none;
}

.attachment {
  width: min(540px, 100%);
  margin-top: 12px;
}

.attachment-image-frame {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b111b;
}

.attachment-image {
  width: 100%;
  max-height: 360px;
  display: block;
  object-fit: contain;
  background: #0b111b;
  cursor: zoom-in;
}

.attachment-card {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.74);
}

.attachment-image-frame + .attachment-card {
  margin-top: 8px;
}

.attachment-meta {
  min-width: 0;
}

.attachment-name {
  overflow: hidden;
  color: var(--text);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-size {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.download-link {
  height: 36px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--ink);
  color: #0b111b;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}

.message-actions {
  position: absolute;
  top: 13px;
  right: 13px;
  display: flex;
  gap: 6px;
  padding: 3px;
  border: 1px solid rgba(71, 85, 105, 0.56);
  border-radius: 8px;
  background: rgba(11, 17, 27, 0.72);
  backdrop-filter: blur(10px);
}

.copy-button,
.delete-button {
  width: 32px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  background: #1e293b;
  color: #dce8f7;
}

.copy-button svg,
.delete-button svg {
  width: 16px;
  height: 16px;
  display: block;
  margin: auto;
  stroke: currentColor;
}

.delete-button {
  background: #3b1720;
  color: var(--danger);
}

.copy-button:hover {
  background: #263348;
}

.delete-button:hover {
  background: #4b1d28;
}

.copy-button:disabled,
.composer button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.96);
}

.composer textarea {
  border-color: var(--line-strong);
  background: #0d1420;
}

.selected-file {
  grid-column: 1 / -1;
  min-height: 18px;
  margin-top: -5px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 24px;
}

.image-viewer.is-open {
  display: grid;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 12, 0.84);
  backdrop-filter: blur(10px);
}

.image-viewer-dialog {
  position: relative;
  z-index: 1;
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  margin: 0;
}

.viewer-image {
  max-width: 100%;
  max-height: calc(100vh - 116px);
  max-height: calc(100dvh - 116px);
  justify-self: center;
  align-self: center;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 8px;
  object-fit: contain;
  background: #02060c;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48);
}

.viewer-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.9);
  color: var(--muted);
  font-size: 13px;
}

#viewerName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-download {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-weight: 850;
  text-decoration: none;
}

.viewer-close {
  position: absolute;
  top: -14px;
  right: -14px;
  z-index: 2;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.94);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
}

.viewer-close:hover {
  background: var(--surface);
}

@media (max-width: 980px) {
  .app-shell {
    padding: 18px;
  }

  .chat-panel {
    height: calc(100vh - 36px);
    height: calc(100dvh - 36px);
    min-height: 640px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .chat-panel.is-connected .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 0 minmax(0, 1fr);
  }

  .control-panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 16px;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-panel.is-connected .control-panel {
    padding-top: 0;
    padding-bottom: 0;
    border-bottom-color: transparent;
  }

  .settings {
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    align-items: end;
  }
}

@media (max-width: 760px) {
  body {
    background: var(--page);
  }

  .app-shell {
    padding: 0;
  }

  .chat-panel {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  h1 {
    font-size: 19px;
  }

  .status {
    max-width: calc(100vw - 134px);
    margin-top: 5px;
    font-size: 12px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 19px;
  }

  .control-panel {
    display: block;
    padding: 12px 14px;
  }

  .control-heading {
    display: none;
  }

  .settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  label {
    gap: 5px;
    font-size: 11px;
  }

  input {
    height: 39px;
    padding: 0 10px;
  }

  .password-field {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .password-field input {
    height: 33px;
  }

  .field-button {
    height: 33px;
    width: 34px;
  }

  .settings button {
    grid-column: 1 / -1;
    min-height: 39px;
    box-shadow: none;
  }

  .conversation {
    min-height: 0;
  }

  .messages {
    gap: 10px;
    padding: 12px;
    background: #0b111b;
  }

  .drop-hint {
    inset: 12px;
  }

  .message {
    width: 100%;
    padding: 12px;
    box-shadow: 0 8px 20px rgba(23, 32, 51, 0.07);
  }

  .message-head {
    gap: 6px;
    margin-bottom: 8px;
    font-size: 12px;
  }

  .sender {
    max-width: 46vw;
  }

  .lock-state {
    padding: 2px 6px;
    font-size: 11px;
  }

  .message-text {
    font-size: 14px;
    line-height: 1.56;
  }

  .attachment {
    width: 100%;
    margin-top: 10px;
  }

  .attachment-image-frame {
    border-radius: 8px;
  }

  .attachment-image {
    width: 100%;
    max-height: 42vh;
  }

  .image-viewer {
    padding: 12px;
  }

  .image-viewer-dialog {
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }

  .viewer-image {
    max-height: calc(100vh - 104px);
    max-height: calc(100dvh - 104px);
  }

  .viewer-close {
    top: 8px;
    right: 8px;
  }

  .attachment-card {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .attachment-name {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .download-link {
    width: 100%;
    height: 40px;
  }

  .message-actions {
    position: static;
    width: fit-content;
    margin: 11px 0 0 auto;
  }

  .copy-button,
  .delete-button {
    width: 38px;
    height: 36px;
  }

  .composer {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    grid-column: 1 / -1;
  }

  textarea {
    min-height: 58px;
    max-height: 128px;
    padding: 11px 12px;
    font-size: 16px;
  }

  .composer button {
    width: 100%;
    min-height: 41px;
    box-shadow: none;
  }

  .selected-file {
    min-height: 17px;
    margin-top: -2px;
    font-size: 12px;
  }
}

@media (max-width: 430px) {
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .control-panel,
  .messages,
  .composer {
    padding-left: 10px;
    padding-right: 10px;
  }

  .settings {
    grid-template-columns: 1fr;
  }

  .status {
    max-width: calc(100vw - 122px);
  }

  .toolbar {
    gap: 6px;
  }
}

@media (max-height: 690px) and (max-width: 760px) {
  .settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 132px;
    overflow-y: auto;
    padding-right: 2px;
  }

  .settings button {
    grid-column: 1 / -1;
  }

  textarea {
    min-height: 50px;
  }
}
