/* ========================================
   Task Dashboard — Base Styles + Light Theme
   ======================================== */

:root,
.theme-light {
  --bg-page: #f4f5f7;
  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #f0f2ff;
  --bg-active: #e8ebff;
  --bg-input: #ffffff;

  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-muted: #8b8ba0;
  --text-inverse: #ffffff;

  --border: #e2e4ea;
  --border-hover: #4a6cf7;

  --accent: #4a6cf7;
  --accent-light: #eef0ff;
  --accent-text: #4a6cf7;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);

  --priority-emergency: #dc3545;
  --priority-high: #e8590c;
  --priority-medium: #f59f00;
  --priority-low: #2b8a3e;

  --sidebar-width: 220px;
  --header-height: 52px;
  --radius: 8px;
  --radius-sm: 4px;
}

/* ========================================
   Dark Theme
   ======================================== */

.theme-dark {
  color-scheme: dark;

  --bg-page: #1a1b1e;
  --bg-surface: #25262b;
  --bg-sidebar: #1e1f23;
  --bg-hover: #2c2e33;
  --bg-active: #2a2d3a;
  --bg-input: #2c2e33;

  --text-primary: #e1e2e6;
  --text-secondary: #a6a7ab;
  --text-muted: #6b6c72;
  --text-inverse: #ffffff;

  --border: #373a40;
  --border-hover: #5c7cfa;

  --accent: #5c7cfa;
  --accent-light: #2a2d3a;
  --accent-text: #748ffc;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);

  --priority-emergency: #ff6b6b;
  --priority-high: #ff922b;
  --priority-medium: #fcc419;
  --priority-low: #51cf66;
}

/* ========================================
   Solarized Theme
   ======================================== */

.theme-solarized {
  --bg-page: #fdf6e3;
  --bg-surface: #eee8d5;
  --bg-sidebar: #eee8d5;
  --bg-hover: #e8e1cc;
  --bg-active: #ddd6c1;
  --bg-input: #fdf6e3;

  --text-primary: #073642;
  --text-secondary: #586e75;
  --text-muted: #93a1a1;
  --text-inverse: #fdf6e3;

  --border: #d3cbb7;
  --border-hover: #268bd2;

  --accent: #268bd2;
  --accent-light: #eee8d5;
  --accent-text: #268bd2;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);

  --priority-emergency: #dc322f;
  --priority-high: #cb4b16;
  --priority-medium: #b58900;
  --priority-low: #859900;
}

/* ========================================
   High Contrast Theme
   ======================================== */

.theme-high-contrast {
  --bg-page: #ffffff;
  --bg-surface: #ffffff;
  --bg-sidebar: #f5f5f5;
  --bg-hover: #e0e0e0;
  --bg-active: #d0d0d0;
  --bg-input: #ffffff;

  --text-primary: #000000;
  --text-secondary: #1a1a1a;
  --text-muted: #4a4a4a;
  --text-inverse: #ffffff;

  --border: #000000;
  --border-hover: #0000cc;

  --accent: #0000cc;
  --accent-light: #e6e6ff;
  --accent-text: #0000cc;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.25);

  --priority-emergency: #cc0000;
  --priority-high: #cc4400;
  --priority-medium: #886600;
  --priority-low: #006600;
}

/* ========================================
   Reset
   ======================================== */

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

html, body {
  height: 100%;
}

html {
  transition: background-color 0.2s ease, color 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ========================================
   App Layout
   ======================================== */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Sidebar toggle (hamburger) button */
.btn-sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  flex-shrink: 0;
}

.btn-sidebar-toggle:hover {
  border-color: var(--border-hover);
  color: var(--accent);
  background: var(--accent-light);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-selector {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 28px 4px 10px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8ba0' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.theme-selector:hover {
  border-color: var(--border-hover);
}

/* Layout */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

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

/* Sidebar backdrop (mobile overlay) */
.sidebar-backdrop {
  display: none;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  padding: 16px 0;
  transition: width 0.2s ease;
}

/* ── Desktop collapsed state (icons-only) ── */
.sidebar.collapsed {
  width: 48px;
}

.sidebar.collapsed .sidebar-label {
  opacity: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
}

.sidebar.collapsed .dir-item {
  padding: 9px 0;
  justify-content: center;
}

.sidebar.collapsed .dir-label,
.sidebar.collapsed .dir-count {
  display: none;
}

.sidebar.collapsed .dir-item {
  border-left-color: transparent;
}

.sidebar.collapsed .dir-icon {
  width: 20px;
  height: 20px;
}

.sidebar-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0 16px 8px;
}

