* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
  background-image:
    linear-gradient(#e8e8e8 1px, transparent 1px),
    linear-gradient(90deg, #e8e8e8 1px, transparent 1px);
  background-size: 28px 28px;
  color: #111827;
}

.app {
  max-width: 1340px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 96px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 58px;
  height: 58px;
  border-radius: 10px;
  background: white;
  border: 1px solid #ddd;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #c7352b;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  overflow: hidden;
}

.logo-wide {
  width: 146px;
  height: 58px;
  padding: 8px 12px;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.brand p,
.muted {
  margin: 4px 0 0;
  font-size: 12px;
  color: #6b7280;
}

.date-pill {
  background: white;
  border: 1px solid #ddd;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12px;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.tab-btn,
.secondary-btn {
  border: 1px solid #d1d5db;
  background: white;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: #c7352b;
  color: white;
  border-color: #c7352b;
}

.secondary-btn:hover,
.tab-btn:hover {
  filter: brightness(0.98);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.panel {
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.05);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.records-header {
  align-items: flex-start;
}

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

.toolbar input,
.panel-header input {
  width: min(420px, 100vw - 44px);
  padding: 12px 13px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.records-table {
  min-width: 2450px;
}

.report-table {
  min-width: 1120px;
}

th {
  background: #1e3a8a;
  color: white;
  padding: 12px;
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

td {
  border-bottom: 1px solid #e5e7eb;
  padding: 12px;
  font-size: 13px;
  white-space: nowrap;
  vertical-align: top;
}

.long-cell {
  white-space: normal;
  min-width: 180px;
  max-width: 260px;
}

.status {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  display: inline-block;
}

.status.Following {
  background: #dbeafe;
  color: #1d4ed8;
}

.status.Success {
  background: #dcfce7;
  color: #15803d;
}

.status.Fail {
  background: #fee2e2;
  color: #b91c1c;
}

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

.view-btn,
.edit-btn,
.delete-btn {
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.view-btn {
  background: #e0f2fe;
  color: #0369a1;
}

.edit-btn {
  background: #fef3c7;
  color: #92400e;
}

.delete-btn {
  background: #fee2e2;
  color: #b91c1c;
}

.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: #c7352b;
  color: white;
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(199, 53, 43, 0.35);
  z-index: 10;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.42);
  display: none;
  justify-content: center;
  align-items: flex-end;
  z-index: 20;
}

.modal.active {
  display: flex;
}

.modal-card {
  width: min(1040px, 100%);
  max-height: 94vh;
  overflow-y: auto;
  background: white;
  border-radius: 22px 22px 0 0;
  padding: 18px;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.16);
}

.form-card {
  width: min(1080px, 100%);
}

.details-card {
  width: min(900px, 100%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.close-btn {
  border: none;
  background: #f3f4f6;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}

.form-section {
  border: 1px solid #d1d5db;
  border-radius: 14px;
  margin-bottom: 14px;
  padding: 14px;
  background: #fff;
}

.form-section h3 {
  margin: 0 0 14px;
  font-size: 13px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #d92d20;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 14px;
  background: #f9fafb;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.check-grid label {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 16px;
  align-items: center;
  text-align: center;
  cursor: pointer;
}

.check-grid input {
  width: 20px;
  height: 20px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.save-btn {
  flex: 1;
  border: none;
  background: #c7352b;
  color: white;
  padding: 16px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

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

.empty {
  text-align: center;
  color: #6b7280;
  padding: 24px;
}

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

.detail-item {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
  background: #f9fafb;
}

.detail-item.full {
  grid-column: 1 / -1;
}

.detail-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #6b7280;
  margin-bottom: 6px;
}

.detail-value {
  font-size: 14px;
  word-break: break-word;
}

@media (max-width: 768px) {
  .app {
    padding: 14px;
    padding-bottom: 90px;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .brand {
    align-items: flex-start;
  }

  .logo-wide {
    width: 128px;
  }

  h1 {
    font-size: 14px;
    letter-spacing: 2px;
  }

  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar input,
  .toolbar button {
    width: 100%;
  }

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

  .check-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-actions {
    flex-direction: column;
  }

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

  .fab {
    right: 18px;
    bottom: 18px;
  }

  /* Mobile card layout: no horizontal table scrolling */
  .table-wrap {
    overflow-x: visible;
  }

  .records-table,
  .report-table {
    min-width: 0;
    width: 100%;
  }

  .records-table thead,
  .report-table thead {
    display: none;
  }

  .records-table,
  .records-table tbody,
  .records-table tr,
  .records-table td,
  .report-table,
  .report-table tbody,
  .report-table tr,
  .report-table td {
    display: block;
  }

  .records-table tbody,
  .report-table tbody {
    padding: 10px;
  }

  .records-table tr,
  .report-table tr {
    margin-bottom: 14px;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #ffffff;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0,0,0,0.04);
  }

  .records-table td,
  .report-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    width: 100%;
    border-bottom: 1px solid #f1f5f9;
    padding: 11px 12px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
    text-align: right;
  }

  .records-table td:last-child,
  .report-table td:last-child {
    border-bottom: 0;
  }

  .records-table td::before,
  .report-table td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    max-width: 42%;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: #6b7280;
    text-align: left;
  }

  .records-table td.empty,
  .report-table td.empty {
    display: block;
    text-align: center;
    padding: 24px 12px;
  }

  .records-table td.empty::before,
  .report-table td.empty::before {
    display: none;
  }

  .long-cell {
    min-width: 0;
    max-width: none;
  }

  .actions-cell {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .view-btn,
  .edit-btn,
  .delete-btn {
    padding: 9px 11px;
  }

  .modal-card {
    max-height: 96vh;
    padding: 14px;
  }

}

/* Desktop records: full information card layout, no horizontal scrolling needed */
.records-table {
  min-width: 0;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 14px;
}

.records-table thead {
  display: none;
}

.records-table tbody {
  display: block;
  padding: 12px;
}

.records-table tr {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 5px 18px rgba(0,0,0,0.05);
  margin-bottom: 14px;
}

.records-table td {
  display: block;
  white-space: normal;
  word-break: break-word;
  min-height: 68px;
  border-bottom: 1px solid #f1f5f9;
  border-right: 1px solid #f1f5f9;
  padding: 12px;
  line-height: 1.35;
}

.records-table td::before {
  content: attr(data-label);
  display: block;
  font-size: 10px;
  line-height: 1.2;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #6b7280;
  margin-bottom: 7px;
}

.records-table td.long-cell {
  grid-column: span 2;
  min-width: 0;
  max-width: none;
  min-height: 86px;
}

.records-table td[data-label="Action"] {
  grid-column: 1 / -1;
  min-height: auto;
  border-bottom: 0;
}

.records-table td.empty {
  grid-column: 1 / -1;
  display: block;
  text-align: center;
}

.records-table td.empty::before {
  display: none;
}

.charts-header {
  align-items: flex-start;
}

.chart-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.inline-control {
  min-width: 160px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.inline-control select {
  margin-top: 7px;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 16px;
}

.chart-card {
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #fff;
  padding: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.04);
}

.chart-title h3 {
  margin: 0;
  font-size: 15px;
}

.chart-title p {
  margin: 5px 0 12px;
  font-size: 12px;
  color: #6b7280;
}

.chart-box {
  position: relative;
  width: 100%;
  height: 320px;
}

.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 1180px) {
  .records-table tr {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .records-table tr,
  .charts-grid {
    grid-template-columns: 1fr;
  }

  .records-table td.long-cell {
    grid-column: 1 / -1;
  }

  .chart-controls,
  .chart-controls .inline-control {
    width: 100%;
  }

  .chart-box {
    height: 280px;
  }
}

/* Records date filters */
.records-toolbar select,
.records-toolbar .date-filter-input {
  min-width: 150px;
  width: auto;
  padding: 12px 13px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* Updated charts layout */
.chart-card-wide {
  grid-column: 1 / -1;
}

.chart-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.compact-control {
  width: min(220px, 100%);
  min-width: 180px;
}

.compact-control select {
  margin-top: 7px;
}

@media (max-width: 768px) {
  .records-toolbar select,
  .records-toolbar .date-filter-input {
    width: 100%;
  }

  .chart-title-row {
    flex-direction: column;
  }

  .compact-control {
    width: 100%;
  }
}
