/* app/public/style.css - Clean, minimalist light theme design */

:root {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --radius: 12px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
}

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

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--danger-light);
  color: var(--danger);
  border-color: var(--danger);
  transform: scale(1.08);
}

/* Navigation Tabs */
nav.nav-tabs {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.5rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.85rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--primary);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Main Container */
main {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
}

/* Sections */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease-in-out;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

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

.btn-secondary:hover {
  background: #e2e8f0;
}

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* Form inputs */
.form-group {
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  font-size: 0.95rem;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

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

/* Reference Banner (Adding Reading) */
.reference-box {
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.ref-item {
  display: flex;
  flex-direction: column;
}

.ref-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ref-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
}

tr:hover td {
  background-color: #f1f5f9;
}

.table-group-header td {
  background-color: #f1f5f9 !important;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.6rem 1rem;
  border-top: 2px solid var(--border-color);
}

/* Hide mobile-specific cell labels on desktop */
.mobile-cell-label {
  display: none;
}

/* PIVOT TABLE COMPACT STYLES & VERTICAL ZEBRA STRIPING */
#pivot-table {
  border-collapse: separate;
  border-spacing: 0;
}

#pivot-table th, 
#pivot-table td {
  padding: 0.4rem 0.35rem;
  font-size: 0.82rem;
  border-right: 1px solid rgba(226, 232, 240, 0.6);
}

#pivot-table th:last-child, 
#pivot-table td:last-child {
  border-right: none;
}

#pivot-table th {
  font-size: 0.75rem;
  padding: 0.5rem 0.35rem;
  white-space: nowrap;
}

/* Vertical Zebra Striping (Alternating Even Columns) */
#pivot-table td:nth-child(even), 
#pivot-table th:nth-child(even) {
  background-color: #f1f5f9;
}

#pivot-table tr:hover td:nth-child(even) {
  background-color: #e2e8f0;
}

#pivot-table .table-group-header td {
  background-color: #e2e8f0 !important;
  border-right: none !important;
}

/* Pivot Cell Hover Edit Button */
.pivot-cell {
  position: relative;
  text-align: center;
  vertical-align: middle;
  min-width: 62px;
}

.pivot-edit-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  display: none;
  background: #ffffff;
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 0.65rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  z-index: 10;
  transition: transform 0.1s ease, background 0.1s;
}

.pivot-edit-btn:hover {
  background: var(--primary);
  color: #ffffff;
  transform: scale(1.1);
}

.pivot-cell:hover .pivot-edit-btn {
  display: inline-block;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-active { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* Anomaly Alert Box */
.anomaly-alert {
  background: var(--warning-light);
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

#login-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background-color: var(--bg-main);
  z-index: 999;
}

.auth-container {
  max-width: 360px;
  width: 100%;
  margin: 0 auto;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.auth-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1.5rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Checkbox Grid */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
  header {
    padding: 0.6rem 0.85rem;
  }
  .logo {
    font-size: 1rem;
    gap: 0.35rem;
  }
  .user-badge {
    display: none !important;
  }
  main {
    padding: 1rem 0.5rem;
  }
  .card {
    padding: 1rem 0.75rem;
  }
  nav.nav-tabs {
    padding: 0 0.5rem;
  }
  .tab-btn {
    padding: 0.75rem 0.6rem;
    font-size: 0.85rem;
  }

  /* MOBILE CARD LAYOUT FOR ADD READINGS TABLE */
  #tab-add-reading table, 
  #tab-add-reading thead, 
  #tab-add-reading tbody {
    display: block;
    width: 100%;
  }

  /* Hide table header on mobile */
  #tab-add-reading table thead {
    display: none;
  }

  #tab-add-reading tbody tr:not(.table-group-header) {
    display: grid;
    grid-template-columns: 1fr 1.6fr;
    grid-template-areas: 
      "info info"
      "prev input"
      "prev delta"
      "cost cost";
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.85rem;
    margin-bottom: 0.85rem;
    gap: 0.35rem 0.75rem;
    box-shadow: var(--shadow-sm);
    width: 100%;
  }

  #tab-add-reading tbody tr.table-group-header {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    width: 100%;
  }

  #tab-add-reading tbody td {
    padding: 0;
    border: none;
    background: transparent !important;
  }

  #tab-add-reading tbody tr .meter-info-td {
    grid-area: info;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
  }

  #tab-add-reading tbody tr .reading-col-prev {
    grid-area: prev;
    align-self: start;
  }

  #tab-add-reading tbody tr .reading-col-input {
    grid-area: input;
  }

  #tab-add-reading tbody tr .reading-col-delta {
    grid-area: delta;
    margin-top: 0.1rem;
  }

  /* Hide Delta title label on mobile */
  #tab-add-reading tbody tr .reading-col-delta .mobile-cell-label {
    display: none !important;
  }

  #tab-add-reading tbody tr .cost-column {
    grid-area: cost;
    border-top: 1px solid #f1f5f9;
    padding-top: 0.35rem;
    margin-top: 0.25rem;
  }

  .mobile-cell-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
  }
}
