/* App Container Layout */
.app-container {
  display: flex;
  width: 100%;
  height: 100vh;
  padding: 2.5vh; /* This creates the space around the app */
  gap: 1.5rem;
}

/* Side Menu Styles */
#side-menu {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-color);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  display: flex; /* Use flexbox for its children */
  flex-direction: column;
  gap: 1.5rem; /* Space between menu groups if ever visible at once */
}

/* Menu Button Groups and Buttons */

.menu-btn {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-color);
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-color);
}

.menu-btn:focus, .menu-btn.active {
  background: rgba(var(--primary-accent-rgb), 0.2);
  color: var(--primary-accent);
  border-color: var(--primary-accent);
  outline: none;
}

/* Dashboard Panel Styles */
.dashboard-panel {
  flex: 1; /* This is the key change to make it fill remaining space */
  position: relative;
  background: var(--surface-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* REMOVE height, width, max-width, and margin properties */
}

/* Dashboard Section Titles */
.dashboard-section-title {
  font-weight: 600;
  color: var(--text-color);
  font-size: 1.1rem;
  margin: 0 0 1rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}


.dashboard-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.dashboard-placeholder {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 3rem 1rem;
}

/* Dashboard Grid Layout */
.dashboard-main-grid {
  /* Reverted to a standard grid to fix chart rendering */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

/* Home Launcher Container */
#home-container {
  /* Styled to match the KPI grid layout */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* New grid for KPIs */
.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem; /* Space between KPIs and main content */
}

.card-full-width {
  grid-column: 1 / -1;
}

/* Card Styles */
.dashboard-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 1.5rem;
  transition: all 0.2s;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden; /* Ensure clean animation boundaries */
}

.dashboard-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

/* Makes the card header flexible for the new icon */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.card-title {
  font-weight: 600;
  color: var(--text-color);
  font-size: 1rem;
  margin: 0;
  flex: 1; /* Allows title to take space, pushing icon to the right */
}

/* Card explanation styles */
.card-explanation {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: 0.5rem; /* Space between header and explanation */
}

/* KPI Card Styles */
.kpi-card .card-value {
  font-size: 1.5rem; /* Slightly smaller to fit multiple lines */
  font-weight: 700;
  color: var(--primary-accent);
  margin: auto 0;
  text-align: left;
  line-height: 1.4;
}

.kpi-card .card-value small {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.kpi-percentage-positive {
  color: #48bb78; /* Green */
  font-size: 1rem;
}

.kpi-percentage-negative {
  color: #f56565; /* Red */
  font-size: 1rem;
}

/* Text Card Styles */
.text-card .card-content {
  font-size: 0.9rem;
  color: var(--text-color);
  line-height: 1.5;
  margin: auto 0;
}

/* Chart Card Styles */
.chart-card {
  min-height: 300px;
}

.chart-container {
  flex: 1;
  min-height: 250px;
  border-radius: 8px;
  overflow: hidden;
}


/* Loading States */
.dashboard-loading {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 2rem;
}

.dashboard-error {
  text-align: center;
  color: #fc8181;
  font-size: 0.9rem;
  padding: 2rem;
}

/* Workflow Stats Specific Styles */
.workflow-status {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-active {
  background: rgba(72, 187, 120, 0.2);
  color: #48bb78;
  border: 1px solid rgba(72, 187, 120, 0.3);
}

.status-inactive {
  background: rgba(160, 174, 192, 0.2);
  color: #a0aec0;
  border: 1px solid rgba(160, 174, 192, 0.3);
}

.workflow-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  font-size: 0.8rem;
  margin-bottom: 1rem;
}

.stat-item {
  text-align: center;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}

.stat-value {
  display: block;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 0.25rem;
}

.stat-label {
  display: block;
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.workflow-last-execution {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.workflow-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto; /* Push buttons to bottom of flex container */
  padding-top: 1rem; /* Add padding to ensure space from content above */
  flex-wrap: wrap;
}

.export-xlsx-btn {
  background: rgba(72, 187, 120, 0.2);
  color: #48bb78;
  border: 1px solid rgba(72, 187, 120, 0.3);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.export-xlsx-btn:hover {
  background: rgba(72, 187, 120, 0.3);
  border-color: rgba(72, 187, 120, 0.5);
  transform: translateY(-1px);
}

.export-xlsx-btn.hidden {
  display: none;
}

.last-execution-time {
  color: var(--text-color);
  font-weight: 500;
}

.workflow-item.exporting {
  animation: exportHighlight 2s ease-in-out;
  border: 2px solid rgba(72, 187, 120, 0.8) !important;
  box-shadow: 0 0 20px rgba(72, 187, 120, 0.4) !important;
}

@keyframes exportHighlight {
  0%, 100% {
    border-color: rgba(72, 187, 120, 0.8);
    box-shadow: 0 0 20px rgba(72, 187, 120, 0.4);
  }
  50% {
    border-color: rgba(72, 187, 120, 1);
    box-shadow: 0 0 30px rgba(72, 187, 120, 0.6);
  }
}

/* --- STYLES COPIED FROM DELETED workflow-stats.css --- */

/* Styles for the dashboard header */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(var(--surface-color-rgb), 0.8);
  gap: 1rem;
}

.panel-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-color);
  min-width: 120px; /* Ensure title has some minimum width */
}

