:root {
  --bg: #080c10;
  --bg-elevated: #101820;
  --surface: rgba(22, 30, 40, 0.72);
  --surface-solid: #161e28;
  --surface-hover: #1e2836;
  --text: #f4f7fb;
  --muted: #8b9cb0;
  --accent: #5b8def;
  --accent-2: #8b6cf8;
  --accent-hover: #4a7de0;
  --user-bubble: linear-gradient(135deg, #1a3d66, #1e2f4a);
  --assistant-bubble: #151c26;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --danger: #ff7b7b;
  --ok: #4fd1a5;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 0% -10%, rgba(91, 141, 239, 0.18), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(139, 108, 248, 0.12), transparent 55%),
    var(--bg);
}

.hidden { display: none !important; }

.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 12, 16, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(91, 141, 239, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  font-size: 11px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border: 1px solid var(--border);
}

.user-label {
  font-size: 13px;
  color: var(--muted);
}

.login-screen {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-card {
  width: min(420px, 100%);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
}

.login-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--accent);
  background: rgba(91, 141, 239, 0.12);
  border: 1px solid rgba(91, 141, 239, 0.25);
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.login-card p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 24px;
}

.app-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 20px 24px;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.72fr);
  gap: 14px;
  flex: 1;
  min-height: calc(100vh - 76px);
}

.panel-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0 4px 10px;
}

.user-menu {
  position: relative;
}

.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.user-menu-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.user-menu-caret {
  color: var(--muted);
  font-size: 11px;
}

.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 160px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}

.user-menu-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.user-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.main-nav,
.automation-nav {
  display: flex;
  gap: 8px;
  padding: 0 4px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar,
.automation-nav::-webkit-scrollbar { display: none; }

.nav-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.nav-btn.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(91, 141, 239, 0.28);
}

.section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.section-chat {
  width: 100%;
  max-width: none;
  margin: 0;
  min-height: 0;
}

.section-automation {
  min-height: 0;
}

.chat-layout {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.chat-sidebar {
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 420px;
  max-height: calc(100vh - 180px);
}

.chat-new-btn {
  width: 100%;
  justify-content: center;
  font-size: 12px;
  padding: 7px 8px;
  min-height: 32px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-sidebar-title {
  margin: 2px 6px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.chat-item {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.chat-item-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  line-height: 1.3;
}

.chat-item-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-delete {
  flex-shrink: 0;
  width: 26px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}

.chat-item-delete:hover {
  color: var(--danger);
  background: rgba(255, 123, 123, 0.1);
  border-color: rgba(255, 123, 123, 0.25);
}

.chat-item-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-item-btn.active {
  background: rgba(91, 141, 239, 0.14);
  border-color: rgba(91, 141, 239, 0.28);
}

.chat-item-meta {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
  white-space: normal;
  line-height: 1.25;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 320px;
  max-height: calc(100vh - 280px);
}

.bubble {
  max-width: 88%;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border: 1px solid rgba(91, 141, 239, 0.25);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
}

.bubble .role {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.composer {
  border-radius: var(--radius);
  padding: 14px;
  margin-top: auto;
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
}

.composer textarea:focus {
  outline: 2px solid rgba(91, 141, 239, 0.35);
  border-color: rgba(91, 141, 239, 0.5);
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  gap: 12px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.15s, opacity 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 8px 20px rgba(91, 141, 239, 0.25);
}

.btn-primary:hover { filter: brightness(1.05); }

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-lg {
  padding: 12px 22px;
  min-width: 160px;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.04); }

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
}

.error {
  color: var(--danger);
  margin-top: 14px;
  font-size: 14px;
}

.typing {
  color: var(--muted);
  font-style: italic;
}

.automation-layout {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 10px;
  min-height: calc(100vh - 180px);
}

.section-automation .automation-nav {
  padding: 0 2px 8px;
  gap: 6px;
}

.section-automation .automation-nav .nav-btn {
  padding: 6px 11px;
  font-size: 11px;
}

.section-automation .panel-header {
  padding: 0 2px 8px;
}

.task-sidebar,
.task-panel {
  border-radius: var(--radius);
  min-height: 420px;
}

.task-sidebar {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-sidebar-title {
  margin: 4px 8px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.task-nav-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 9px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.3;
}

.task-nav-btn:hover { background: rgba(255, 255, 255, 0.04); }

.task-nav-btn.active {
  background: rgba(91, 141, 239, 0.14);
  border-color: rgba(91, 141, 239, 0.28);
  color: white;
}

.task-panel {
  padding: 16px 18px;
  overflow: auto;
  font-size: 13px;
}

.placeholder-state {
  height: 100%;
  min-height: 320px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
}

.placeholder-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.placeholder-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.task-runner h2 {
  margin: 0 0 6px;
  font-size: 17px;
  letter-spacing: -0.03em;
}

.task-runner .task-desc {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.45;
  max-width: 100%;
  font-size: 12px;
}

.file-field {
  margin-bottom: 14px;
}

.file-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
}

.file-field input[type="file"] {
  width: 100%;
  font: inherit;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: rgba(0, 0, 0, 0.18);
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  align-items: center;
}

.task-log {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  color: #c5d0dc;
}

.task-result {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(79, 209, 165, 0.08);
  border: 1px solid rgba(79, 209, 165, 0.22);
  color: var(--ok);
  font-size: 13px;
}

.task-error {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 123, 123, 0.08);
  border: 1px solid rgba(255, 123, 123, 0.22);
  color: var(--danger);
  font-size: 13px;
  white-space: pre-wrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.confirm-panel {
  width: min(400px, 100%);
}

.confirm-text {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.15);
}

.admin-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.admin-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.admin-status {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.admin-field {
  margin-bottom: 10px;
}

.admin-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--muted);
}

.admin-field input {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.admin-feedback {
  margin-top: 10px;
  font-size: 13px;
  white-space: pre-wrap;
}

.admin-feedback.ok { color: var(--ok); }
.admin-feedback.err { color: var(--danger); }

@media (max-width: 1100px) {
  .workspace-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .section-chat,
  .section-automation {
    min-height: 480px;
  }
}

@media (max-width: 800px) {
  .automation-layout {
    grid-template-columns: 1fr;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    max-height: 200px;
    min-height: auto;
  }

  .task-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    min-height: auto;
  }

  .task-sidebar-title {
    width: 100%;
  }

  .messages {
    max-height: calc(100vh - 320px);
  }
}
