/* ─── MailMindHub WebUI Style - Browser Panel Design ───────────────────────── */

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

:root {
  /* Base colors - Dark theme */
  --bg:           #0a0a0a;
  --bg2:          #141414;
  --bg3:          #1a1a1a;
  --fg:           #e0e0e0;
  --muted:        #666;
  --muted2:       #888;
  --border:       #2a2a2a;
  --border2:      #333;
  
  /* Accent colors */
  --green:        #22c55e;
  --green-dim:    rgba(34, 197, 94, 0.1);
  --green-border: rgba(34, 197, 94, 0.3);
  --cyan:         #00e5c3;
  --cyan-dim:     rgba(0, 229, 195, 0.1);
  --amber:        #f0a500;
  --amber-dim:    rgba(240, 165, 0, 0.1);
  --red:          #ff5b6e;
  --red-dim:      rgba(255, 91, 110, 0.1);
  
  /* Log colors */
  --log-bg:       #0d0d0d;
  --log-fg:       #a3e635;
  --log-warn:     #fbbf24;
  --log-err:      #f87171;
  
  /* Scrollbar */
  --scrollbar:      #333;
  --scrollbar-hover:#444;

  /* Fonts */
  --font:         'JetBrains Mono', Menlo, Monaco, Consolas, monospace;
}

body {
  font-family: var(--font);
  font-size: 12px;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  min-width: 0;
}

.logo {
  font-family: var(--font);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--fg);
  padding: 0 16px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  height: 100%;
  display: flex;
  align-items: center;
}

.logo-brand {
  color: var(--green);
  font-weight: 700;
}

/* ─── Control Bar (above nav tabs) ─────────────────────────────────────────── */
.control-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  height: 34px;
  display: flex;
  align-items: center;
}

#header-status {
  display: flex;
  align-items: center;
  width: 100%;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex: 1;
  min-width: 0;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-dot.off {
  background: #444;
  animation: none;
}

.status-info {
  font-size: 10px;
  color: var(--muted2);
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header actions */
.header-actions {
  display: flex;
  gap: 4px;
  padding-right: 12px;
  flex-shrink: 0;
}

.header-btn {
  font-family: var(--font);
  font-size: 9px;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--muted2);
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  font-weight: 500;
}

.header-btn:hover:not(:disabled) {
  border-color: var(--green-border);
  color: var(--green);
}

.header-btn.run:not(:disabled) {
  border-color: var(--green-border);
  color: var(--green);
}

.header-btn.run:not(:disabled):hover {
  background: var(--green-dim);
}

.header-btn.stop:not(:disabled) {
  border-color: rgba(255, 91, 110, 0.4);
  color: var(--red);
}

.header-btn.stop:not(:disabled):hover {
  background: var(--red-dim);
}

.header-btn:disabled {
  border-color: var(--border);
  color: #444;
  cursor: not-allowed;
}

/* Language switcher */
.lang-switch {
  display: flex;
  gap: 2px;
  padding-right: 12px;
  border-left: 1px solid var(--border);
  margin-left: 8px;
}

.lang-switch a {
  font-family: var(--font);
  font-size: 10px;
  padding: 3px 6px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.04em;
  border-radius: 3px;
  transition: all 0.15s;
}

.lang-switch a:hover {
  color: var(--fg);
}

.lang-switch a.active {
  color: var(--green);
  background: var(--green-dim);
}

/* ─── Navigation Tabs ───────────────────────────────────────────────────────── */
nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0;
  display: flex;
  gap: 0;
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 18px;
  font-family: var(--font);
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all 0.15s;
  position: relative;
}

.tab:hover {
  color: var(--fg);
  background: var(--bg3);
}

.tab.active {
  color: var(--fg);
  border-bottom-color: var(--green);
  background: var(--bg);
}

/* ─── Main Content ──────────────────────────────────────────────────────────── */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 18px;
}

label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--fg);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
  border-radius: 0;
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green-border);
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.hint {
  font-size: 10px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.5;
}