.panel-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Styles for the visualizer toggle button */
.workflow-visualizer-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: var(--primary-accent);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0, 183, 255, 0.3);
}

.workflow-visualizer-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(0, 183, 255, 0.4);
}

/* --- New Dashboard View Controls --- */

.dashboard-controls {
  /* flex: 1; <-- REMOVE THIS (no longer needed) */
  display: flex;
  justify-content: flex-end;
  margin-left: auto;
}


/* --- New Workflow Action Button Styles --- */

/* Base style for new buttons */
.workflow-action-btn {
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid;
}

.workflow-action-btn:hover {
  transform: translateY(-1px);
}

/* "Execute" button style (using primary accent) */
.btn-execute {
  background: rgba(0, 183, 255, 0.2);
  color: var(--primary-accent);
  border-color: rgba(0, 183, 255, 0.3);
}

.btn-execute:hover {
  background: rgba(0, 183, 255, 0.3);
  border-color: rgba(0, 183, 255, 0.5);
}

/* "Explain" button style (using a new blue accent) */
.btn-explain {
  background: rgba(66, 153, 225, 0.2);
  color: #4299e1;
  border-color: rgba(66, 153, 225, 0.3);
}

.btn-explain:hover {
  background: rgba(66, 153, 225, 0.3);
  border-color: rgba(66, 153, 225, 0.5);
}

/* --- New Command Bar Styles (Replaces old chat.css) --- */

#chat-form {
  display: flex;
  gap: 0.75rem;
  flex: 1; /* <-- ADDED */
  /* padding, background, border-bottom, width, and z-index are REMOVED */
}

#chat-input {
  flex: 1;
  border: 1px solid var(--border-color);
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-color);
  height: 44px;
  line-height: 44px;
  padding: 0 1rem;
  outline: none;
  border-radius: 8px; /* New style */
  transition: all 0.2s;
}

#chat-input:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--primary-accent);
}

#chat-input::placeholder {
  color: var(--text-light);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px; /* Match input */
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  background-color: var(--primary-accent);
  color: #0D0E1B;
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 15px var(--primary-accent);
}

/* New Loader Styles */
#thinking-loader {
  display: none; /* Hidden by default */
  padding: 1rem;
  background: rgba(var(--surface-color-rgb), 0.5);
  border-bottom: 1px solid var(--border-color);
}

/* When 'thinking', show loader and hide input */
.dashboard-panel.thinking #thinking-loader {
  display: flex;
  justify-content: center;
}

.dashboard-panel.thinking #chat-form {
  opacity: 0.5;
  pointer-events: none;
}



/* --- New Custom Table Styles --- */

.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.dashboard-table th,
.dashboard-table td {
  border: 1px solid var(--border-color);
  padding: 0.75rem;
  text-align: left;
  color: var(--text-secondary);
}

.dashboard-table th {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-color);
  font-weight: 600;
}

/* --- Professional Table Styling (Replaces DataTables) --- */

.tile-table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 1rem;
}

.tile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: transparent;
  color: var(--text-color);
}

