:root {
  --bg: #07111f;
  --bg-soft: rgba(15, 31, 49, 0.86);
  --card: rgba(12, 26, 43, 0.95);
  --card-2: rgba(7, 18, 31, 0.9);
  --text: #f5f7fb;
  --muted: #9fb4c9;
  --line: rgba(157, 187, 214, 0.18);
  --accent: #5ce1e6;
  --accent-2: #7aa2ff;
  --danger: #ff8b8b;
  --success: #77e7b8;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(92, 225, 230, 0.2), transparent 32%),
    radial-gradient(circle at right 20%, rgba(122, 162, 255, 0.18), transparent 26%),
    linear-gradient(180deg, #081120 0%, #0b1728 45%, #07111f 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

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

.hidden {
  display: none !important;
}

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

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 64px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand span {
  display: flex;
  flex-direction: column;
}

.brand strong {
  font-size: 1.05rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-content,
.chat-page {
  display: grid;
  gap: 20px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    var(--card);
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-panel {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  align-items: center;
  min-height: calc(100vh - 120px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-copy h1,
.chat-toolbar h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.panel-copy p,
.chat-toolbar p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

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

.auth-form label,
.device-picker {
  display: grid;
  gap: 8px;
}

.auth-form span,
.device-picker span {
  font-size: 0.92rem;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card-2);
  color: var(--text);
  padding: 14px 16px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(92, 225, 230, 0.45);
  box-shadow: 0 0 0 3px rgba(92, 225, 230, 0.12);
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 999px;
  padding: 0 18px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #07111f;
  font-weight: 700;
}

.secondary-button,
.ghost-button {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-color: var(--line);
}

.prompt-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
}

.prompt-menu {
  position: relative;
}

.prompt-menu-toggle {
  min-width: 46px;
  width: 46px;
  padding: 0;
  gap: 4px;
}

.prompt-menu-toggle span {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

.prompt-menu-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 40;
  min-width: 240px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(7, 18, 31, 0.98);
  box-shadow: var(--shadow);
}

.prompt-menu-option {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.prompt-menu-option:hover,
.prompt-menu-option:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.form-error,
.form-status {
  margin: 0;
  font-size: 0.92rem;
}

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

.form-status {
  color: var(--success);
}

.chat-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: calc(100vh - 120px);
  gap: 18px;
}

.chat-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.toolbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.device-picker {
  min-width: 220px;
}

.messages-container {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.02);
  padding: 16px;
  overflow-y: auto;
  min-height: 320px;
  max-height: calc(100vh - 320px);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: flex;
}

.message-content {
  max-width: min(720px, 88%);
  padding: 14px 16px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.user-message {
  justify-content: flex-end;
}

.user-message .message-content {
  background: linear-gradient(135deg, rgba(92, 225, 230, 0.9), rgba(122, 162, 255, 0.9));
  color: #07111f;
  border-bottom-right-radius: 8px;
}

.assistant-message .message-content,
.alarm-message .message-content {
  background: rgba(10, 23, 38, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  border-bottom-left-radius: 8px;
  max-width: min(860px, 96%);
}

.message-meta {
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.user-message .message-meta {
  color: rgba(7, 17, 31, 0.72);
}

.message-text {
  line-height: 1.65;
  white-space: normal;
  word-break: break-word;
}

.message-text a {
  color: var(--accent);
  text-decoration: underline;
}

.message-time {
  margin-top: 10px;
  font-size: 0.76rem;
  color: var(--muted);
}

.user-message .message-time {
  color: rgba(7, 17, 31, 0.78);
}

.alarm-content p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.55;
}

.alarm-content strong {
  color: var(--text);
}

.alarm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(92, 225, 230, 0.12);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid rgba(92, 225, 230, 0.2);
}

.alarm-preview-row {
  margin-top: 12px;
}

.alarm-thumb {
  width: 136px;
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: block;
}

.summary-clip-row {
  margin: 12px 0;
}

.summary-clip-inline-group {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.summary-clip-cue {
  flex: 1 1 220px;
  min-width: 0;
  line-height: 1.65;
  word-break: break-word;
}

.summary-clip-inline-previews {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 1 auto;
}

.summary-clip-inline-previews .summary-clip-row {
  margin: 0;
}

.alarm-media-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.alarm-crop-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: center;
  margin: 0;
  flex: 0 0 auto;
}

.alarm-crop-thumb {
  width: auto;
  height: auto;
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  background: #081119;
}

.summary-clip-card {
  position: relative;
  display: block;
  width: min(220px, 100%);
  overflow: hidden;
  border-radius: 14px;
  text-decoration: none;
  background: #081119;
  border: 1px solid var(--line);
}

.alarm-media-row .summary-clip-row,
.alarm-media-row .play-btn {
  flex: 0 1 160px;
  margin: 0;
}

.alarm-media-row .summary-clip-card {
  width: 160px;
}

.summary-clip-preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  pointer-events: none;
}

.summary-clip-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  pointer-events: none;
}

.summary-clip-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  background: linear-gradient(to top, rgba(3, 8, 17, 0.64), rgba(3, 8, 17, 0.2));
}

.summary-clip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  font-size: 1.15rem;
  background: rgba(3, 8, 17, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.summary-clip-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 17, 0.78);
}