.hint code {
  background: var(--bg3);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  background: var(--green);
  color: #000;
  border: none;
  padding: 8px 20px;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.05em;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  font-family: var(--font);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-sm:hover {
  border-color: var(--fg);
  color: var(--fg);
}

.btn-sm.danger {
  color: var(--red);
  border-color: rgba(255, 91, 110, 0.4);
}

.btn-sm.danger:hover {
  background: var(--red-dim);
  border-color: var(--red);
}

/* ─── Feedback ──────────────────────────────────────────────────────────────── */
.feedback {
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 11px;
  border-left: 3px solid;
}

.feedback.ok {
  border-color: var(--green);
  background: var(--green-dim);
  color: var(--green);
}

.feedback.err {
  border-color: var(--red);
  background: var(--red-dim);
  color: var(--red);
}

/* ─── Section Dividers ──────────────────────────────────────────────────────── */
.section-title {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 24px;
  margin-bottom: 14px;
}

/* ─── Log Viewer ────────────────────────────────────────────────────────────── */
.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.log-title {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

#log-wrap {
  background: var(--log-bg);
  border: 1px solid var(--border);
  height: calc(100vh - 220px);
  min-height: 400px;
  overflow-y: auto;
  padding: 12px;
}

#log-content {
  font-size: 11px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

.ll {
  color: var(--log-fg);
}

.ll.warn {
  color: var(--log-warn);
}

.ll.error {
  color: var(--log-err);
}

/* ─── Tasks Table ───────────────────────────────────────────────────────────── */
.tasks-filter {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tasks-filter .filter-btn {
  font-family: var(--font);
  font-size: 10px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  letter-spacing: 0.04em;
  transition: all 0.15s;
}

.tasks-filter .filter-btn.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.tasks-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
}

.tasks-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.tasks-table th {
  text-align: left;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--bg2);
  white-space: nowrap;
}

.tasks-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tasks-table tr:last-child td {
  border-bottom: none;
}

.tasks-table tr:hover td {
  background: var(--bg2);
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 2px;
  letter-spacing: 0.03em;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pending {
  background: rgba(254, 249, 195, 0.15);
  color: #fcd34d;
}

.badge-processing {
  background: rgba(219, 234, 254, 0.15);
  color: #60a5fa;
}

.badge-completed {
  background: rgba(220, 252, 231, 0.15);
  color: #4ade80;
}

.badge-failed {
  background: rgba(254, 226, 226, 0.15);
  color: #f87171;
}

.badge-cancelled {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}

.badge-email {
  background: rgba(243, 244, 246, 0.1);
  color: #9ca3af;
}

.badge-weather {
  background: rgba(219, 234, 254, 0.1);
  color: #93c5fd;
}

.badge-news {
  background: rgba(237, 233, 254, 0.1);
  color: #a78bfa;
}

.badge-ai_job {
  background: rgba(254, 243, 199, 0.1);
  color: #fbbf24;
}

.badge-web_search {
  background: rgba(236, 253, 245, 0.1);
  color: #34d399;
}

.badge-report {
  background: rgba(252, 231, 243, 0.1);
  color: #f472b6;
}

.badge-system_status {
  background: rgba(240, 253, 244, 0.1);
  color: #22c55e;
}

.retry-badge {
  display: inline-block;
  font-size: 8px;
  padding: 1px 4px;
  border-radius: 2px;
  background: rgba(254, 226, 226, 0.2);
  color: #f87171;
  font-weight: 600;
  margin-left: 4px;
}

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

.task-subject,
.task-to {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-repeat {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.tasks-empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

/* ─── Cache Stats Bar ───────────────────────────────────────────────────────── */
.cache-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-bottom: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 10px;
}
.cache-stats .cache-label {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-right: 2px;
}
.cache-stats .cache-chip {
  padding: 2px 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg);
}
.cache-stats .cache-chip.muted { color: var(--muted); }
.cache-stats .cache-chip.disabled { color: var(--muted); font-style: italic; }

/* ─── Details / Override ────────────────────────────────────────────────────── */
details.override {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  background: var(--bg2);
}

details.override summary {
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
  padding: 10px 12px;
  letter-spacing: 0.05em;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: color 0.15s;
}

details.override summary::before {
  content: '▶';
  font-size: 8px;
  transition: transform 0.15s;
}

details.override[open] summary::before {
  transform: rotate(90deg);
}

details.override[open] summary {
  color: var(--fg);
}

details.override > :not(summary) {
  padding: 0 12px 12px;
}

/* ─── Radio Group ───────────────────────────────────────────────────────────── */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-group label {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* ─── Toggle Label ──────────────────────────────────────────────────────────── */
.toggle-label {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* ─── Provider Info ─────────────────────────────────────────────────────────── */
.provider-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg2);
  border-left: 3px solid var(--green);
  margin-bottom: 16px;
  font-size: 11px;
}

.provider-info.warn {
  border-color: var(--amber);
}

.provider-tag {
  font-size: 9px;
  letter-spacing: 0.1em;
  font-weight: 600;
  background: var(--fg);
  color: var(--bg);
  padding: 2px 6px;
  flex-shrink: 0;
}

.server-info {
  font-size: 10px;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--bg2);
  margin-bottom: 12px;
  line-height: 1.8;
  border-left: 3px solid var(--border);
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-hover);
}

