:root {
  --color-bg: #f5f6fa;
  --color-primary: #2f3640;
  --color-accent: #00a8ff;
  --color-success: #4cd137;
  --color-warning: #fbc531;
  --color-error: #e84118;
  --sidebar-width: 240px;
  font-family: "Vazirmatn", "Tahoma", sans-serif;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-primary);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.rond-switch form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rond-switch label {
  font-size: 14px;
  font-weight: 600;
}

.rond-switch select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d5d5d5;
  background: #f7f8fa;
  font-size: 14px;
  cursor: pointer;
}

.nav-toggle {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
}

.sidebar {
  position: fixed;
  top: 60px;
  right: 0;
  width: var(--sidebar-width);
  bottom: 0;
  background: #fff;
  border-left: 1px solid #e0e0e0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 9;
}

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

.sidebar a {
  color: var(--color-primary);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.sidebar a:hover {
  background: rgba(0, 168, 255, 0.12);
}

@media (min-width: 992px) {
  .sidebar {
    transform: translateX(0);
    left: auto;
    right: 0;
  }
  .content {
    margin-right: var(--sidebar-width);
  }
}

.content {
  padding: 24px 32px;
}

.flash-container {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.flash {
  padding: 10px 14px;
  border-radius: 10px;
  border-right: 4px solid;
  background: #fff;
  line-height: 1.6;
}

.flash--success {
  border-color: var(--color-success);
}

.flash--info {
  border-color: var(--color-accent);
}

.flash--warning {
  border-color: var(--color-warning);
}

.flash--error {
  border-color: var(--color-error);
}

.app-footer {
  text-align: center;
  padding: 18px 0 30px;
  color: #7f8c8d;
}

.form-card {
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  margin-bottom: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 24px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dcdde1;
  font-size: 14px;
  box-sizing: border-box;
}

button,
.button {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(0, 168, 255, 0.2);
}

button.is-active,
.button.is-active {
  background: var(--color-warning);
  color: #2f3640;
}

.accent {
  background: #f39c12;
}

.warning {
  background: #fbc531;
  color: #2f3640;
}

.error {
  background: #e84118;
}

.upload-button {
  margin-top: 8px;
  width: 100%;
}

.button.secondary,
button.secondary {
  background: #353b48;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

#shapes-table tr.selected {
  background-color: #e3f2fd;
}

#shapes-table tr.selected td {
  font-weight: 600;
}

/* Issue 18: Light green background for best layout */
.comparison-table tr.is-best {
  background-color: #e8f5e9; /* Light green, more subtle */
  border-left: 4px solid #4caf50; /* Green accent border */
}

thead {
  background: #f0f6ff;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #ecf0f1;
}

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

.name-input {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.name-input select,
.name-input input[type="text"] {
  width: 100%;
}

.color-input select {
  flex: 1;
}

.color-preview {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #ccc;
  flex-shrink: 0;
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 24px;
  align-items: start;
}

.legend-card {
  background: #fff;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.06);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.legend-color {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.preview-frame {
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.06);
}

.preview-frame img,
.preview-frame canvas {
  width: 100%;
  display: block;
  border-radius: 10px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.action-bar {
  gap: 16px;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.analysis-layout {
  display: grid;
  grid-template-columns: minmax(540px, 3fr) 1.5fr;
  gap: 20px;
  margin-top: 24px;
  align-items: start;
}

.analysis-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 32px;
}

.result-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
  background: #f8f9fb;
}

.detected-info {
  margin-top: 18px;
  border-top: 1px solid #ecf0f1;
  padding-top: 12px;
}

.detected-info ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
}

.detected-info li {
  background: #f0f6ff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.heatmap-stage {
  background: #fff;
  border-radius: 20px;
  padding: 24px 28px 32px;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.08);
}

.heatmap-stage__header {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 22px;
}

.heatmap-stage__body {
  display: flex;
  gap: 26px;
  align-items: stretch;
}

.heatmap-board {
  flex: 1 1 auto;
  background: #c7c7c7;
  border-radius: 18px;
  padding: 26px;
  display: flex;
  gap: 18px;
  justify-content: center;
  align-items: center;
}

.heatmap-frame {
  flex: 1 1 32%;
  min-width: 260px;
  background: #e5e5e5;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.heatmap-frame img {
  width: 100%;
  height: 100%;
  max-height: 420px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #d5d5d5;
}

.heatmap-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  min-width: 180px;
}

