* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #222);
  min-height: 100vh; overflow-x: hidden;
}

#app { max-width: 480px; margin: 0 auto; padding: 12px; }

.hidden { display: none !important; }

h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

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

/* Worker badge */
.worker-badge {
  font-size: 11px; padding: 4px 10px; border-radius: 20px; font-weight: 600;
  background: #fff3e0; color: #e65100;
}
.worker-badge.online { background: #e8f5e9; color: #2e7d32; }
.worker-badge.offline { background: #fff3e0; color: #e65100; }

/* Swipe-to-reveal */
.sr-wrap {
  position: relative; overflow: hidden;
  border-radius: 14px; margin-bottom: 10px;
}
.sr-actions-right {
  position: absolute; right: 0; top: 0; bottom: 0;
  display: flex; align-items: stretch;
  pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.sr-wrap.reveal-right .sr-actions-right { pointer-events: auto; opacity: 1; }
.sr-actions-left {
  position: absolute; left: 0; top: 0; bottom: 0;
  display: flex; align-items: stretch;
  pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.sr-wrap.reveal-left .sr-actions-left { pointer-events: auto; opacity: 1; }
.sr-action {
  width: 76px; min-height: 100%; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: #fff;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.1s;
}
.sr-action:active { filter: brightness(0.75); }
.sr-action .sr-icon { font-size: 22px; line-height: 1; }
.sr-action .sr-label { font-size: 11px; font-weight: 600; letter-spacing: 0.02em; }
.sr-act-pin { background: #ff9800; }
.sr-act-archive { background: #78909c; }
.sr-act-edit { background: #3390ec; }
.sr-act-sandbox { background: #43a047; }
.sr-act-delete { background: #e53935; }
.sr-wrap.pinned .sr-content { border-left: 3px solid #ff9800; }
.status-badge { font-size: 11px; margin-left: 6px; }
.pin-badge { color: #ff9800; }
.archive-badge { color: #78909c; }
.project-card.archived { opacity: 0.55; }
.sr-content {
  position: relative; z-index: 1;
  transform: translate3d(0, 0, 0);
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
}

/* Project card */
.project-card {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 14px; padding: 14px; cursor: pointer;
}
.pc-row { display: flex; justify-content: space-between; align-items: center; }
.project-name { font-weight: 600; font-size: 16px; flex: 1; }
.project-desc { font-size: 13px; color: var(--tg-theme-hint-color, #888); margin-top: 4px; }
.project-meta { font-size: 12px; color: var(--tg-theme-hint-color, #aaa); margin-top: 6px; display: flex; gap: 12px; }
.pc-edit { font-size: 14px; opacity: 0.5; }

/* Buttons */
.btn-primary {
  display: block; width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--tg-theme-button-color, #3390ec); color: var(--tg-theme-button-text-color, #fff);
  font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 16px;
}
.btn-primary:disabled { opacity: 0.5; }

.btn-back {
  background: none; border: none; font-size: 16px; cursor: pointer;
  color: var(--tg-theme-button-color, #3390ec); padding: 8px 0; font-weight: 600;
}

.btn-icon { background: none; border: none; font-size: 16px; cursor: pointer; padding: 4px; }

/* Inputs */
input[type="text"], textarea {
  display: block; width: 100%; padding: 12px 14px; border: none; border-radius: 12px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5); color: var(--tg-theme-text-color, #222);
  font-size: 15px; outline: none; margin-bottom: 10px; resize: none; font-family: inherit;
}

/* Chat */
.chat-header {
  display: flex; align-items: center; gap: 8px; padding: 8px 0 12px;
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color, #eee); margin-bottom: 8px;
}
.chat-title { flex: 1; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#chat-messages {
  height: calc(100vh - 180px); overflow-y: auto; padding: 8px 0;
  display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch;
}

.msg {
  padding: 10px 14px; border-radius: 14px; max-width: 85%;
  font-size: 14px; line-height: 1.5; word-break: break-word;
}
.msg-user {
  background: var(--tg-theme-button-color, #3390ec); color: #fff;
  align-self: flex-end; border-bottom-right-radius: 4px;
}
.msg-assistant {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  align-self: flex-start; border-bottom-left-radius: 4px;
}
.msg-assistant pre {
  background: #1a1a2e; color: #e0e0e0; padding: 10px; border-radius: 8px;
  overflow-x: auto; font-size: 13px; margin: 6px 0; white-space: pre-wrap;
}
.msg-assistant code {
  background: rgba(0,0,0,0.08); padding: 2px 5px; border-radius: 4px; font-size: 13px;
}
.msg-system {
  align-self: center; text-align: center; font-size: 12px;
  color: var(--tg-theme-hint-color, #888); padding: 4px 12px;
}

#chat-typing {
  text-align: center; font-size: 13px; color: var(--tg-theme-hint-color, #888);
  padding: 8px; animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.chat-input-wrap {
  display: flex; gap: 8px; padding-top: 8px;
  border-top: 1px solid var(--tg-theme-secondary-bg-color, #eee);
}
.chat-input-wrap textarea { flex: 1; margin-bottom: 0; padding: 10px 14px; min-height: 40px; max-height: 100px; }
.chat-input-wrap button {
  padding: 10px 16px; border: none; border-radius: 12px;
  background: var(--tg-theme-button-color, #3390ec); color: #fff;
  font-size: 18px; cursor: pointer; align-self: flex-end;
}
.chat-input-wrap button:disabled { opacity: 0.5; }

/* Sandbox */
.sandbox-header { display: flex; align-items: center; gap: 10px; padding: 8px 0 12px; }
.sandbox-title { flex: 1; font-weight: 600; font-size: 16px; }
.sandbox-frame {
  width: 100%; height: calc(100vh - 80px); border: none; border-radius: 12px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
}

/* Archive folder */
.archive-folder { margin-bottom: 12px; }
.af-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px; cursor: pointer;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
}
.af-row:active { opacity: 0.7; }
.af-icon { font-size: 20px; }
.af-name { font-weight: 600; font-size: 15px; flex: 1; }
.af-count {
  font-size: 12px; font-weight: 600; color: #fff; background: #78909c;
  padding: 2px 8px; border-radius: 10px; min-width: 20px; text-align: center;
}
.af-arrow { font-size: 20px; color: var(--tg-theme-hint-color, #aaa); transition: transform 0.2s; }
.af-list { padding-top: 8px; }

/* Delete dialog */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  background: var(--tg-theme-bg-color, #fff); border-radius: 16px;
  padding: 24px 20px; width: 100%; max-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.dialog-icon { text-align: center; font-size: 36px; margin-bottom: 8px; }
.dialog-title { text-align: center; font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.dialog-text { text-align: center; font-size: 13px; color: var(--tg-theme-hint-color, #888); margin-bottom: 16px; line-height: 1.4; }
.dialog-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.dialog-btn {
  display: block; width: 100%; padding: 12px; border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer; text-align: center;
}
.dialog-btn-archive { background: #eceff1; color: #546e7a; }
.dialog-btn-download { background: #e8f5e9; color: #2e7d32; }
.dialog-confirm { border-top: 1px solid var(--tg-theme-secondary-bg-color, #eee); padding-top: 16px; }
.dialog-hint { font-size: 13px; color: var(--tg-theme-hint-color, #888); margin-bottom: 8px; }
.dialog-expected {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5); padding: 8px 12px;
  border-radius: 8px; font-weight: 600; font-size: 14px; margin-bottom: 8px;
  text-align: center; user-select: all;
}
.dialog-input {
  width: 100%; padding: 10px 12px; border: 2px solid var(--tg-theme-secondary-bg-color, #ddd);
  border-radius: 10px; font-size: 15px; outline: none; margin-bottom: 12px;
  background: var(--tg-theme-bg-color, #fff); color: var(--tg-theme-text-color, #222);
}
.dialog-input:focus { border-color: #e53935; }
.dialog-buttons { display: flex; gap: 8px; }
.dialog-btn-cancel { flex: 1; background: var(--tg-theme-secondary-bg-color, #f4f4f5); color: var(--tg-theme-text-color, #222); }
.dialog-btn-delete { flex: 1; background: #e53935; color: #fff; }
.dialog-btn-delete:disabled { opacity: 0.35; cursor: default; }

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--tg-theme-hint-color, #888); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }
