/* ============================================================
   BUILDYBOT — APP VIEWER LAYOUT
   ============================================================ */

:root {
  --app-header-height: 48px;
  --app-header-bg: #1e293b;
  --app-header-text: #f1f5f9;
  --app-header-border: #334155;
  --app-header-font-size: 0.88rem;
  --app-header-padding-x: 1rem;
  --app-back-btn-bg: transparent;
  --app-back-btn-color: #f1f5f9;
  --app-back-btn-hover-bg: rgba(255, 255, 255, 0.12);
  --app-back-btn-radius: 4px;
  --app-body-bg: #f0f2f5;
  --app-body-padding: 0;

  --radius-sm: 4px;
  --border-color: #d1d5db;
  --bg: #f0f2f5;
  --nav-bg: #1e293b;
  --nav-text: #f1f5f9;
  --transition-speed: 0.2s;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--app-body-bg);
  color: #1e293b;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header bar --- */
.app-viewer-header {
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  align-items: center;
  height: var(--app-header-height);
  background: var(--app-header-bg);
  color: var(--app-header-text);
  border-bottom: 1px solid var(--app-header-border);
  padding: 0 var(--app-header-padding-x);
  gap: 0.75rem;
  font-size: var(--app-header-font-size);
}

.app-viewer-name {
  font-weight: 600;
  white-space: nowrap;
}

.app-viewer-body {
  flex: 1;
  background: var(--app-body-bg);
  padding: var(--app-body-padding);
  min-height: calc(100vh - var(--app-header-height));
}

/* --- Main container --- */
.main-container {
  max-width: none;
  margin: 0;
  padding: 1.25rem 1rem 3rem;
}

.section {
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.section h2 {
  margin: 0 0 0.6rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e293b;
}

.hint {
  font-size: 0.82rem;
  color: #64748b;
  margin: 0 0 0.5rem;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}
.section-header-row h2 {
  margin: 0;
}

/* Date Range */
.date-range-section {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.date-range-section h2 {
  margin: 0;
}
.date-range-row {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}
.date-range-row label {
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.date-range-row input[type="date"] {
  padding: 0.35rem 0.55rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.88rem;
  background: #fff;
}

/* Inputs Grid */
.inputs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 0;
}
.inputs-grid .section {
  margin-bottom: 0;
}

@media (max-width: 1100px) {
  .inputs-grid {
    grid-template-columns: 1fr;
  }
}

.table-container {
  min-height: 180px;
}
.table-container-large {
  min-height: 300px;
}

.table-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}
.btn-primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}
.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
.btn-lg {
  padding: 0.6rem 2rem;
  font-size: 1rem;
}
.btn-danger {
  color: #dc2626;
  border-color: #fca5a5;
}
.btn-danger:hover {
  background: #fef2f2;
  border-color: #dc2626;
}

/* Refresh Row */
.refresh-row {
  display: flex;
  justify-content: center;
  padding: 1.25rem 0;
}

/* File input */
input[type="file"] {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.file-upload-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.load-status {
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 0.5rem;
  min-height: 1.2em;
}

.hidden {
  display: none !important;
}

.paste-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1500;
}

.paste-modal-content {
  width: min(1050px, 100%);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.9rem 1rem 1rem;
}

.paste-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.paste-modal-header h3 {
  margin: 0;
  font-size: 1rem;
  color: #0f172a;
}

.paste-table {
  min-height: 320px;
  margin-top: 0.35rem;
}

.paste-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.commit-files-detail {
  padding: 4px 8px 6px 20px;
  background: #f8fafc;
  border-top: 1px dashed #e2e8f0;
}

.commit-file-row {
  padding: 2px 0;
  font-size: 0.76rem;
  color: #475569;
}

.commit-file-path {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.74rem;
  color: #334155;
}

.commit-file-stats {
  font-size: 0.73rem;
  margin-left: 0.5rem;
}

.commit-file-summary {
  display: block;
  font-size: 0.73rem;
  color: #64748b;
  padding-left: 0.5rem;
  margin-top: 1px;
}

/* --- Timeline --- */
.timeline-container {
  position: relative;
  padding: 1rem 0 1rem 2.5rem;
}
.timeline-container::before {
  content: '';
  position: absolute;
  left: 1.1rem;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #cbd5e1;
  border-radius: 2px;
}
.timeline-day {
  position: relative;
  margin-bottom: 1.2rem;
}
.timeline-day:last-child {
  margin-bottom: 0;
}
.timeline-dot {
  position: absolute;
  left: -1.65rem;
  top: 0.15rem;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #94a3b8;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px #cbd5e1;
}
.timeline-date {
  font-weight: 700;
  font-size: 0.92rem;
  color: #1e293b;
  margin-bottom: 0.35rem;
}
.timeline-events {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.timeline-event {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.84rem;
  line-height: 1.35;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  background: #f8fafc;
  border-left: 3px solid #94a3b8;
}
.timeline-event.type-commit {
  border-left-color: #8b5cf6;
  background: #f5f3ff;
}
.timeline-event .tag-commit {
  background: #8b5cf6;
  color: #fff;
}
.timeline-event.type-email {
  border-left-color: #0ea5e9;
  background: #f0f9ff;
}
.timeline-event .tag-email {
  background: #0ea5e9;
  color: #fff;
}
.timeline-event.type-time {
  border-left-color: #10b981;
  background: #ecfdf5;
}
.timeline-event .tag-time {
  background: #10b981;
  color: #fff;
}
.timeline-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  margin-top: 0.05rem;
}
.timeline-text {
  word-break: break-word;
}
.timeline-empty {
  color: #94a3b8;
  font-style: italic;
  font-size: 0.88rem;
}

/* Summary Totals */
.summary-totals {
  display: none;
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: #eef2ff;
  border: 1px solid #818cf8;
  border-radius: 4px;
}

.summary-totals table {
  border-collapse: collapse;
  width: auto;
  font-size: 0.75rem;
}

.summary-totals th,
.summary-totals td {
  padding: 2px 10px;
  text-align: center;
  border: 1px solid #c7d2fe;
}

.summary-totals th {
  background: #ddd6fe;
  font-weight: 700;
  font-size: 0.72rem;
  color: #1e1b4b;
}

.summary-totals td:first-child,
.summary-totals th:first-child {
  text-align: left;
  font-weight: 600;
  color: #1e293b;
}

.summary-totals tr.totals-grand td {
  border-top: 2px solid #818cf8;
  font-weight: 700;
  background: #ddd6fe;
  color: #1e1b4b;
}

/* Tabulator overrides for Excel-like feel */
.tabulator .tabulator-cell {
  padding: 1px 8px;
  font-size: 0.85rem;
}
.tabulator .tabulator-col-title {
  font-size: 0.82rem;
  font-weight: 700;
}
.tabulator .tabulator-cell.tabulator-editing input,
.tabulator .tabulator-cell.tabulator-editing textarea {
  font-size: 0.85rem;
  padding: 2px 4px;
}

.tabulator .tabulator-cell.notes-cell {
  white-space: normal;
  line-height: 1.35;
}

/* Responsive */
@media (max-width: 575.98px) {
  .app-viewer-header {
    gap: 0.5rem;
    --app-header-padding-x: 0.65rem;
  }
  .main-container {
    padding: 0.75rem 0.5rem 2rem;
  }
}