.heatmap-button {
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.heatmap-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.heatmap-button--primary {
  background: #7fb6d9;
  color: #1e1e1e;
}

.heatmap-button--success {
  background: #a8e6a0;
  color: #1e401e;
}

.heatmap-button--danger {
  background: #e57676;
  color: #fff;
}

.heatmap-empty {
  margin-top: 24px;
  text-align: center;
  background: #f5f6fa;
  border-radius: 12px;
  padding: 18px;
  border: 1px dashed #c8d6e5;
  font-weight: 500;
}

@media (max-width: 992px) {
  .heatmap-stage__body {
    flex-direction: column;
  }

  .heatmap-board {
    flex-direction: column;
  }

  .heatmap-controls {
    flex-direction: row;
  }

  .heatmap-button {
    flex: 1 1 30%;
  }
}

.status-card {
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.status-card strong {
  font-size: 18px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.gallery-grid img {
  width: 100%;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.lightbox__content {
  position: relative;
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}

.lightbox__content img {
  max-width: 100%;
  height: auto;
}

.lightbox__close {
  position: absolute;
  top: 8px;
  left: 8px;
  background: transparent;
  border: none;
  font-size: 32px;
  cursor: pointer;
}

.emotion-stage {
  background: #fff;
  border-radius: 20px;
  padding: 24px 28px 32px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.emotion-stage__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.emotion-stage__title h2 {
  margin: 0 0 8px;
}

.emotion-stage__title p {
  margin: 0;
  color: #636e72;
}

.emotion-stage__status {
  align-self: center;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #f1f2f6;
  color: #2f3640;
  font-weight: 600;
}

.emotion-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.toolbar-btn {
  background: #8c7ae6;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  color: #fff;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
}

.toolbar-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(140, 122, 230, 0.35);
}

.toolbar-btn.success {
  background: #44bd32;
}

.toolbar-btn.error {
  background: #e84118;
}

.toolbar-btn.accent {
  background: #0097e6;
}

.toolbar-btn.secondary {
  background: #2f3640;
}

.toolbar-btn.next-btn {
  background: linear-gradient(135deg, #4834d4, #686de0);
}

.toolbar-select {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.toolbar-select select {
  min-width: 140px;
}

.emotion-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.emotion-cameras {
  background: #f8f9fe;
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: inset 0 0 0 1px rgba(104, 109, 224, 0.2);
}

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

.cameras-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.cameras-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.camera-placeholder {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: #636e72;
}

.camera-placeholder p {
  margin: 8px 0;
}

.camera-hint {
  font-size: 13px;
  color: #95a5a6;
}

.camera-card {
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.camera-card video {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #000;
  min-height: 150px;
}

.camera-label {
  font-size: 13px;
  font-weight: 600;
  color: #2f3640;
}

.camera-status {
  font-size: 12px;
  font-weight: 500;
}

.emotion-charts-wrapper {
  display: grid;
  grid-template-columns: minmax(520px, 3fr) minmax(260px, 1fr);
  gap: 24px;
}

.emotion-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.emotion-chart-card {
  background: #f8f9fe;
  border-radius: 18px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: inset 0 0 0 1px rgba(104, 109, 224, 0.2);
}

.emotion-chart-card canvas {
  min-height: 300px;
  max-height: 400px;
}

.emotion-chart-card header h3 {
  margin: 0;
}

.chart-legend {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  color: #636e72;
}

.legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-left: 6px;
}

.legend-positive {
  background: #00cec9;
}

.legend-positive-light {
  background: #81ecec;
}

.legend-negative {
  background: #d63031;
}

.legend-negative-mid {
  background: #e17055;
}

.legend-negative-light {
  background: #fab1a0;
}

.legend-negative-alt {
  background: #ff7675;
}

.legend-neutral {
  background: #b2bec3;
}

.emotion-swatch {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.emotion-swatch__panel {
  background: #fef1e6;
  border-radius: 18px;
  padding: 18px 20px;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 159, 67, 0.3);
}

.swatch-label {
  font-weight: 700;
  font-size: 15px;
}

.swatch-preview {
  height: 120px;
  border-radius: 16px;
  margin: 16px 0;
  background: linear-gradient(135deg, #ff9f43, #e17055);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.swatch-note {
  margin: 0;
  font-size: 13px;
  color: #636e72;
}

.emotion-segments {
  background: #fdfdfd;
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: inset 0 0 0 1px rgba(223, 230, 233, 0.6);
}

.emotion-segments h4 {
  margin-top: 0;
}

.emotion-segments__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.segment-card {
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.segment-card img {
  /* Issue 111: Maintain proportions even if scale is not preserved in saved file */
  width: 100%;
  height: 96px;
  object-fit: contain;  /* Issue 111: Use contain instead of cover to maintain aspect ratio */
  background: #f5f5f5;
  border-radius: 8px;
}

.segment-card figcaption {
  padding: 8px 10px 12px;
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.segment-card.is-highlighted {
  box-shadow: 0 12px 24px rgba(72, 52, 212, 0.3);
  transform: translateY(-4px);
}

.segment-card.is-dimmed {
  opacity: 0.45;
}

.segments-empty {
  margin: 0;
  color: #636e72;
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.modal.hidden {
  display: none !important;
}

.modal__dialog {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal__dialog--wide {
  max-width: 960px;
}

.modal__header {
  padding: 16px 20px;
  background: #f0f3ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal__header h3 {
  margin: 0;
}

.modal__close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal__body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
}

.preferences-form {
  display: grid;
  gap: 14px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1 1 auto;
}

.slider-value {
  min-width: 60px;
  text-align: center;
  font-weight: 600;
  color: #4834d4;
}

.preferences-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.projector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.projector-grid figure {
  /* Issue 112: Make projector items clickable and interactive */
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.projector-grid figure:hover {
  /* Issue 112: Visual feedback on hover */
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.projector-grid figure.selected {
  /* Issue 112: Highlight selected item */
  border: 3px solid #00a8ff;
  box-shadow: 0 8px 24px rgba(0, 168, 255, 0.3);
  background: #f8f9fb;
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: inset 0 0 0 1px rgba(120, 120, 120, 0.08);
}

.projector-grid img {
  width: 100%;
  border-radius: 12px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #dcdde1;
}

.projector-grid figcaption {
  text-align: center;
  font-weight: 500;
}

@media (max-width: 1024px) {
  .emotion-content {
    grid-template-columns: 1fr;
  }

  .emotion-swatch {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .emotion-swatch__panel,
  .emotion-segments {
    flex: 1 1 280px;
  }
}