/* ─── Animations ────────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.tab-body {
  animation: fadeIn 0.2s ease-out;
}

/* ─── Utility Classes ───────────────────────────────────────────────────────── */
.text-muted {
  color: var(--muted);
}

.text-green {
  color: var(--green);
}

.text-red {
  color: var(--red);
}

.mb-2 {
  margin-bottom: 8px;
}

.mb-4 {
  margin-bottom: 16px;
}

.mt-4 {
  margin-top: 16px;
}

/* ─── Login Page ────────────────────────────────────────────────────────────── */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.login-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 24px;
  color: var(--fg);
}

.login-box .logo {
  display: block;
  text-align: center;
  font-size: 18px;
  margin-bottom: 8px;
  border: none;
  padding: 0;
}

.login-box .logo-brand {
  color: var(--green);
}

/* ─── Light Theme ───────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:             #f5f5f2;
  --bg2:            #eaeae7;
  --bg3:            #dfdedd;
  --fg:             #161616;
  --muted:          #717171;
  --muted2:         #8a8a8a;
  --border:         #d2d2ce;
  --border2:        #c0c0bc;

  --green:          #15803d;
  --green-dim:      rgba(21, 128, 61, 0.07);
  --green-border:   rgba(21, 128, 61, 0.28);
  --cyan:           #0e7490;
  --cyan-dim:       rgba(14, 116, 144, 0.07);
  --amber:          #b45309;
  --amber-dim:      rgba(180, 83, 9, 0.07);
  --red:            #b91c1c;
  --red-dim:        rgba(185, 28, 28, 0.07);

  --log-bg:         #ededeb;
  --log-fg:         #166534;
  --log-warn:       #92400e;
  --log-err:        #b91c1c;

  --scrollbar:      #c0c0bc;
  --scrollbar-hover:#a0a09c;
}

/* ─── Theme Transitions ─────────────────────────────────────────────────────── */
body, header, nav, .tab, .header-btn, .lang-switch a,
input, select, textarea, .btn-sm, .hint code,
#log-wrap, .tasks-table th, .tasks-table td,
details.override, details.override summary,
.provider-info, .server-info, .login-box,
.tasks-filter .filter-btn, .badge {
  transition: background-color 0.25s ease, color 0.15s ease, border-color 0.2s ease;
}

/* ─── Theme Toggle Button ───────────────────────────────────────────────────── */
.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 100%;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  color: var(--muted2);
  transition: color 0.15s, background-color 0.15s;
  flex-shrink: 0;
  padding: 0 7px;
}

.theme-btn:hover {
  color: var(--green);
  background: var(--green-dim);
}

.theme-btn svg {
  display: block;
  flex-shrink: 0;
}

.theme-btn .icon-sun  { display: none; }
.theme-btn .icon-moon { display: block; }

[data-theme="light"] .theme-btn .icon-sun  { display: block; }
[data-theme="light"] .theme-btn .icon-moon { display: none; }

/* ─── Icon-only header buttons ──────────────────────────────────────────────── */
.header-btn.icon {
  width: 28px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ─── Header Menu Dropdown ──────────────────────────────────────────────────── */
.header-menu {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

.header-menu-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 100%;
  padding: 0 11px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  color: var(--muted2);
  font-family: var(--font);
  font-size: 10px;
  letter-spacing: 0.05em;
  transition: color 0.15s, background-color 0.15s;
}

.header-menu-btn:hover {
  color: var(--fg);
  background: var(--bg3);
}

.header-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-top: none;
  min-width: 130px;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.header-menu.open .header-menu-dropdown {
  display: block;
}

.header-menu-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 14px 5px;
}

.header-menu-dropdown a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  font-family: var(--font);
  font-size: 11px;
  color: var(--muted2);
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: color 0.1s, background-color 0.1s;
}

.header-menu-dropdown a:hover {
  color: var(--fg);
  background: var(--bg3);
}

.header-menu-dropdown a.active {
  color: var(--green);
}

.header-menu-dropdown a.active::after {
  content: '✓';
  font-size: 10px;
}


/* ─── Stats Dashboard ───────────────────────────────────────────────────────── */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stats-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 4px;
}

.stats-card-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--cyan);
  line-height: 1.2;
}

.stats-card-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 4px;
}

/* Bar chart */
.stats-barchart {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 100px;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.stats-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.stats-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.stats-bar {
  width: 70%;
  background: var(--cyan);
  border-radius: 2px 2px 0 0;
  position: relative;
  overflow: hidden;
  min-height: 2px;
  opacity: 0.8;
}

.stats-bar-err {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--red);
  opacity: 0.8;
}