.video-modal-panel,
.widget-modal-panel {
  position: relative;
  z-index: 1;
  width: min(960px, calc(100vw - 32px));
  border-radius: 18px;
  padding: 18px;
  background: rgba(7, 18, 31, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.video-modal-player {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: min(54vw, 540px);
  max-height: min(78vh, 720px);
  border-radius: 12px;
  background: #000;
  object-fit: contain;
}

.video-modal-loading {
  position: absolute;
  inset: 18px;
  display: grid;
  place-items: center;
  gap: 14px;
  border-radius: 12px;
  background: rgba(3, 8, 17, 0.58);
  color: #fff;
  pointer-events: none;
  text-align: center;
}

.video-modal-loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.24);
  border-top-color: #fff;
  border-radius: 999px;
  animation: videoSpinner 0.8s linear infinite;
}

.video-modal-loading-text {
  font-size: 0.95rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.widget-modal {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.widget-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 17, 0.78);
}

.widget-modal-panel {
  max-height: min(88vh, 920px);
  display: grid;
  gap: 18px;
  overflow: hidden;
}

.widget-modal-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  letter-spacing: -0.03em;
}

.widget-modal-body {
  min-height: 240px;
  max-height: min(70vh, 760px);
  overflow: auto;
}

.widget-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
}

.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.widget-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.widget-card h3,
.widget-card p {
  margin: 0;
}

.widget-card p {
  color: var(--muted);
  line-height: 1.5;
}

.widget-kicker {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.widget-live-shell {
  position: relative;
  width: 100%;
}

.widget-live-player {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  background: #000;
}

.widget-live-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 0;
  border-radius: 14px;
  background: rgba(3, 8, 17, 0.52);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(1px);
}

.widget-live-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(7, 18, 31, 0.82);
  color: #eef7ff;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1;
}

.widget-live-status[data-tone="ready"] {
  background: rgba(17, 94, 89, 0.88);
}

.widget-live-status[data-tone="warning"] {
  background: rgba(146, 64, 14, 0.9);
}

.widget-live-status[data-tone="error"] {
  background: rgba(127, 29, 29, 0.92);
}

.widget-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #081119;
}

.widget-thumb-natural {
  width: auto;
  max-width: 100%;
  max-height: 320px;
  aspect-ratio: auto;
  object-fit: contain;
}

.widget-media-button {
  display: inline-flex;
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}

.widget-thumb-frame {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}

.widget-thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  color: #fff;
  background: linear-gradient(to top, rgba(3, 8, 17, 0.72), rgba(3, 8, 17, 0.2));
  border-radius: 14px;
  text-align: center;
  pointer-events: none;
}

.widget-thumb-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: rgba(3, 8, 17, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 1.05rem;
}

.picture-modal {
  position: fixed;
  inset: 0;
  z-index: 1075;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.picture-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 17, 0.86);
}

.picture-modal-panel {
  position: relative;
  z-index: 1;
  width: fit-content;
  max-width: min(92vw, 1200px);
  max-height: 90vh;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(7, 18, 31, 0.96);
  box-shadow: var(--shadow);
}

.picture-modal-image {
  display: block;
  max-width: 100%;
  max-height: calc(90vh - 36px);
  width: auto;
  height: auto;
  border-radius: 12px;
  background: #081119;
}

.widget-meta {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.widget-inline-button,
.widget-launch-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(92, 225, 230, 0.2);
  background: rgba(92, 225, 230, 0.12);
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

.widget-inline-button {
  margin-top: 12px;
}

.widget-launch-button {
  width: fit-content;
}

.widget-card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.video-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(7, 18, 31, 0.75);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}

.chat-input-area {
  display: grid;
  gap: 12px;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.45;
  animation: typingPulse 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

.input-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.input-form textarea {
  min-height: 56px;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 16px;
}

@media (max-width: 980px) {
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .chat-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .messages-container {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1200px);
    padding-top: 14px;
  }

  .app-header,
  .toolbar-actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .panel {
    padding: 18px;
  }

  .device-picker {
    min-width: 100%;
    width: 100%;
  }

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

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

  .message-content {
    max-width: 100%;
  }

  .messages-container {
    padding: 12px;
  }

  .prompt-menu-panel {
    left: auto;
    right: 0;
  }

  .widget-modal,
  .video-modal,
  .picture-modal {
    padding: 12px;
  }

  .summary-clip-inline-group {
    flex-direction: column;
  }

  .summary-clip-cue {
    flex: none;
    width: 100%;
  }

  .summary-clip-inline-previews {
    width: 100%;
  }
}

@keyframes typingPulse {
  0%, 80%, 100% {
    transform: scale(0.85);
    opacity: 0.35;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes videoSpinner {
  to {
    transform: rotate(360deg);
  }
}
