/* Predsol Crystal Pressure Gauge Data Logger - Styles */

:root {
  --primary: #012a57;
  --primary-light: #034078;
  --bg: #F8FAFC;
  --card-bg: #FFFFFF;
  --text: #1E293B;
  --text-muted: #64748B;
  --success: #059669;
  --danger: #DC2626;
  --warning: #D97706;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.06);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.header__inner {
  width: 95%;
  max-width: 95vw;
  margin: 0 auto;
  padding: 1rem 1.5rem 1rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header__left {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-right: auto;
}

.header__logo {
  display: block;
  flex-shrink: 0;
}

.header__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
}

.header__right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header__ref-time {
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.header__recordings-btn {
  text-decoration: none;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.header__recordings-btn:hover {
  background: #011d3a;
}

.reference-time {
  background: var(--card-bg);
  padding: 0.5rem 2rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 1px solid #E2E8F0;
}

.reference-time__label {
  margin-right: 0.5rem;
}

.reference-time__value {
  font-variant-numeric: tabular-nums;
}

/* Main layout */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem;
}

.main--logger {
  max-width: 95vw;
  width: 95%;
  padding: 1.25rem;
}

.main--recordings {
  max-width: 95vw;
  width: 95%;
}

/* Logger compact layout */
.logger-row {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}

.logger-row:last-child {
  margin-bottom: 0;
}

.logger-row--top {
  grid-template-columns: 1fr 1fr 1fr;
}

.logger-row--bottom {
  grid-template-columns: minmax(200px, 320px) 1fr;
}

.card--compact {
  padding: 1rem 1.25rem;
  margin-bottom: 0;
}

.card--compact .card__title {
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.measurement-widget--compact {
  padding: 1rem;
  min-height: 72px;
}

.measurement-widget--compact .measurement-value {
  font-size: 2rem;
}

.measurement-widget--compact .measurement-unit {
  font-size: 1.25rem;
}

.card--compact .connection-hint {
  margin-top: 0.5rem;
  font-size: 0.75rem;
}

.card--compact .device-info {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  font-size: 0.8125rem;
}

.card--compact .statistics-grid {
  gap: 1rem;
}

.card--compact .stat-value {
  font-size: 1.25rem;
}

.card--compact .chart-container {
  height: 280px;
  min-height: 180px;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 2rem;
  margin-bottom: 2rem;
}

.card__title {
  margin: 0 0 1rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

/* Connection panel */
.connection-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.device-info {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #E2E8F0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text);
}

.device-info[aria-hidden="true"] {
  display: none;
}

.device-info__item {
  white-space: nowrap;
}

.connection-hint {
  margin: 0.75rem 0 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 42rem;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
}

.status-indicator::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-indicator[data-status="connected"] {
  color: var(--success);
  background: rgba(5, 150, 105, 0.12);
}

.status-indicator[data-status="disconnected"] {
  color: var(--danger);
  background: rgba(220, 38, 38, 0.12);
}

.status-indicator[data-status="reconnecting"] {
  color: var(--warning);
  background: rgba(217, 119, 6, 0.12);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

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

.btn--primary {
  background: var(--primary);
  color: white;
}

.btn--primary:hover:not(:disabled) {
  background: #011d3a;
}

.btn--secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #E2E8F0;
}

.btn--secondary:hover:not(:disabled) {
  background: #F1F5F9;
}

.btn--success {
  background: var(--success);
  color: white;
}

.btn--success:hover:not(:disabled) {
  background: #047857;
}

.btn--danger {
  background: var(--danger);
  color: white;
}

.btn--danger:hover:not(:disabled) {
  background: #B91C1C;
}

.btn--sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* Measurement widget */
.measurement-widget {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  min-height: 120px;
}

.measurement-value {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.measurement-unit {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Statistics grid */
.statistics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1.5rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-unit {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Recording controls */
.recording-controls {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
}

.card--recording.card--compact {
  display: flex;
  flex-direction: column;
}

.card--recording.card--compact .recording-controls {
  flex: 1;
  align-items: stretch;
}

.btn--record {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn--record .btn__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn--record:active:not(:disabled) {
  transform: scale(0.98);
}

.btn--record.btn--start {
  background: var(--success);
  color: white;
}

.btn--record.btn--start:hover:not(:disabled) {
  background: #047857;
}

.btn--record.btn--stop {
  background: var(--danger);
  color: white;
}

.btn--record.btn--stop:hover:not(:disabled) {
  background: #B91C1C;
}

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

/* Chart */
.chart-container {
  position: relative;
  width: 100%;
  height: 320px;
  min-height: 200px;
}

.chart-container canvas {
  display: block;
  max-width: 100%;
}

.chart-fallback-msg {
  margin: 0;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* Navigation */
.nav {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid #E2E8F0;
}

.nav--top {
  margin-top: 0;
  margin-bottom: 1.5rem;
  padding-top: 0;
  border-top: none;
  border-bottom: 1px solid #E2E8F0;
  padding-bottom: 1rem;
}

.nav-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.nav-link:hover {
  text-decoration: underline;
}

/* Modals – hidden by default, shown with .visible class */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  max-width: 420px;
  width: 100%;
}

.modal__title {
  margin: 0 0 0.75rem 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.modal__text {
  margin: 0 0 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.modal__input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.modal__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.modal__actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.modal--chart {
  max-width: min(90vw, 800px);
  width: 100%;
}

.modal__chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal__chart-header .modal__title {
  margin: 0;
}

.modal__close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal__close-btn:hover {
  color: var(--text);
}

.chart-container--modal {
  height: 400px;
  min-height: 300px;
  margin-bottom: 1rem;
}

.modal__chart-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn--chart {
  background: #7c3aed;
  color: white;
  border: none;
}

.btn--chart:hover:not(:disabled) {
  background: #6d28d9;
}

/* Recordings page */
.recordings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.recordings-header .card__title {
  margin-bottom: 0;
}

.table-wrapper {
  overflow-x: auto;
  margin-bottom: 1rem;
}

.switch-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding: 0.375rem 0;
}

.switch-toggle__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-toggle__slider {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 22px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}

.switch-toggle__slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}

.switch-toggle__input:checked + .switch-toggle__slider {
  background: var(--primary);
}

.switch-toggle__input:checked + .switch-toggle__slider::before {
  transform: translateX(18px);
}

.switch-toggle__label {
  font-weight: 500;
  color: var(--text);
}

.switch-toggle__input:focus-visible + .switch-toggle__slider {
  box-shadow: 0 0 0 3px rgba(1, 42, 87, 0.3);
}

.btn-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.2em;
  margin-right: 0.35em;
  flex-shrink: 0;
}

.btn--open {
  background: var(--primary);
  color: white;
  border: none;
}

.btn--open:hover:not(:disabled) {
  background: #011d3a;
}

.btn--csv {
  background: #0d9488;
  color: white;
  border: none;
}

.btn--csv:hover:not(:disabled) {
  background: #0f766e;
}

.btn--excel {
  background: #15803d;
  color: white;
  border: none;
}

.btn--excel:hover:not(:disabled) {
  background: #166534;
}

.btn--archive {
  background: #64748b;
  color: white;
  border: none;
}

.btn--archive:hover:not(:disabled) {
  background: #475569;
}

.btn--unarchive {
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn--unarchive:hover:not(:disabled) {
  background: rgba(1, 42, 87, 0.08);
}

.btn--png {
  background: #7c3aed;
  color: white;
  border: none;
}

.btn--png:hover:not(:disabled) {
  background: #6d28d9;
}

.btn--close {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #E2E8F0;
}

.btn--close:hover:not(:disabled) {
  background: #F1F5F9;
}

.recordings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  table-layout: auto;
}

.recordings-table th:first-child,
.recordings-table td:first-child {
  min-width: 0;
}

.recordings-table th:nth-child(2),
.recordings-table th:nth-child(3),
.recordings-table th:nth-child(4),
.recordings-table th:nth-child(5),
.recordings-table td:nth-child(2),
.recordings-table td:nth-child(3),
.recordings-table td:nth-child(4),
.recordings-table td:nth-child(5) {
  width: 1%;
  white-space: nowrap;
}

.recordings-table th,
.recordings-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #E2E8F0;
}

.recordings-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
}

.link-button:hover {
  text-decoration: underline;
}

.recordings-table .actions-cell {
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.recordings-table .actions-cell .btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.main--recordings .btn--csv,
.main--recordings #detailExportCsv {
  display: none;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin: 0;
}

.detail-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

/* Responsive */
@media (max-width: 900px) {
  .logger-row--top {
    grid-template-columns: 1fr;
  }

  .logger-row--bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .header__inner {
    padding: 1rem;
  }

  .header__title {
    font-size: 1.125rem;
  }

  .header__right {
    width: 100%;
    justify-content: flex-end;
  }

  .main {
    padding: 1rem;
  }

  .main--logger {
    padding: 1rem;
  }

  .card {
    padding: 1rem 1.25rem;
  }

  .measurement-value {
    font-size: 2.25rem;
  }

  .measurement-unit {
    font-size: 1.25rem;
  }
}
