:root {
  --bg: #0f141a;
  --panel: #17212b;
  --panel-2: #1d2a36;
  --line: #2c3b4c;
  --text: #eef3f8;
  --muted: #9aa8b8;
  --accent: #3390ec;
  --danger: #e86666;
  --ok: #74c476;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  justify-content: center;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 14, 18, 0.92);
  backdrop-filter: blur(6px);
}

.auth-overlay[hidden],
.app[hidden] {
  display: none !important;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 22px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.login-hint,
.login-field {
  color: var(--muted);
  font-size: 13px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.login-field input,
.chat-input-bar input {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #101821;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.login-field input {
  padding: 12px;
}

.login-field input:focus,
.chat-input-bar input:focus {
  border-color: var(--accent);
}

.login-error {
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 13px;
}

.login-submit,
.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.login-submit {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  font-size: 16px;
}

.app {
  width: 100%;
  max-width: 760px;
  height: 100dvh;
  display: grid;
  grid-template-rows: 42% 23% 35%;
  overflow: hidden;
  background: radial-gradient(circle at top, #1b2835, #0f141a 46%);
}

.table-panel,
.editor-panel,
.chat-panel {
  min-height: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 25, 34, 0.86);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-title.compact {
  padding-bottom: 8px;
}

.panel-title h1,
.panel-title h2 {
  margin: 0;
  font-size: 16px;
}

.panel-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.export-actions {
  display: flex;
  gap: 6px;
}

.export-link {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  background: var(--panel-2);
}

.export-link.disabled {
  pointer-events: none;
  opacity: 0.4;
}

.table-wrap {
  height: calc(100% - 58px);
  overflow: auto;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #14202b;
  color: #cfe1f4;
  font-weight: 700;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.row-editor {
  height: calc(100% - 58px);
  overflow: auto;
  padding: 10px 12px 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.field-card {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(29, 42, 54, 0.74);
}

.field-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(51, 144, 236, 0.3);
}

.field-name {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.field-value {
  min-height: 18px;
  font-size: 13px;
  word-break: break-word;
}

.chat-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  border-bottom: none;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 88%;
  padding: 9px 11px;
  border-radius: 14px;
  line-height: 1.35;
  font-size: 14px;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: #2b5278;
}

.message.bot {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: #223140;
}

.status {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.chat-input-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: rgba(16, 23, 32, 0.95);
}

.chat-input-bar input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 24px;
}

.icon-btn,
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 13px;
}

.icon-btn {
  border: none;
  background: #26384a;
  color: #fff;
  cursor: pointer;
}

.icon-btn.recording {
  background: var(--danger);
}

@media (max-width: 480px) {
  .app {
    grid-template-rows: 41% 24% 35%;
  }

  .row-editor {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 94%;
  }
}
