:root {
  --bg: #fbf6ef;
  --panel: #fffaf2;
  --panel-strong: #f3e9d8;
  --border: rgba(0, 0, 0, 0.06);
  --accent: #004225;
  --accent-2: #006B3D;
  --muted: #6b6b6b;
  --text: #2b2b2b;
  --danger: #b00020;
  --font-body: "Space Grotesk", "Inter", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
}

.primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.35);
}

.danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.danger:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 25px rgba(176, 32, 32, 0.25);
}

button {
  font-family: inherit;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-section.slim {
  gap: 8px;
}

.sidebar-section a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}

.sidebar-section a:hover {
  background: rgba(0, 66, 37, 0.04);
}

.sidebar-section a.active {
  background: rgba(0, 66, 37, 0.08);
  color: var(--accent-2);
}

.section-heading {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.session-item {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease;
  position: relative;
  /* for delete button/menu positioning */
}

.session-item:hover {
  border-color: rgba(0, 66, 37, 0.6);
  transform: translateX(2px);
}

.session-item.active {
  border-color: var(--accent);
  background: rgba(0, 66, 37, 0.06);
}

.session-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.session-meta {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.badge.accent {
  background: rgba(0, 66, 37, 0.12);
  color: #e0f4ea;
}

/* Delete button and confirmation menu */
.session-item .session-delete {
  position: absolute;
  right: 10px;
  top: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.session-delete button.delete-btn {
  display: none;
  /* show on hover only */
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 6px;
}

.session-item:hover .session-delete button.delete-btn {
  display: inline-flex;
}

.session-delete button.delete-btn:hover {
  color: var(--danger);
  background: rgba(176, 0, 32, 0.06);
}

.session-delete .delete-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 34px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  z-index: 30;
  width: 220px;
}

.session-item.show-delete-menu .session-delete .delete-menu {
  display: block;
}

.session-delete .delete-menu .title {
  font-weight: 700;
  margin-bottom: 6px;
}

.session-delete .delete-menu .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.session-delete .delete-menu button.confirm-delete {
  background: rgba(176, 0, 32, 0.12);
  color: var(--danger);
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.session-delete .delete-menu button.cancel-delete {
  background: transparent;
  border: 1px dashed var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.git-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.git-actions button {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.git-actions button:hover {
  border-color: rgba(0, 66, 37, 0.6);
}

.git-actions input {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.git-output {
  min-height: 40px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px;
}

.raw-output {
  font-family: monospace;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px;
  margin-top: 8px;
  white-space: pre-wrap;
}

.attachments {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment-image {
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
}

.main {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.title {
  font-size: 24px;
  font-weight: 700;
}

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

.model-select {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.model-select select {
  background: transparent;
  color: var(--text);
  border: none;
  font-weight: 600;
  font-size: 13px;
}

.model-select img#model-icon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: inline-block;
}

.queue-indicator {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  min-width: 100px;
  text-align: center;
  font-size: 13px;
}

.panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.value {
  font-weight: 700;
  font-size: 14px;
}

.chat-area {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: white;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 400px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.empty-message {
  text-align: center;
  margin: auto;
  max-width: 400px;
  padding: 40px 20px;
}

.message {
  padding: 16px 20px;
  border-radius: 16px;
  border: 1px solid var(--border);
  position: relative;
  max-width: 85%;
}

.message.user {
  background: #f0f4f2;
  border-color: rgba(0, 66, 37, 0.1);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: #fff;
  border-color: var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.message .meta {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
}

.message .body {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 15px;
  color: #333;
}

.message .body p {
  margin-bottom: 12px;
}

.message .body ul,
.message .body ol {
  margin-bottom: 12px;
  padding-left: 20px;
}

.status-chip {
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
}

.composer {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  background: white;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.composer-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.prompt-helpers {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9f9f9;
  color: var(--text);
  padding: 12px 16px;
  font-family: var(--font-body);
  resize: none;
  min-height: 46px;
  max-height: 200px;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-size: 15px;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 66, 37, 0.05);
  background: white;
}

.attachment-preview {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.attachment-chip {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
}

.attachment-thumb {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
}

.attachment-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.attachment-meta .name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.attachment-remove {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
}

.attachment-remove:hover {
  color: var(--text);
  border-color: rgba(0, 0, 0, 0.18);
}

#mini-send-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s, background 0.2s;
}

#mini-send-btn:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
}

#mini-send-btn:active {
  transform: translateY(0);
}

.primary.small {
  padding: 8px 16px;
  font-size: 14px;
}

@media (max-width: 768px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-width: 320px;
    border-right: none;
    border-bottom: none;
    padding: 12px;
    gap: 12px;
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    background: var(--bg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
  }

  .sidebar.active {
    display: flex;
    animation: slideIn 0.2s ease;
  }

  @keyframes slideIn {
    from {
      transform: translateX(-100%);
    }
    to {
      transform: translateX(0);
    }
  }

  #close-sidebar {
    display: block !important;
  }

  #menu-toggle {
    display: flex !important;
  }

  .sidebar .brand {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
  }

  .sidebar-section {
    flex: 1;
  }

  .main {
    padding: 12px;
    gap: 12px;
  }

  .title {
    font-size: 20px;
  }

  .panel {
    grid-template-columns: repeat(2, 1fr);
    padding: 10px;
    gap: 10px;
  }

  .message {
    max-width: 95%;
    padding: 12px 16px;
  }

  .chat-area {
    min-height: 300px;
    padding: 12px;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
  }

  .topbar-actions {
    margin-top: 0;
  }

  .input-row {
    gap: 8px;
    flex-wrap: wrap;
  }

  textarea {
    width: 100%;
    flex: none;
    order: 1;
  }

  #send-btn {
    flex: 1;
    order: 2;
  }

  #mini-send-btn {
    order: 3;
  }

  .primary {
    padding: 10px 16px;
    font-size: 14px;
  }

  .sidebar .back-home {
    margin-top: 40px;
  }
}

.model-preview {
  margin-top: 6px;
  min-height: 32px;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.02);
}

.model-chip img {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  padding: 2px;
}

.admin-shell {
  max-width: 1400px;
  margin: 40px auto;
  padding: 0 16px 40px;
}

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

.admin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
}

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

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

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.admin-row .model-chip {
  border: none;
  padding: 0;
  background: transparent;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.admin-form input,
.admin-form select {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

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

#menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

#menu-toggle:hover {
  background: rgba(0, 66, 37, 0.05);
}

#menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}

.provider-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.provider-row-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.provider-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.provider-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  align-items: start;
}

.provider-column {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--panel-strong);
  min-height: 70px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.provider-column.overflow {
  background: #fff7e9;
}

.provider-column-header {
  font-weight: 700;
  color: var(--accent-2);
  font-size: 13px;
}

.provider-column-slot {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.provider-column-slot .provider-card {
  cursor: grab;
}

.provider-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.03);
  cursor: grab;
  position: relative;
}

.provider-card .delete-btn {
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  line-height: 1;
  background: transparent;
}

.provider-card .delete-btn:hover {
  background: rgba(176, 0, 32, 0.06);
  color: var(--danger);
}

.provider-card.dragging {
  opacity: 0.6;
}

.provider-column-slot .drag-over {
  outline: 2px dashed var(--accent);
}

.provider-column-slot.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
}

.priority-label {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--accent);
}

.provider-add-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.provider-add-row input {
  flex: 1;
  min-width: 160px;
}

/* Inline icon select for adding a provider */
.icon-select-inline {
  min-width: 120px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
}

/* Inline editor when clicking Edit icon on a model row */
.icon-editor {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
}

.icon-editor select,
.tier-editor select {
  min-width: 140px;
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 8px;
}

.tier-editor {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
}

.empty-slot {
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  background: transparent;
}

/* Loading indicator with spinner */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

/* Only animate in once when first shown, not on re-renders */
.loading-indicator.animate-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0, 66, 37, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}