:root {
  --primary-color: #3390ec;
  --secondary-color: #6c757d;
  --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  color: #334e68;
}

.glass-container {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: none;
  box-shadow: none;
  border-radius: 0;
  width: 100%;
  flex: 1;
  padding: 24px;
  position: relative;
  transition: all 0.5s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.header h1 {
  font-size: 22px;
  font-weight: 600;
  color: #102a43;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.tg-icon {
  width: 26px;
  height: 26px;
  color: var(--primary-color);
}

/* Tabs */
.tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 24px;
}

body.tg-mode-dark .tabs {
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--secondary-color);
  background: transparent;
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
}

.tab-btn.active {
  background: white;
  color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

body.tg-mode-dark .tab-btn.active {
  background: #242f3d;
  color: white;
}

/* Pages */
.page {
  display: none;
  flex-direction: column;
  gap: 20px;
  animation: slideIn 0.3s ease-out;
  flex: 1;
}

.page.active {
  display: flex;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Channels List */
.channels-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.channel-item {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  transition: all 0.2s ease;
}

.channel-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.mode-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  padding: 2px;
}

.mode-selector.disabled-selector {
  opacity: 0.3;
  filter: grayscale(100%);
  pointer-events: none;
}

body.tg-mode-dark .mode-selector {
  background: rgba(255, 255, 255, 0.05);
}

.mode-btn {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--secondary-color);
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.mode-btn.active {
  background: white;
  color: var(--primary-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.mode-btn:first-child.active {
  color: #e74c3c;
}

body.tg-mode-dark .mode-btn.active {
  background: #242f3d;
  color: white;
}

body.tg-mode-dark .mode-btn:first-child.active {
  color: #ff6b6b;
}

.channel-item.mode-off {
  opacity: 0.7;
}

.channel-item.mode-search {
  border-left: 3px solid var(--primary-color);
}

.search-criteria-box {
  background: rgba(51, 144, 236, 0.05);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.criteria-input {
  background: transparent;
  border: 1px solid rgba(51, 144, 236, 0.2);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  min-height: 60px;
  color: inherit;
  outline: none;
}

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

.save-criteria-btn {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
  height: auto;
}

.save-criteria-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.save-criteria-btn.success {
  background: #27ae60 !important;
  color: white !important;
  animation: pulseSuccess 0.4s ease-in-out;
}

@keyframes pulseSuccess {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.criteria-input:focus {
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.5);
}

body.tg-mode-dark .criteria-input:focus {
  background: rgba(0, 0, 0, 0.2);
}

.criteria-hint {
  font-size: 11px;
  color: var(--secondary-color);
  font-style: italic;
}

body.tg-mode-dark .channel-item {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
}

.channel-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.channel-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

.channel-meta {
  font-size: 12px;
  color: var(--secondary-color);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.channel-item.awaiting-approval {
  opacity: 0.8;
  border-style: dashed;
  border-width: 1.5px;
}

.status-badge {
  font-size: 9px;
  background: #f1c40f;
  color: #102a43;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
}

body.tg-mode-dark .status-badge {
  background: #f39c12;
  color: #fff;
}

.approve-btn {
  background: #27ae60;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.approve-btn:hover {
  background: #2ecc71;
  transform: translateY(-1px);
}

/* Filters List */
.filters-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.filter-item {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
}

body.tg-mode-dark .filter-item {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
}

.filter-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.filter-context {
  font-weight: 500;
  font-size: 14px;
  color: inherit;
}

.delete-btn {
  background: transparent;
  color: #e74c3c;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.delete-btn:hover {
  background: rgba(231, 76, 60, 0.1);
  transform: scale(1.1);
}

/* Add Channel */
.add-channel-box {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  gap: 8px;
}

input {
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid #bcccdc;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.3s ease;
  width: 100%;
}

input:focus {
  border-color: var(--primary-color);
  background: white;
}

.primary-btn {
  background: var(--primary-color);
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.primary-btn:hover {
  background: #2884e6;
  transform: translateY(-1px);
}

.placeholder-text {
  text-align: center;
  color: var(--secondary-color);
  font-size: 14px;
  margin-top: 40px;
  line-height: 1.6;
}

/* Overlay & Spinner */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.hidden { display: none; }

.spinner {
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}


/* Dark Mode */
body.tg-mode-dark {
  --bg-gradient: linear-gradient(135deg, #101921 0%, #0c141a 100%);
  --glass-bg: rgba(23, 33, 43, 0.85);
  --glass-border: rgba(255, 255, 255, 0.05);
  color: #f5f5f5;
}

body.tg-mode-dark .header h1 { color: white; }
body.tg-mode-dark input {
  background: rgba(14, 22, 33, 0.7);
  border-color: #242f3d;
  color: white;
}
body.tg-mode-dark .overlay { background: rgba(23, 33, 43, 0.8); }
body.tg-mode-dark .placeholder-text { color: #8da4b8; }

/* Confirm Filter Page */
#page-confirm-filter {
    padding-bottom: 20px;
}

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

.confirm-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.confirm-header p {
    font-size: 14px;
    color: var(--secondary-color);
}

.history-container {
    margin: 16px 0;
    padding: 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

body.tg-mode-dark .history-container {
    background: rgba(255, 255, 255, 0.03);
}

.history-item {
    padding: 4px 8px;
    border-radius: 8px;
}

.history-item-user {
    align-self: flex-end;
    background: rgba(51, 144, 236, 0.1);
    color: var(--primary-color);
}

.history-item-assistant {
    align-self: flex-start;
    background: rgba(0, 0, 0, 0.05);
    color: var(--secondary-color);
}

body.tg-mode-dark .history-item-assistant {
    background: rgba(255, 255, 255, 0.1);
    color: #eee;
}

.confirm-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
}

.option-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
    border-radius: 16px;
    border: 1.5px solid #eee;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

body.tg-mode-dark .option-btn {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.1);
    color: white;
}

.option-btn:hover {
    border-color: var(--primary-color);
    background: rgba(51, 144, 236, 0.05);
    transform: translateY(-2px);
}

.option-label {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.option-text {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
}

.confirm-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.refine-box {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 16px;
    padding: 12px;
    border: 1px dashed rgba(0, 0, 0, 0.1);
}

body.tg-mode-dark .refine-box {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.1);
}

.refine-box p {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    text-align: left;
    color: var(--secondary-color);
}

.secondary-btn {
    background: rgba(0, 0, 0, 0.05);
    color: var(--secondary-color);
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

body.tg-mode-dark .secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: #8da4b8;
}

.full-width {
    width: 100%;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Settings Page Styles */
.settings-group {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

body.tg-mode-dark .settings-group {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.05);
}

.settings-group h3 {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
    color: var(--secondary-color);
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.setting-item:last-child {
    border-bottom: none;
}

body.tg-mode-dark .setting-item {
    border-color: rgba(255, 255, 255, 0.05);
}

.setting-label {
    font-size: 15px;
    font-weight: 500;
}

.glass-select, .glass-select-small, .glass-input {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    color: inherit;
}

body.tg-mode-dark .glass-select, 
body.tg-mode-dark .glass-select-small, 
body.tg-mode-dark .glass-input {
    background: rgba(14, 22, 33, 0.7);
    border-color: #242f3d;
}

.glass-select-small {
    padding: 4px 8px;
    min-width: 80px;
}

.time-range {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--secondary-color);
}

.hidden {
    display: none !important;
}

/* Auto-save Status */
.save-status {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #27ae60;
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
    pointer-events: none;
}

.save-status.show {
    animation: fadeInOut 2s ease forwards;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -10px); }
    15% { opacity: 1; transform: translate(-50%, 0); }
    85% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -10px); }
}