.stats-bar-label {
  font-size: 9px;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
}

.stats-bar-count {
  font-size: 9px;
  color: var(--muted2);
}

/* ─── Chat UI ───────────────────────────────────────────────────────────────── */
.chat-container {
  display: flex;
  gap: 16px;
  height: calc(100vh - 180px);
  padding: 16px;
}

.chat-sidebar {
  width: 280px;
  background: var(--bg2);
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-main {
  flex: 1;
  background: var(--bg2);
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sessions {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
}

.chat-sessions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.chat-sessions-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg);
}

.chat-session-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.chat-session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  transition: background 0.2s;
}

.chat-session-item:hover {
  background: var(--bg3);
}

.chat-session-item.active {
  background: var(--green-dim);
}

.chat-session-item.active .chat-session-name {
  color: var(--green);
}

.chat-session-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.chat-session-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-session-meta {
  font-size: 0.7rem;
  color: var(--muted);
}

.chat-session-delete {
  margin: 0;
}

.chat-session-delete-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.chat-session-delete-btn:hover {
  color: var(--red);
  background: var(--red-dim);
}

.chat-session-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
}

.chat-message-user {
  align-self: flex-end;
  background: var(--green);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message-assistant {
  align-self: flex-start;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.chat-message-role {
  font-weight: 600;
}

.chat-message-time {
  font-size: 0.7rem;
}

.chat-message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chat-input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-textarea {
  flex: 1;
  min-height: 60px;
  max-height: 200px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
}

.chat-textarea:focus {
  outline: none;
  border-color: var(--green-border);
}

.chat-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.85rem;
  cursor: pointer;
}

.chat-send-btn {
  padding: 10px 24px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.chat-send-btn:hover {
  opacity: 0.9;
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-new-btn {
  padding: 6px 12px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-new-btn:hover {
  opacity: 0.9;
}

@media (max-width: 768px) {
  .chat-sidebar {
    width: 220px;
  }
  .chat-message {
    max-width: 90%;
  }
}

/* ─── Task Form Styles ────────────────────────────────────────────────────── */

.task-form-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.task-form-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  flex: 1;
}

.btn-back {
  padding: 6px 12px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-back:hover {
  background: var(--bg3);
  border-color: var(--border2);
}

.task-form {
  max-width: 800px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--fg);
  font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--green);
}

.form-group small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.form-fieldset {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.form-fieldset legend {
  padding: 0 8px;
  font-weight: 600;
  color: var(--fg);
  font-size: 0.95rem;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-primary {
  padding: 10px 24px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-cancel {
  padding: 10px 24px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel:hover {
  background: var(--bg3);
  border-color: var(--border2);
}

.tasks-actions-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

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

/* ─── Instance Management Styles ──────────────────────────────────────────── */

.instances-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.instances-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.instances-table-wrap {
  overflow-x: auto;
}

.instances-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.instances-table thead {
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
}

.instances-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

.instances-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.instances-table tbody tr:hover {
  background: var(--bg2);
}

.instance-name {
  font-weight: 600;
  color: var(--fg);
}

.instance-address {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--muted2);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-running {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.badge-stopped {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(255, 91, 110, 0.3);
}

.badge-ai {
  background: var(--cyan-dim);
  color: var(--cyan);
  border: 1px solid rgba(0, 229, 195, 0.3);
}

.btn-sm.success {
  background: var(--green);
  color: #fff;
}

.btn-sm.success:hover {
  background: #16a34a;
}

/* ─── Mail Actions ────────────────────────────────────────────────────────── */

.mail-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.action-group h4 {
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-action {
  padding: 10px 16px;
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.btn-action:hover {
  background: var(--bg3);
  border-color: var(--border2);
  transform: translateX(2px);
}

.btn-action.danger {
  border-color: var(--red);
  color: var(--red);
}

.btn-action.danger:hover {
  background: var(--red-dim);
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.modal-close:hover {
  background: var(--bg3);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* ─── OAuth Guide ─────────────────────────────────────────────────────────── */

.oauth-guide h4 {
  margin-top: 20px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
}

.oauth-guide ol {
  margin-left: 20px;
  margin-bottom: 16px;
}

.oauth-guide li {
  margin-bottom: 8px;
  line-height: 1.6;
}

.oauth-guide pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  overflow-x: auto;
  font-size: 0.85rem;
  margin: 12px 0;
}

.oauth-guide code {
  font-family: var(--font);
  color: var(--green);
}

.oauth-notice {
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--cyan-dim);
  border: 1px solid rgba(0, 229, 195, 0.3);
  border-radius: 4px;
  color: var(--cyan);
}

.oauth-notice p {
  margin: 0;
  font-size: 0.85rem;
}

/* ─── AI Messages Waterfall ────────────────────────────────────────────────── */

.ai-messages-page {
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* 统计卡片 */
.ai-messages-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--cyan);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted2);
  margin-top: 0.25rem;
}

/* 过滤器栏 */
.ai-messages-filters {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 1.5rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-select, .filter-input {
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  min-width: 0;
}

.filter-select {
  flex: 0 1 auto;
}

.filter-input {
  flex: 1 1 150px;
}

.btn-filter, .btn-reset {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-reset {
  background: var(--muted);
}

.btn-filter:hover { opacity: 0.85; }
.btn-reset:hover { background: var(--muted2); }

/* 分布卡片 */
.ai-messages-distributions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.dist-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}

.dist-card h4 {
  font-size: 0.8rem;
  color: var(--muted2);
  margin-bottom: 0.5rem;
}

.dist-bars {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.dist-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.dist-label {
  width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}

.dist-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg2);
  border-radius: 4px;
  overflow: hidden;
}

.dist-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.dist-count {
  width: 30px;
  text-align: right;
  color: var(--muted2);
}

/* 瀑布流消息容器 */
.ai-messages-masonry {
  column-count: 2;
  column-gap: 0.75rem;
}

@media (max-width: 900px) {
  .ai-messages-masonry { column-count: 1; }
}

/* 单个消息卡片 */
.ai-msg-card {
  break-inside: avoid;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.2s;
}

.ai-msg-card:hover {
  border-color: var(--border2);
}

/* 卡片头部 */
.ai-msg-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.ai-msg-time {
  font-size: 0.7rem;
  color: var(--muted2);
}

.ai-msg-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
}

.ai-msg-ok {
  background: var(--green-dim);
  color: var(--green);
}

.ai-msg-err {
  background: var(--red-dim);
  color: var(--red);
}

.ai-msg-type {
  background: var(--cyan-dim);
  color: var(--cyan);
}

.ai-msg-ai {
  background: var(--amber-dim);
  color: var(--amber);
}

/* 邮件上下文 */
.ai-msg-context {
  font-size: 0.75rem;
  margin-bottom: 0.4rem;
}

.ai-msg-field {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.15rem;
}

.ai-msg-field-label {
  width: 1.2rem;
  text-align: center;
}

.ai-msg-field-value {
  color: var(--muted2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 结果预览 */
.ai-msg-body-preview details {
  font-size: 0.75rem;
  color: var(--fg);
}

.ai-msg-body-preview summary {
  cursor: pointer;
  color: var(--muted2);
  font-size: 0.7rem;
  padding: 0.2rem 0;
}

.ai-msg-body-preview summary:hover {
  color: var(--cyan);
}

.ai-msg-pre {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.7rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  color: var(--fg);
  margin-top: 0.3rem;
}

/* 错误信息 */
.ai-msg-error {
  background: var(--red-dim);
  border: 1px solid var(--red-border, rgba(255,91,110,0.3));
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--red);
  margin-bottom: 0.4rem;
}

/* 调度信息 */
.ai-msg-schedule {
  font-size: 0.7rem;
  color: var(--amber);
  background: var(--amber-dim);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  margin-bottom: 0.4rem;
}

/* 操作按钮 */
.ai-msg-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.btn-sm {
  background: var(--bg2);
  color: var(--muted2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.65rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-sm:hover {
  background: var(--border);
  color: var(--fg);
}

/* 空状态 */
.ai-messages-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

/* 加载更多 */
.ai-messages-load-more {
  text-align: center;
  padding: 1rem 0;
}

.btn-load-more {
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-load-more:hover {
  background: var(--border);
}

/* 详情模态框 */
.ai-msg-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.ai-msg-modal-content {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}

.ai-msg-modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--muted2);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

.ai-msg-modal-close:hover {
  color: var(--fg);
}

.ai-msg-detail-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.ai-msg-detail-time {
  font-size: 0.8rem;
  color: var(--muted2);
}

.ai-msg-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
}

.ai-msg-detail-field {
  color: var(--fg);
}

.ai-msg-detail-field strong {
  color: var(--muted2);
  display: block;
  font-size: 0.7rem;
  margin-bottom: 0.1rem;
}

.ai-msg-json {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-size: 0.75rem;
  max-height: 400px;
  overflow: auto;
  color: var(--green);
}

/* Toast 通知 */
.toast-notification {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  z-index: 10001;
  animation: toast-in 0.2s ease, toast-out 0.2s ease 1.8s forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(1rem); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(1rem); }
}