.dir-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  cursor: pointer;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
}

.dir-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.dir-item.active {
  background: var(--bg-active);
  color: var(--accent);
  font-weight: 500;
  border-left-color: var(--accent);
}

.dir-count {
  background: var(--bg-page);
  border-radius: 10px;
  padding: 0 8px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 24px;
  text-align: center;
  line-height: 20px;
}

.dir-item.active .dir-count {
  background: var(--accent);
  color: var(--text-inverse);
}

/* Directory accent colors */
.dir-item[data-dir="prepare"]    { --dir-accent: #4a6cf7; }
.dir-item[data-dir="taskinbox"]  { --dir-accent: #7c3aed; }
.dir-item[data-dir="current"]    { --dir-accent: #16a34a; }
.dir-item[data-dir="emergency"]  { --dir-accent: #dc3545; }
.dir-item[data-dir="done"]       { --dir-accent: #0d9488; }
.dir-item[data-dir="trash"]      { --dir-accent: #6b7280; }
.dir-item[data-dir="quarantine"] { --dir-accent: #d97706; }

.dir-item .dir-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--dir-accent);
  opacity: 0.7;
  transition: opacity 0.12s;
}

.dir-item:hover .dir-icon,
.dir-item.active .dir-icon {
  opacity: 1;
}

.dir-item.active {
  border-left-color: var(--dir-accent);
  color: var(--dir-accent);
}

.dir-item.active .dir-count {
  background: var(--dir-accent);
}

.dir-item .dir-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.breadcrumb a {
  color: var(--accent-text);
}

.breadcrumb .separator {
  margin: 0 6px;
  color: var(--text-muted);
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.5;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}

.btn-primary:hover {
  box-shadow: var(--shadow-sm);
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--bg-surface);
  color: var(--priority-emergency);
  border-color: var(--border);
}

.btn-danger:hover {
  background: var(--priority-emergency);
  color: #fff;
  border-color: var(--priority-emergency);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-outline:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-success {
  background: var(--priority-low);
  color: #fff;
  border-color: var(--priority-low);
  pointer-events: none;
}

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

.btn-sm {
  padding: 3px 10px;
  font-size: 0.75rem;
}

/* ========================================
   Forms
   ======================================== */

.props-form {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.form-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 16px;
  align-items: center;
  padding: 6px 0;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-input,
.form-select {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.12s;
  max-width: 400px;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.form-static {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 5px 0;
}

.form-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.save-status {
  font-size: 0.8125rem;
  color: var(--accent-text);
}

/* Tag input */
.tag-input-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 400px;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.8125rem;
  padding: 2px 6px 2px 8px;
  border-radius: var(--radius-sm);
}

.tag-remove {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.6;
}

.tag-remove:hover {
  opacity: 1;
}

.tag-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tag-field {
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
}

.tag-add-btn {
  padding: 4px 10px;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.tag-field:focus {
  outline: none;
  border-color: var(--accent);
}

/* ========================================
   Task Cards
   ======================================== */

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.task-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

.task-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.task-card-title {
  font-weight: 500;
  font-size: 0.9375rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Priority badge */
.priority-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.priority-badge.emergency {
  background: var(--priority-emergency);
  color: #fff;
}

.priority-badge.high {
  background: var(--priority-high);
  color: #fff;
}

.priority-badge.medium {
  background: var(--priority-medium);
  color: #453a04;
}

.priority-badge.low {
  background: var(--priority-low);
  color: #fff;
}

/* Card metadata row */
.task-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.task-card-meta .sep {
  color: var(--border);
}

.recurring-indicator {
  color: var(--accent-text);
}

/* Status badges */
.status-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: capitalize;
}
.status-badge.status-pending {
  background: var(--bg-page);
  color: var(--text-muted);
}
.status-badge.status-waiting_for_subtasks {
  background: #fef3c7;
  color: #92400e;
}
.status-badge.status-completed {
  background: #d1fae5;
  color: #065f46;
}
.status-badge.status-failed {
  background: #fee2e2;
  color: #991b1b;
}
.status-badge.status-rejected {
  background: #e5e7eb;
  color: #6b7280;
}

/* Subtask indicator in task card */
.subtask-indicator {
  color: var(--accent-text);
  font-weight: 500;
}

/* Expandable subtask list in task card */
.subtask-expand-list {
  margin-top: 8px;
  padding-left: 4px;
  border-left: 2px solid var(--border);
}
.subtask-row,
.subtask-detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8125rem;
}
.subtask-row:hover,
.subtask-detail-row:hover {
  background: var(--bg-page);
}
.subtask-no {
  color: var(--text-muted);
  font-weight: 600;
  min-width: 24px;
}
.subtask-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subtask-exec {
  color: var(--text-muted);
  font-size: 0.75rem;
}
.loading-sm,
.error-sm {
  font-size: 0.8125rem;
  padding: 4px 8px;
  color: var(--text-muted);
}
.error-sm {
  color: var(--danger);
}

/* Subtask detail list in parent task detail view */
.subtask-detail-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
}

/* Dark theme status badge overrides */
.theme-dark .status-badge.status-waiting_for_subtasks {
  background: #78350f;
  color: #fef3c7;
}
.theme-dark .status-badge.status-completed {
  background: #064e3b;
  color: #d1fae5;
}
.theme-dark .status-badge.status-failed {
  background: #7f1d1d;
  color: #fee2e2;
}
.theme-dark .status-badge.status-rejected {
  background: #374151;
  color: #d1d5db;
}

/* Tags */
.task-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.tag {
  display: inline-block;
  background: var(--bg-page);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: var(--radius-sm);
  line-height: 1.6;
}

/* ========================================
   States
   ======================================== */

.loading {
  text-align: center;
  padding: 48px 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.loading::before {
  content: "";
  display: block;
  width: 24px;
  height: 24px;
  margin: 0 auto 12px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 48px 0;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 16px;
  font-size: 0.9375rem;
}

/* ========================================
   Utility
   ======================================== */

/* ========================================
   Detail View
   ======================================== */

.detail-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.detail-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0;
}

/* Properties grid */
.props-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 16px;
  align-items: baseline;
}

.prop-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.prop-value {
  font-size: 0.875rem;
  color: var(--text-primary);
}

.prop-code {
  font-family: "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 0.8125rem;
  background: var(--bg-page);
  padding: 1px 6px;
  border-radius: 3px;
}

.prop-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Action bar */
.action-bar {
  display: flex;
  gap: 10px;
  padding: 16px 0;
}

/* Associated files */
.associated-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.associated-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.associated-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.12s;
}

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

.associated-name {
  flex: 1;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.associated-toggle {
  font-size: 0.625rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.associated-content {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}

.error-text {
  color: var(--priority-emergency);
  font-size: 0.8125rem;
}

/* ========================================
   Markdown Body
   ======================================== */

.markdown-body {
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.markdown-body h1 {
  font-size: 1.375rem;
  font-weight: 600;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.markdown-body h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 20px 0 8px;
}

.markdown-body h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 16px 0 6px;
}

.markdown-body p {
  margin: 0 0 12px;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 24px;
  margin: 0 0 12px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body code {
  font-family: "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 0.85em;
  background: var(--bg-page);
  padding: 1px 5px;
  border-radius: 3px;
}

.markdown-body pre {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0 0 12px;
  overflow-x: auto;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 12px;
  padding: 4px 16px;
  color: var(--text-secondary);
}

.markdown-body strong {
  font-weight: 600;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 12px;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
  font-size: 0.875rem;
}

.markdown-body th {
  background: var(--bg-page);
  font-weight: 600;
}

/* ========================================
   EasyMDE Overrides
   ======================================== */

/* Fullscreen z-index must be above the dashboard header (z-index: 10) */
.editor-toolbar.fullscreen {
  z-index: 12;
}

.EasyMDEContainer .CodeMirror-fullscreen {
  z-index: 11;
}

.editor-preview-side {
  z-index: 12;
}

/* ── Issue 1 Fix: Side-by-side preview height matching ── */

/* Inline side-by-side: constrain within detail section.
   EasyMDE uses flex-wrap:wrap so toolbar/statusbar (100% width) take their
   own rows while editor + preview share a row.  align-items:stretch makes
   both panes equal height within that row. */
.EasyMDEContainer.sided--no-fullscreen {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  align-items: stretch;
}

.EasyMDEContainer.sided--no-fullscreen .CodeMirror {
  border: none;
  border-bottom: 1px solid var(--border);
}

.EasyMDEContainer.sided--no-fullscreen .CodeMirror-sided {
  min-height: 300px;
}

.EasyMDEContainer.sided--no-fullscreen .editor-preview-active-side {
  padding: 16px 20px;
  background: var(--bg-page);
  border-left: 1px solid var(--border);
  /* Remove explicit height so flex stretch controls the height instead */
  height: unset !important;
  min-height: 300px;
  /* Match the editor's maxHeight (set to "60vh" in EasyMDE config) so the
     preview scrolls at the same point instead of growing unbounded */
  max-height: 60vh;
  overflow-y: auto;
}

/* ── Issue 2+3+4 Fix: Preview pane typography & list rendering ── */
/* Apply markdown-body-equivalent styles to both preview modes */

.editor-preview,
.editor-preview-side {
  font-size: 0.9375rem;
  line-height: 1.7;
  padding: 16px 20px;
}

.editor-preview h1,
.editor-preview-side h1 {
  font-size: 1.375rem;
  font-weight: 600;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.editor-preview h2,
.editor-preview-side h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 20px 0 8px;
}

.editor-preview h3,
.editor-preview-side h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 16px 0 6px;
}

.editor-preview p,
.editor-preview-side p {
  margin: 0 0 12px;
}

/* Issue 2: Ensure bullets and numbers are visible with adequate padding */
.editor-preview ul,
.editor-preview ol,
.editor-preview-side ul,
.editor-preview-side ol {
  padding-left: 28px;
  margin: 0 0 12px;
}

/* Issue 3: Nested lists get additional indentation */
.editor-preview li > ul,
.editor-preview li > ol,
.editor-preview-side li > ul,
.editor-preview-side li > ol {
  padding-left: 24px;
  margin: 4px 0 4px;
}

.editor-preview li,
.editor-preview-side li {
  margin-bottom: 4px;
}

/* Issue 2: Ensure list-style is explicitly set (reset may strip it) */
.editor-preview ul,
.editor-preview-side ul {
  list-style-type: disc;
}

.editor-preview ol,
.editor-preview-side ol {
  list-style-type: decimal;
}

.editor-preview ul ul,
.editor-preview-side ul ul {
  list-style-type: circle;
}

.editor-preview ul ul ul,
.editor-preview-side ul ul ul {
  list-style-type: square;
}

/* Issue 4: Code blocks */
.editor-preview code,
.editor-preview-side code {
  font-family: "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 0.85em;
  background: var(--bg-page);
  padding: 1px 5px;
  border-radius: 3px;
}

.editor-preview pre,
.editor-preview-side pre {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0 0 12px;
  overflow-x: auto;
}

.editor-preview pre code,
.editor-preview-side pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* Issue 4: Blockquotes */
.editor-preview blockquote,
.editor-preview-side blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 12px;
  padding: 4px 16px;
  color: var(--text-secondary);
}

/* Issue 4: Strong text */
.editor-preview strong,
.editor-preview-side strong {
  font-weight: 600;
}

/* Issue 4: Horizontal rules */
.editor-preview hr,
.editor-preview-side hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Issue 4: Tables */
.editor-preview table,
.editor-preview-side table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 12px;
}

.editor-preview th,
.editor-preview td,
.editor-preview-side th,
.editor-preview-side td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
  font-size: 0.875rem;
}

.editor-preview th,
.editor-preview-side th {
  background: var(--bg-page);
  font-weight: 600;
}

/* ── EasyMDE Theme Overrides ── */

.EasyMDEContainer .CodeMirror {
  background: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--border);
}

.EasyMDEContainer .CodeMirror-cursor {
  border-left-color: var(--text-primary);
}

.EasyMDEContainer .CodeMirror-selected {
  background: var(--accent-light);
}

.EasyMDEContainer .CodeMirror-focused .CodeMirror-selected {
  background: var(--accent-light);
}

.editor-toolbar {
  border-color: var(--border);
}

.editor-toolbar button {
  color: var(--text-secondary) !important;
}

.editor-toolbar button:hover,
.editor-toolbar button.active {
  background: var(--bg-hover);
  border-color: var(--border);
}

.editor-toolbar i.separator {
  border-left-color: var(--border);
  border-right-color: transparent;
}

.editor-preview {
  background: var(--bg-page);
  color: var(--text-primary);
}

.editor-preview-side {
  background: var(--bg-page);
  color: var(--text-primary);
  border-color: var(--border);
}

.editor-toolbar.fullscreen {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.editor-toolbar.fullscreen::before {
  background: linear-gradient(to right, var(--bg-surface) 0, transparent 100%);
}

.editor-toolbar.fullscreen::after {
  background: linear-gradient(to right, transparent 0, var(--bg-surface) 100%);
}

.EasyMDEContainer .CodeMirror-fullscreen {
  background: var(--bg-surface);
}

.EasyMDEContainer .CodeMirror-gutters {
  background: var(--bg-page);
  border-right-color: var(--border);
}

.editor-statusbar {
  color: var(--text-muted);
}

/* ========================================
   Theme-Specific Tweaks
   ======================================== */

/* Theme selector dropdown arrow fix for dark themes */
.theme-dark .theme-selector {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6c72' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
}

.theme-high-contrast .theme-selector {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234a4a4a' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
}

/* ========================================
   Modal Dialogs
   ======================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: modal-fade-in 0.15s ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  min-width: 340px;
  max-width: 480px;
  width: 90%;
  animation: modal-slide-in 0.15s ease;
}

@keyframes modal-slide-in {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.modal-message {
  font-size: 0.9375rem;
  color: var(--text-primary);
  margin-bottom: 16px;
  line-height: 1.5;
  white-space: pre-line;
}

.modal-input {
  width: 100%;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  margin-bottom: 16px;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* High contrast: thicker borders */
.theme-high-contrast .detail-section,
.theme-high-contrast .task-card,
.theme-high-contrast .associated-item {
  border-width: 2px;
}

.theme-high-contrast .dir-item.active {
  border-left-width: 4px;
}

.theme-high-contrast .btn {
  border-width: 2px;
}

/* ========================================
   Utility
   ======================================== */

/* Sort control in task list view */
.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.sort-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.sort-select {
  max-width: 240px;
}

/* Edit-mode navigation guard toast */
.edit-guard-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--priority-medium);
  color: #453a04;
  padding: 8px 16px;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  margin: 0 32px 8px;
  animation: modal-fade-in 0.15s ease;
}

