/* Elegant Dark Monochrome — Chat Style */
* { box-sizing: border-box; }

body { 
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  margin: 0; 
  background: #0d0d0d;
  color: #e8e8e8; 
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app { 
  max-width: 640px; 
  margin: 0 auto; 
  padding: 24px 16px 48px; 
}

header {
  text-align: center;
  margin-bottom: 24px;
}

h1 { 
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 4px 0;
  letter-spacing: -0.3px;
  color: #f5f5f5;
}

.sub { 
  color: #888; 
  margin: 0;
  font-size: 13px;
}

.hint {
  color: #555;
  font-size: 12px;
  margin: 6px 0 0;
  line-height: 1.4;
}

.session-info {
  color: #555;
  font-size: 11px;
  margin-top: 4px;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-actions {
  display: flex;
  gap: 8px;
}

.quick-actions button {
  flex: 1;
}

button.compact {
  padding: 10px 14px;
  font-size: 13px;
}

textarea { 
  width: 100%; 
  border-radius: 12px; 
  border: 1px solid rgba(255, 255, 255, 0.08); 
  background: rgba(255, 255, 255, 0.04); 
  color: #e8e8e8; 
  padding: 14px; 
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  transition: all 0.3s ease;
}

textarea:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
}

textarea::placeholder { color: #555; }

button { 
  border: 0; 
  border-radius: 12px; 
  padding: 12px 16px; 
  cursor: pointer; 
  background: rgba(255, 255, 255, 0.08); 
  color: #e8e8e8; 
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
}

button:hover { background: rgba(255, 255, 255, 0.12); }
button:active { background: rgba(255, 255, 255, 0.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary { 
  background: rgba(255, 255, 255, 0.05);
  color: #aaa;
}
button.secondary:hover { background: rgba(255, 255, 255, 0.08); color: #ccc; }

/* ===== LOADING DOTS ===== */
@keyframes blink {
  0%, 20% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}
.loading-dots span { animation: blink 1.4s infinite; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

.loading-text {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  font-size: 14px;
  padding: 16px;
}
.loading-text::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #555;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== MAIN INPUT ===== */
.main-input {
  position: relative;
}

.main-input textarea {
  min-height: 80px;
  padding-right: 80px !important;
}

.voice-btn-main {
  position: absolute;
  right: 42px;
  top: 12px;
  padding: 6px;
  min-width: auto;
  background: transparent !important;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-btn-main svg { width: 20px; height: 20px; stroke: #666; }
.voice-btn-main:hover svg { stroke: #aaa; }

.send-btn-main {
  position: absolute;
  right: 6px;
  top: 12px;
  padding: 6px;
  min-width: auto;
  background: transparent !important;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn-main svg { width: 22px; height: 22px; stroke: #666; }
.send-btn-main:hover svg { stroke: #aaa; }

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #444, #888);
  border-radius: 2px;
  transition: width 0.2s ease;
  width: 0%;
}

/* ===== RATE LIMIT ===== */
.rate-limit {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: #555;
}
.rate-bar-track {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.rate-bar-fill {
  height: 100%;
  background: #444;
  transition: width 0.3s ease;
}
.rate-text { white-space: nowrap; }
.rate-warning .rate-bar-fill { background: #a33; }
.rate-warning .rate-text { color: #c66; }

/* ===== CHAT HISTORY ===== */
.chat-history {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-bubble {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}

.bubble-title {
  font-size: 16px;
  font-weight: 600;
  color: #f0f0f0;
}

.bubble-time {
  font-size: 11px;
  color: #555;
  white-space: nowrap;
}

.bubble-text {
  line-height: 1.8;
  color: #c8c8c8;
  font-size: 15px;
  margin-bottom: 14px;
}

.bubble-actions {
  display: flex;
  gap: 8px;
}

.bubble-save-btn {
  padding: 8px 14px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.06);
}

.loading-bubble {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.05);
}

/* ===== CONTINUATION ===== */
.continuation-section {
  animation: fadeIn 0.3s ease;
}

.continue-btn {
  width: 100%;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #e8e8e8;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, border-color 0.2s;
}
.continue-btn:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.15); }
.continue-btn .chapter-suggestion { color: #aaa; }

.or-divider {
  text-align: center;
  color: #444;
  font-size: 12px;
  margin: 10px 0;
}

.chat-input {
  position: relative;
}

.chat-input textarea {
  min-height: 44px;
  max-height: 100px;
  padding-right: 76px !important;
}

.voice-btn-inner {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px;
  min-width: auto;
  background: transparent;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-btn-inner svg { width: 18px; height: 18px; stroke: #666; }
.voice-btn-inner:hover svg { stroke: #aaa; }
.voice-btn-inner:hover { transform: translateY(-50%); }

.send-btn-inner {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px;
  min-width: auto;
  background: transparent;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn-inner svg { width: 20px; height: 20px; stroke: #666; }
.send-btn-inner:hover svg { stroke: #aaa; }
.send-btn-inner:hover { transform: translateY(-50%); }

/* ===== BOOK ===== */
#bookList { margin-top: 8px; }

#bookList:empty::after {
  content: 'Пока пусто ⭐';
  display: block;
  text-align: center;
  color: #444;
  font-size: 13px;
  padding: 16px;
}

.book-item { 
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.book-item:hover { background: rgba(255, 255, 255, 0.06); }

.book-item-title {
  flex: 1;
  cursor: pointer;
  color: #bbb;
}
.book-item-title:hover { color: #f5f5f5; }
.book-item-title small { color: #555; margin-left: 4px; }

.delete-btn-flat {
  padding: 6px;
  background: transparent;
  border-radius: 50%;
  min-width: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.delete-btn-flat svg { stroke: #555; transition: stroke 0.2s; }
.delete-btn-flat:hover { background: rgba(255,60,60,0.1); }
.delete-btn-flat:hover svg { stroke: #f55; }

.continue-last {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #bbb;
}
.continue-last:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e8e8e8;
}

.hidden { display: none; }

/* Voice recording */
.voice-btn-inner.recording,
.voice-btn-main.recording {
  animation: pulse-recording 1s infinite;
}
.voice-btn-inner.recording svg,
.voice-btn-main.recording svg {
  stroke: #f44;
}
@keyframes pulse-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Fallback notice */
.bubble-fallback {
  font-size: 0.8rem;
  color: #f5a623;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(245, 166, 35, 0.1);
  border-radius: 6px;
  border-left: 3px solid #f5a623;
}

/* Model indicator dot */
.model-dot {
  position: absolute;
  right: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 1.5s ease-out;
  pointer-events: none;
}
.model-dot.model-ok {
  background: #4a4;
  box-shadow: 0 0 6px rgba(68, 170, 68, 0.6);
}
.model-dot.model-fail {
  background: #a44;
  box-shadow: 0 0 6px rgba(170, 68, 68, 0.6);
}
.main-input {
  position: relative;
}

/* Settings toolbar */
.settings-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.25);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.settings-toggle:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.5);
}

.settings-panel {
  position: fixed;
  bottom: 60px;
  right: 16px;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
.settings-panel:not(.hidden) {
  display: flex;
}
.settings-panel button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.5);
  font-size: 15px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.06);
}
.settings-panel button:hover {
  background: rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.8);
}