.tile-table thead {
  background: rgba(255, 255, 255, 0.1);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.tile-table th {
  padding: 1rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-color);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.tile-table th:last-child {
  border-right: none;
}

.tile-table tbody tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.tile-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tile-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.tile-table tbody tr:nth-child(even):hover {
  background: rgba(255, 255, 255, 0.11);
}

.tile-table td {
  padding: 0.75rem;
  color: var(--text-secondary);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.tile-table td:last-child {
  border-right: none;
}

/* Table header sorting indicators */
.tile-table th.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 1.5rem;
}

.tile-table th.sortable::after {
  content: '↕';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  opacity: 0.5;
}

.tile-table th.sortable:hover::after {
  opacity: 0.8;
}

.tile-table th.sortable.asc::after {
  content: '↑';
  opacity: 1;
}

.tile-table th.sortable.desc::after {
  content: '↓';
  opacity: 1;
}

/* Table empty state */
.tile-table-empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Table responsive design */
@media (max-width: 768px) {
  .tile-table-container {
    font-size: 0.8rem;
  }

  .tile-table th,
  .tile-table td {
    padding: 0.5rem 0.25rem;
  }
}

/* Add this new rule at the end of the file */
.insight-card {
  border-top: 3px solid var(--primary-accent);
  background: rgba(var(--primary-accent-rgb), 0.05); /* Slight orange tint */
}

/* Success card styling for successful activities */
.success-card {
  border-top: 3px solid #48bb78;
  background: rgba(72, 187, 120, 0.1);
  color: #48bb78;
}

.success-card .card-title {
  color: #48bb78;
}

/* Warning card styling for action required items */
.warning-card {
  border-top: 3px solid #f56565;
  background: rgba(245, 101, 101, 0.1);
  color: #f56565;
}

.warning-card .card-title {
  color: #f56565;
}

/* Waiting card styling for items waiting for action */
.waiting-card {
  border-top: 3px solid #ed8936;
  background: rgba(237, 137, 54, 0.1);
  color: #ed8936;
}

.waiting-card .card-title {
  color: #ed8936;
}

/* Dynamic counter styles */
.card-counter {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}

.success-card .card-counter {
  background: rgba(72, 187, 120, 0.3);
  color: #48bb78;
}

.waiting-card .card-counter {
  background: rgba(237, 137, 54, 0.3);
  color: #ed8936;
}

.warning-card .card-counter {
  background: rgba(245, 101, 101, 0.3);
  color: #f56565;
}

/* Container-specific counter styles */
.waiting-container .card-counter {
  background: rgba(237, 137, 54, 0.3);
  color: #ed8936;
}

.success-container .card-counter {
  background: rgba(72, 187, 120, 0.3);
  color: #48bb78;
}

/* Add this new rule at the end of the file */
.dashboard-introduction-card {
  grid-column: 1 / -1; /* Make it full width */
  background: transparent;
  border: none;
  padding: 0 0 1.5rem 0; /* Only padding at the bottom */
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}
.dashboard-introduction-card .card-title {
  font-size: 1.2rem;
}
.dashboard-introduction-card .card-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 80ch; /* Limit line length for readability */
}

/* --- New User Avatar Menu Styles --- */

.user-menu-container {
  position: relative;
}

.user-avatar-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.user-avatar-btn:hover {
  color: var(--text-color);
  background: rgba(255, 255, 255, 0.2);
  border-color: var(--primary-accent);
}

.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 10px); /* 10px spacing from button */
  right: 0;
  width: 200px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.5rem;
  z-index: 1000;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.1s ease-out; /* Simple fade-in */
}

/* Reuse .menu-btn styles, but adjust margins for the dropdown */
.user-dropdown-menu .menu-btn {
  margin-bottom: 0.25rem;
}

.user-dropdown-menu .menu-btn:last-child {
  margin-bottom: 0;
}

/* --- Todo Activity Card Styles --- */

.todo-activity-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 1.5rem;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

.todo-activity-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(180deg, #ed8936, #f56565);
}

.todo-activity-card.pending::before {
  background: linear-gradient(180deg, #ed8936, #f6ad55);
}

.todo-activity-card.success::before {
  background: linear-gradient(180deg, #48bb78, #68d391);
}

.todo-activity-card.error::before {
  background: linear-gradient(180deg, #f56565, #fc8181);
}

.todo-activity-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.todo-activity-title {
  font-weight: 600;
  color: var(--text-color);
  font-size: 1.1rem;
  margin: 0;
  flex: 1;
}

.todo-activity-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.todo-activity-status {
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.todo-activity-status.pending {
  background: rgba(237, 137, 54, 0.2);
  color: #ed8936;
  border: 1px solid rgba(237, 137, 54, 0.3);
}

.todo-activity-status.success {
  background: rgba(72, 187, 120, 0.2);
  color: #48bb78;
  border: 1px solid rgba(72, 187, 120, 0.3);
}

.todo-activity-status.error {
  background: rgba(245, 101, 101, 0.2);
  color: #f56565;
  border: 1px solid rgba(245, 101, 101, 0.3);
}

.todo-activity-description {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.todo-activity-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.todo-confirm-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.todo-confirm-btn.yes {
  background: rgba(72, 187, 120, 0.2);
  color: #48bb78;
  border: 1px solid rgba(72, 187, 120, 0.3);
}

.todo-confirm-btn.yes:hover {
  background: rgba(72, 187, 120, 0.3);
  border-color: rgba(72, 187, 120, 0.5);
  transform: translateY(-1px);
}

.todo-confirm-btn.no {
  background: rgba(245, 101, 101, 0.2);
  color: #f56565;
  border: 1px solid rgba(245, 101, 101, 0.3);
}

.todo-confirm-btn.no:hover {
  background: rgba(245, 101, 101, 0.3);
  border-color: rgba(245, 101, 101, 0.5);
  transform: translateY(-1px);
}

.todo-activity-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  color: var(--text-light);
}

.todo-activity-id {
  font-family: monospace;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.todo-activity-type {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

