:root {
  --bg-dark: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-panel-hover: #f4f5f7;
  --border-color: #dfe1e5;
  --accent: #3390ec;
  --accent-hover: #2481d7;
  --text-main: #000000;
  --text-muted: #707579;
  --success: #3390ec;
  --error: #e53935;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 260px 320px 1fr;
  gap: 1.5rem;
  height: calc(100vh - 3rem);
  box-sizing: border-box;
}

.glass-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3 { margin-top: 0; margin-bottom: 1rem; font-weight: 600; }

.title {
  color: var(--text-main);
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

/* Form Elements */
label { display: block; font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.4rem; margin-top: 1rem; font-weight: 500; }
select, input[type="date"], input[type="text"] {
  width: 100%;
  background: #f4f5f7;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  box-sizing: border-box;
  transition: all 0.2s;
}
select:focus, input[type="text"]:focus, input[type="date"]:focus {
    border-color: var(--accent);
    background: #ffffff;
}

.checkbox-group {
  margin-top: 0.5rem;
  max-height: 120px;
  overflow-y: auto;
  background: #f4f5f7;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}
.checkbox-item { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.9rem; }

/* Buttons */
button.primary {
  background: var(--accent);
  color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 8px;
  font-size: 1rem; font-weight: 500; cursor: pointer; transition: all 0.2s; width: 100%;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: #f4f5f7; border: 1px solid var(--border-color);
  color: var(--accent); padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; width: 100%; font-weight: 500; transition: all 0.2s;
}
button.secondary:hover { background: #e5e7eb; }

/* Chat List Sidebar (Col 1) */
.chat-list { flex: 1; overflow-y: auto; margin-top: 1rem; margin-right: -1rem; padding-right: 1rem; }
.chat-list-item {
  padding: 0.8rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.chat-list-item:hover { background: var(--bg-panel-hover); }
.chat-list-item.active {
  background: var(--accent);
  color: white;
}
.chat-list-item.active .chat-item-date { color: rgba(255, 255, 255, 0.8); }
.chat-item-title { font-size: 0.95rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

/* Filter Box (Col 2) */
.filter-body { overflow-y: auto; flex: 1; padding-right: 0.5rem; margin-right: -0.5rem; }
.stat-box {
  background: #f4f5f7; border: 1px solid var(--border-color);
  border-radius: 8px; padding: 0.8rem; margin-top: 1.5rem; text-align: center;
}
.stat-value { font-size: 1.3rem; font-weight: bold; color: var(--text-main); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* Progress Bar */
.progress-container { margin-top: 1rem; background: #e5e7eb; border-radius: 8px; overflow: hidden; height: 8px; }
.progress-bar { background: var(--accent); height: 100%; width: 0%; transition: width 0.3s ease; }
.status-text { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; text-align: center; }

/* Logs */
.logs-panel { margin-top: 1rem; }
.logs-toggle { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 0.9rem; padding: 0; font-weight: 500;}
.logs-content {
  background: #f4f5f7; padding: 0.5rem; border-radius: 6px; font-size: 0.8rem; border: 1px solid var(--border-color); color: var(--text-main);
  max-height: 180px; overflow-y: auto; font-family: SFMono-Regular, Consolas, monospace; margin-top: 0.5rem;
}
.log-item.ERROR { color: var(--error); font-weight: bold; }
.log-item.WARN { color: #d97706; font-weight: 600; }
.log-item.INFO { color: var(--text-muted); }

/* Chat Area (Col 3) */
.chat-container {
    background-color: #e4eddb; /* Telegram light background */
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 100l50-50" stroke="%23d2e3c0" stroke-width="2" fill="none"/></svg>');
    background-size: 300px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.chat-history { flex: 1; overflow-y: auto; margin-bottom: 1rem; padding-right: 0.5rem; display: flex; flex-direction: column; }
.message { margin-bottom: 0.8rem; padding: 0.6rem 0.9rem; border-radius: 14px; max-width: 80%; line-height: 1.4; font-size: 0.95rem; box-shadow: 0 1px 2px rgba(0,0,0,0.1); word-wrap: break-word;}
.message.user { background: #effdde; margin-left: auto; border-bottom-right-radius: 4px; color: #000; }
.message.ai { background: #ffffff; margin-right: auto; border-bottom-left-radius: 4px; white-space: pre-wrap; color: #000; }
.message.pending { animation: pulseBg 2s infinite; color: var(--text-muted); background: #ffffff; margin-right: auto; }
.message.error { background: #fee2e2; color: #991b1b; }
.message.system {
    color: #ffffff; text-align: center; font-size: 0.8rem; background: rgba(0,0,0,0.15); padding: 0.2rem 0.6rem;
    margin: 0.5rem auto; width: fit-content; border-radius: 12px; box-shadow: none; border: none; font-weight: 500;
}

.chat-input { display: flex; gap: 0.5rem; align-items: stretch; background: #ffffff; padding: 0.5rem; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border-color);}
.chat-input input { flex: 1; margin: 0; border: none; background: transparent; font-size: 1rem; }
.chat-input input:focus { border: none; }
.chat-input button { width: auto; margin: 0; border-radius: 8px;}

.spinner {
  display: inline-block; width: 1rem; height: 1rem; border: 2px solid rgba(51, 144, 236, 0.3);
  border-radius: 50%; border-top-color: var(--accent); animation: spin 1s linear infinite; margin-right: 0.5rem; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulseBg { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }

/* Modals */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4); 
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 2rem; box-sizing: border-box;
}
.modal-content {
  width: 100%; max-width: 1200px; height: 90vh;
  display: flex; flex-direction: column;
}
.full-screen-logs {
  height: auto; max-height: none; flex: 1; margin-top: 1rem; padding: 1rem; font-size: 0.9rem;
}

/* Responsive Mobile Breaks */
@media (max-width: 1024px) {
  body { overflow: auto; height: auto; }
  .app-container {
    display: flex;
    flex-direction: column;
    height: auto;
    padding: 1rem;
    gap: 1rem;
  }
  .glass-panel {
    min-height: 300px;
  }
  .chat-history {
    min-height: 400px;
  }
}
