/* Smee PWA — Claude-style dark theme */

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

:root {
  --bg: #2b2b2b;
  --bg-sidebar: #202020;
  --bg-input: #3b3b3b;
  --bg-input-focus: #404040;
  --bg-user-msg: #4a4a4a;
  --bg-asst-msg: transparent;
  --text: #ececec;
  --text-dim: #8e8e8e;
  --text-muted: #6b6b6b;
  --accent: #c96442;
  --accent-hover: #b5593a;
  --border: #383838;
  --sidebar-w: 260px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

#app {
  display: flex;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ======== Sidebar ======== */

#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  z-index: 20;
}

.sidebar-header {
  display: flex;
  align-items: center;
  padding: 12px;
  gap: 8px;
}

.sidebar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.sidebar-header button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}

.sidebar-header button:hover { background: var(--bg-input); }

#sidebar-close { display: none; }

.search-box {
  padding: 0 12px 8px;
}

.search-box input {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.search-box input:focus { border-color: var(--text-muted); }

#conv-list {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 8px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}
.conv-label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.unread-badge {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 5px;
}

.conv-item:hover { background: var(--bg-input); color: var(--text); }
.conv-item.active { background: var(--bg-input); color: var(--text); }
.conv-item.archived { color: var(--text-muted); font-style: italic; }

.conv-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ======== Main ======== */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#topbar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 12px;
  height: 44px;
  flex-shrink: 0;
}

#topbar-title {
  flex: 1;
  font-size: 14px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: none; /* shown on mobile */
}

#sidebar-toggle:hover { background: var(--bg-input); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.dot.ok { background: #4ecca3; }

/* ======== Home Screen ======== */

#home-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 32px;
}

.home-greeting {
  font-size: 28px;
  font-weight: 300;
  color: var(--text);
  letter-spacing: -0.5px;
}

.home-input-wrap {
  width: 100%;
  max-width: 600px;
  background: var(--bg-input);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.home-input-wrap:focus-within {
  border-color: var(--text-muted);
}

#home-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 200px;
  outline: none;
  line-height: 1.5;
}

#home-input::placeholder { color: var(--text-muted); }

#home-send {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

#home-send:hover { background: var(--accent-hover); }

/* ======== Chat Screen ======== */

#chat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#message-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.message {
  max-width: 85%;
  padding: 12px 0;
}

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.message-content {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.user .message-content {
  background: var(--bg-user-msg);
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
}

.assistant .message-content {
  padding: 4px 0;
  color: var(--text);
  white-space: normal;
}

/* Markdown in assistant messages */
.assistant .message-content p { margin: 0 0 4px; }
.assistant .message-content p:last-child { margin-bottom: 0; }
.assistant .message-content h1,
.assistant .message-content h2,
.assistant .message-content h3 {
  margin: 8px 0 3px;
  font-size: 15px;
  font-weight: 600;
}
.assistant .message-content h1 { font-size: 17px; }
.assistant .message-content ul,
.assistant .message-content ol {
  margin: 2px 0 4px 20px;
}
.assistant .message-content li { margin: 1px 0; }
.assistant .message-content code {
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}
.assistant .message-content pre {
  background: var(--bg-sidebar);
  padding: 12px;
  border-radius: 8px;
  margin: 8px 0;
  overflow-x: auto;
}
.assistant .message-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}
.assistant .message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-dim);
}
.assistant .message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}
.assistant .message-content thead {
  border-bottom: 2px solid var(--border);
}
.assistant .message-content th {
  text-align: left;
  padding: 6px 10px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.assistant .message-content td {
  padding: 5px 10px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
}
.assistant .message-content tr:hover td {
  background: var(--bg-input);
}
.assistant .message-content strong { font-weight: 600; }
.assistant .message-content a { color: var(--accent); text-decoration: none; }
.assistant .message-content a:hover { text-decoration: underline; }

.message-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 2px;
}

.user .message-meta { text-align: right; }

/* Streaming indicator — cursor on the last text element */
.message.streaming .message-content::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ======== Collapsible Stream Sections ======== */

.stream-section {
  margin: 6px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  font-size: 13px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-sidebar);
  transition: background 0.15s;
}

.section-header:hover { background: var(--bg-input); }