.edit-guard-toast .btn {
  flex-shrink: 0;
}

/* ========================================
   Copy-to-clipboard button (Feature 3)
   ======================================== */

.btn-copy-id {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px 4px;
  margin-left: 6px;
  color: var(--text-muted);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  vertical-align: middle;
}

.btn-copy-id:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

.btn-copy-id.copied {
  color: var(--priority-low);
  border-color: var(--priority-low);
}

/* ========================================
   Task Card Action Buttons (Features 1 & 4)
   ======================================== */

/* Desktop (>768px): card is a flex row — content left, buttons right */
.task-card {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.task-card-body {
  flex: 1;
  min-width: 0;
}

.task-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
  justify-content: center;
  flex-shrink: 0;
}

.task-card-actions .btn-card-action {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Mobile (<=768px): card stacks vertically — buttons below content */
@media (max-width: 768px) {
  .task-card {
    flex-direction: column;
  }

  .task-card-actions {
    flex-direction: row;
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    justify-content: flex-start;
  }
}

/* ========================================
   Template Insert Button (Feature 2)
   ======================================== */

#btn-insert-template {
  margin-left: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

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

/* Sidebar separator */
.sidebar-separator {
  height: 1px;
  background: var(--border);
  margin: 12px 16px;
}

.sidebar.collapsed .sidebar-separator {
  margin: 12px 8px;
}

/* Chat link accent */
.dir-item.chat-item { --dir-accent: #8b5cf6; }

/* Logout sidebar button — reset button defaults, inherit dir-item styling */
button.dir-item {
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

/* Logout accent color */
.dir-item.logout-item { --dir-accent: #e05252; }

/* Chat container layout */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - 48px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}

/* ── Agent toggle ──────────────────────────────────────── */
.agent-toggle {
  display: flex;
  gap: 0;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.agent-toggle-btn {
  padding: 6px 18px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
  transition: background 0.15s, color 0.15s;
}

.agent-toggle-btn:hover {
  background: var(--bg-hover);
}

.agent-toggle-btn.active {
  background: var(--agent-accent, var(--accent));
  color: #fff;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px;
  font-size: 0.9375rem;
  margin: auto 0;
}

/* Individual message */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
}

.chat-msg-user {
  align-self: flex-start;
  margin-left: 32px;
  background: var(--accent);
  color: var(--text-inverse);
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 12px;
}

.chat-msg-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-msg-user .chat-msg-role {
  color: rgba(255, 255, 255, 0.8);
}

.chat-msg-assistant .chat-msg-role {
  color: var(--text-muted);
}

.chat-msg-time {
  font-size: 0.6875rem;
  opacity: 0.6;
}

.chat-msg-content {
  font-size: 0.875rem;
  word-break: break-word;
}

.chat-msg-user .chat-msg-content {
  white-space: pre-wrap;
}

/* Markdown inside assistant messages */
.chat-msg-assistant .chat-msg-content.markdown-body {
  font-size: 0.875rem;
}

.chat-msg-assistant .chat-msg-content.markdown-body h1 {
  font-size: 1.125rem;
}

.chat-msg-assistant .chat-msg-content.markdown-body h2 {
  font-size: 1rem;
}

.chat-msg-assistant .chat-msg-content.markdown-body p:last-child {
  margin-bottom: 0;
}

.chat-msg-assistant .chat-msg-content.markdown-body pre {
  margin: 8px 0;
}

/* Streaming state (inside assistant bubble) */
.chat-msg-streaming {
  border-color: var(--accent);
  animation: streaming-pulse 2s ease-in-out infinite;
}

@keyframes streaming-pulse {
  0%, 100% { border-color: var(--accent); }
  50% { border-color: var(--border); }
}

.chat-streaming-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  padding: 4px 0;
}

.chat-streaming-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.chat-streaming-timer {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 3.5em;
  text-align: right;
  flex-shrink: 0;
}

.chat-streaming-log {
  margin-top: 6px;
  padding: 6px 0 0;
  border-top: 1px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
}

.chat-streaming-log-entry {
  padding: 2px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-streaming-log-entry.chat-streaming-log-text {
  white-space: normal;
  overflow: visible;
  padding: 4px 0;
}

.chat-streaming-log-time {
  display: inline-block;
  min-width: 3.5em;
  font-family: monospace;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Activity section (finalized state in assistant bubble) */
.chat-activity-section {
  margin-bottom: 8px;
}

.chat-activity-toggle {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
  font-weight: 500;
}

.chat-activity-toggle:hover {
  color: var(--text-secondary);
}

.chat-activity-details {
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 300px;
  overflow-y: auto;
}

.chat-activity-event {
  padding: 2px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-activity-event-time {
  display: inline-block;
  min-width: 3.5em;
  font-family: monospace;
  opacity: 0.7;
}

.chat-activity-text {
  padding: 6px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 4px 0;
}

.chat-activity-text.markdown-body {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Error inline in bubble */
.chat-error-inline {
  color: var(--priority-emergency);
  font-size: 0.8125rem;
}

.chat-msg-error {
  border-color: var(--priority-emergency);
  opacity: 0.9;
}

.typing-dots span {
  animation: typing-bounce 1.4s infinite;
  display: inline-block;
  font-weight: bold;
  font-size: 1.2em;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Error message in chat */
.chat-error {
  align-self: center;
  color: var(--priority-emergency);
  background: var(--bg-surface);
  border: 1px solid var(--priority-emergency);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.8125rem;
}

/* Input area */
.chat-input-area {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  resize: none;
  line-height: 1.5;
  min-height: 52px;
  max-height: 120px;
  transition: border-color 0.12s;
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.chat-input:disabled {
  opacity: 0.6;
  cursor: wait;
}

.chat-input-area .btn {
  height: 52px;
  padding: 0 20px;
}

/* ── Chat Files Panel ──────────────────────────────────── */

.chat-files-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  cursor: pointer;
  user-select: none;
}

.chat-files-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn-chat-files-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
}

.chat-files-list {
  padding: 0 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-page);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}

.chat-file-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.chat-file-name {
  flex: 1;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-file-size {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.chat-file-entry {
  display: flex;
  flex-direction: column;
}

.chat-file-preview {
  margin: 4px 0 6px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 400px;
  overflow-y: auto;
}

.chat-file-preview .markdown-body {
  font-size: 0.8125rem;
}

.chat-file-preview-error {
  color: var(--danger);
  font-size: 0.8125rem;
}

/* ── Agent file links / images in chat ─────────────────── */

.agent-file-link {
  color: var(--accent-text);
  text-decoration: underline;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.file-link-icon {
  flex-shrink: 0;
}

.agent-file-figure {
  margin: 12px 0;
  text-align: center;
}

.agent-file-figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.agent-file-figure figcaption {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Constrain inline SVGs in chat messages */
.chat-msg-content svg:not(.file-link-icon):not(.chat-file-icon) {
  max-width: 100%;
  height: auto;
}

/* ========================================
   System Monitor
   ======================================== */

.dir-item.monitor-item { --dir-accent: #0ea5e9; }

.monitor-container {
  display: flex;
  flex-direction: column;
}

.monitor-header {
  margin-bottom: 16px;
}

.monitor-header .page-title {
  margin: 0;
}

/* Tabs */
.monitor-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.monitor-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.monitor-tab:hover:not([disabled]) {
  color: var(--text-primary);
}

.monitor-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.monitor-tab[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Sections */
.monitor-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.monitor-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}

/* Key-value grid (current session) */
.monitor-kv-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: 0.875rem;
}

.monitor-kv-label {
  color: var(--text-muted);
  font-weight: 500;
}

.monitor-kv-value {
  color: var(--text-primary);
}

/* Tables */
.monitor-table-wrap {
  overflow-x: auto;
}

.monitor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.monitor-table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.monitor-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.monitor-table tbody tr:hover {
  background: var(--bg-hover);
}

.monitor-table code {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-active {
  background: #dcfce7;
  color: #166534;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-expired {
  background: #e5e7eb;
  color: #6b7280;
}

/* Dark theme badge overrides */
.theme-dark .badge-active {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.theme-dark .badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.theme-dark .badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.theme-dark .badge-expired {
  background: rgba(156, 163, 175, 0.15);
  color: #9ca3af;
}

/* Solarized badge overrides */
.theme-solarized .badge-active {
  background: rgba(133, 153, 0, 0.15);
  color: #859900;
}

.theme-solarized .badge-warning {
  background: rgba(181, 137, 0, 0.15);
  color: #b58900;
}

.theme-solarized .badge-danger {
  background: rgba(220, 50, 47, 0.15);
  color: #dc322f;
}

.theme-solarized .badge-expired {
  background: rgba(147, 161, 161, 0.15);
  color: #93a1a1;
}

/* High contrast overrides */
.theme-high-contrast .monitor-section {
  border-width: 2px;
}

.theme-high-contrast .monitor-table th {
  border-bottom-width: 3px;
}

.theme-high-contrast .badge {
  border: 1px solid currentColor;
}

/* ── Health Tab ─────────────────────────────────────── */

.health-tab-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.health-refresh-btn {
  font-size: 0.8125rem;
  padding: 6px 14px;
}

.health-unavailable {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.health-unavailable-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.health-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.health-card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.health-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.health-card-sub {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.health-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 0;
  text-align: left;
  margin-top: 4px;
}

.health-toggle:hover {
  text-decoration: underline;
}

.health-card-details {
  margin: 4px 0 0 0;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
}

.health-services {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.health-service {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.health-service-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.health-service-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.health-service-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.health-badge-running {
  background: #dcfce7;
  color: #166534;
}

.health-badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.health-badge-stopped {
  background: #e5e7eb;
  color: #6b7280;
}

.health-badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.health-badge-unknown {
  background: #e5e7eb;
  color: #6b7280;
}

.health-service-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.service-actions {
  /* Placeholder for future start/stop/restart buttons */
}

/* Dark theme health overrides */
.theme-dark .health-badge-running {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.theme-dark .health-badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.theme-dark .health-badge-stopped {
  background: rgba(156, 163, 175, 0.15);
  color: #9ca3af;
}

.theme-dark .health-badge-error {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.theme-dark .health-badge-unknown {
  background: rgba(156, 163, 175, 0.15);
  color: #9ca3af;
}

/* Solarized theme health overrides */
.theme-solarized .health-badge-running {
  background: rgba(133, 153, 0, 0.15);
  color: #859900;
}

.theme-solarized .health-badge-warning {
  background: rgba(181, 137, 0, 0.15);
  color: #b58900;
}

.theme-solarized .health-badge-stopped {
  background: rgba(147, 161, 161, 0.15);
  color: #93a1a1;
}

.theme-solarized .health-badge-error {
  background: rgba(220, 50, 47, 0.15);
  color: #dc322f;
}

.theme-solarized .health-badge-unknown {
  background: rgba(147, 161, 161, 0.15);
  color: #93a1a1;
}

/* High contrast health overrides */
.theme-high-contrast .health-card {
  border-width: 2px;
}

.theme-high-contrast .health-service {
  border-width: 2px;
}

.theme-high-contrast .health-service-badge {
  border: 1px solid currentColor;
}

/* ========================================
   Mobile Responsive (<=768px)
   ======================================== */

@media (max-width: 768px) {
  /* Sidebar becomes an overlay */
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    z-index: 20;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }

  /* When open on mobile, slide in */
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }

  /* Desktop collapsed class has no effect on mobile */
  .sidebar.collapsed {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }

  .sidebar.collapsed.mobile-open {
    transform: translateX(0);
  }

  .sidebar.collapsed .sidebar-label { opacity: 1; height: auto; padding: 0 16px 8px; }
  .sidebar.collapsed .dir-item { padding: 7px 16px; justify-content: flex-start; }
  .sidebar.collapsed .dir-label,
  .sidebar.collapsed .dir-count { display: initial; }
  .sidebar.collapsed .dir-item { border-left: 3px solid transparent; }
  .sidebar.collapsed .dir-icon { width: 16px; height: 16px; }

  /* Backdrop */
  .sidebar-backdrop.visible {
    display: block;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    z-index: 19;
    background: rgba(0, 0, 0, 0.4);
    animation: modal-fade-in 0.2s ease;
  }

  /* Reduce main content padding */
  .main {
    padding: 16px;
  }

  /* Tighter header */
  .header {
    padding: 0 12px;
  }

  /* Smaller modal min-width */
  .modal-dialog {
    min-width: 0;
    width: 95%;
  }

  /* Edit guard toast tighter margins */
  .edit-guard-toast {
    margin: 0 16px 8px;
  }

  /* Chat: tighter layout on mobile */
  .chat-container {
    height: calc(100vh - var(--header-height) - 32px);
    height: calc(100dvh - var(--header-height) - 32px);
  }

  .chat-msg {
    max-width: 95%;
  }

  .chat-msg-user {
    margin-left: 16px;
  }

  .chat-input-area .btn {
    height: 44px;
    padding: 0 14px;
  }

  /* Monitor: responsive layout on mobile */
  .monitor-kv-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .monitor-kv-label {
    font-weight: 600;
    margin-top: 8px;
  }

  .monitor-kv-label:first-child {
    margin-top: 0;
  }

  .monitor-tabs {
    overflow-x: auto;
  }

  .monitor-table {
    font-size: 0.75rem;
  }

  .monitor-table th,
  .monitor-table td {
    padding: 6px 8px;
  }

  .health-grid {
    grid-template-columns: 1fr;
  }

  /* EasyMDE editor on mobile: remove max-height so the editor grows to
     its natural content height inside the scrollable .main container.
     Users scroll the page to reach the bottom and the Save/Cancel buttons. */
  .EasyMDEContainer .CodeMirror {
    max-height: none !important;
    min-height: 120px !important;
  }

  .EasyMDEContainer.sided--no-fullscreen .editor-preview-active-side {
    max-height: none !important;
    min-height: 120px !important;
  }
}