.section-chevron::before {
  content: '\25B6'; /* right triangle */
  display: inline-block;
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.stream-section.expanded .section-chevron::before {
  transform: rotate(90deg);
}

.section-label {
  flex: 1;
  color: var(--text-dim);
  font-weight: 500;
}

.stream-section.active .section-label {
  color: var(--accent);
}

.section-status {
  color: #4ecca3;
  font-weight: 600;
  font-size: 12px;
}

.section-body {
  display: none;
}

.stream-section.expanded .section-body {
  display: block;
}

.section-content {
  padding: 8px 12px;
  background: var(--bg);
}

/* Thinking section */
.thinking-section {
  border-color: rgba(201, 100, 66, 0.3);
}

.thinking-section.active {
  border-color: var(--accent);
}

.thinking-content {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

/* Active thinking — pulsing border */
.thinking-section.active {
  animation: thinking-pulse 2s ease-in-out infinite;
}

@keyframes thinking-pulse {
  0%, 100% { border-color: rgba(201, 100, 66, 0.3); }
  50% { border-color: var(--accent); }
}

/* Tool call section */
.tool-section {
  border-color: rgba(58, 134, 255, 0.3);
}

.tool-section.active {
  border-color: rgba(58, 134, 255, 0.6);
}

.tool-section.active .section-label {
  color: #3a86ff;
}

/* Spinner for active tool calls */
.tool-section.active .section-status::after {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(58, 134, 255, 0.3);
  border-top-color: #3a86ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.tool-input-display {
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
  font-size: 11px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  line-height: 1.4;
  max-height: 150px;
  overflow-y: auto;
}

.tool-result-display {
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
  font-size: 11px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  line-height: 1.4;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.tool-result-display:empty {
  display: none;
}

/* Input area */
#input-area {
  padding: 12px 20px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

#message-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 150px;
  outline: none;
  line-height: 1.5;
}

#message-input:focus { border-color: var(--text-muted); }
#message-input::placeholder { color: var(--text-muted); }

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

#send-btn:hover { background: var(--accent-hover); }

/* ======== Drop Zone ======== */

.home-input-wrap.drop-active,
#input-area.drop-active {
  border-color: var(--accent) !important;
  background: rgba(201, 100, 66, 0.08);
  box-shadow: inset 0 0 0 2px var(--accent);
  transition: all 0.15s;
}

.home-input-wrap.drop-active::after,
#input-area.drop-active::after {
  content: 'Drop file here';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}

.home-input-wrap,
#input-area {
  position: relative;
}

/* ======== Approval Panel ======== */

#approval-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 300px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  z-index: 30;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.panel-header button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.panel-header button:hover { background: var(--bg-input); }

.approval-card {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.approval-tool {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.approval-input {
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0 8px;
  word-break: break-all;
  max-height: 60px;
  overflow: hidden;
}

.approval-actions { display: flex; gap: 6px; }

.approval-actions button {
  flex: 1;
  padding: 6px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-approve { background: #4ecca3; color: #000; }
.btn-deny { background: var(--accent); color: #fff; }
.btn-feedback { background: #3a86ff; color: #fff; }
.approval-actions button:hover { opacity: 0.85; }

.approval-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Floating approval badge */
#approval-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#approval-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e94560;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ======== Mobile ======== */

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-w));
    top: 0;
    bottom: 0;
    transition: left 0.2s ease;
  }

  #sidebar.open { left: 0; }
  #sidebar-close { display: flex; }
  #sidebar-toggle { display: flex; }

  .home-greeting { font-size: 22px; }
}

/* ======== Desktop ======== */

@media (min-width: 769px) {
  #sidebar-toggle { display: none; }
}

/* ======== Archive View ======== */

.archive-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  gap: 12px;
  flex: 1;
}

.archive-icon {
  color: var(--text-muted);
  margin-bottom: 8px;
}

.archive-notice h3 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}

.archive-notice p {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 400px;
}

.archive-meta {
  font-size: 12px !important;
  color: var(--text-muted) !important;
}

.btn-load-archive {
  margin-top: 12px;
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-load-archive:hover { background: var(--accent-hover); }
.btn-load-archive:disabled { opacity: 0.6; cursor: default; }

/* ======== Status Bar ======== */

#status-bar {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.3px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  flex-shrink: 0;
}

/* ======== Queued Label ======== */

.queued-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 2px;
  text-align: right;
  font-style: italic;
}

/* ======== Queue Delivered Section ======== */

.queue-delivered-section {
  border-color: rgba(78, 204, 163, 0.3);
}

.queue-delivered-section .section-label {
  color: #4ecca3;
}

.queue-delivered-section .section-status {
  background: rgba(78, 204, 163, 0.15);
  color: #4ecca3;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 11px;
}

.queue-delivered-content {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

/* ======== UNODIR Card ======== */

.unodir-card {
  border: 1px solid rgba(58, 134, 255, 0.4);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}

.unodir-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-sidebar);
}

.unodir-icon {
  background: #3a86ff;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.unodir-title {
  flex: 1;
  font-weight: 500;
  color: var(--text);
}

.unodir-timer {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  color: #3a86ff;
  font-weight: 600;
}

.unodir-timer.resolved {
  color: #4ecca3;
}

.unodir-reasoning {
  padding: 8px 12px 0;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.unodir-order {
  padding: 8px 12px;
}

.unodir-item {
  padding: 4px 0;
  color: var(--text);
  font-size: 13px;
}

.unodir-actions {
  display: flex;
  gap: 6px;
  padding: 8px 12px 12px;
}

.unodir-actions button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.unodir-actions .btn-approve { background: #4ecca3; color: #000; }
.unodir-actions .btn-deny { background: var(--bg-input); color: var(--text); }
.unodir-actions button:hover { opacity: 0.85; }
