/* Base layout */
:root {
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1f2933;
  background-color: #f7fafc;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  width: min(960px, 95vw);
  margin: 1.5rem auto 3rem;
  flex: 1;
}

.topbar {
  background: #1f2933;
  color: #fff;
  padding: 1.25rem 5vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.topbar a,
.topbar button.link {
  color: #d1ecff;
  text-decoration: none;
  margin-right: 1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.95rem;
}

.topbar a:hover,
.topbar button.link:hover {
  color: #fff;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  margin-bottom: 1.5rem;
}

.hero-card {
  background: linear-gradient(120deg, #0f172a 0%, #1e293b 60%, #334155 100%);
  color: #f8fafc;
}

.hero-card .muted {
  color: #cbd5f5;
}

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

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.snapshot-head {
  align-items: center;
  flex-wrap: wrap;
}

.snapshot-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.dsr-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-top: 1rem;
}

.custom-range {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 180px;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.button-secondary {
  background: #e2e8f0;
  color: #1f2933;
}

.button-secondary:hover {
  background: #cbd5e1;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.fuel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.fuel-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid #e2e8f0;
}

.fuel-card h3 {
  margin: 0 0 0.75rem;
}

.fuel-card .stat-grid {
  margin-top: 0;
}

.fuel-card .stat-tile {
  background: #fff;
}

.highlight-card {
  background: linear-gradient(135deg, #eef2ff 0%, #ffffff 60%);
  border: 1px solid #e0e7ff;
}

.card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.clickable-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}

.clickable-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.12);
}

.metric-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: baseline;
}

.stat-sub {
  font-size: 1.6rem;
}

.metric-box {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.55rem 0.85rem;
  min-width: 120px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.fuel-card .metric-box {
  padding: 0.5rem 0.75rem;
  min-width: 110px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.metric-box.wide {
  min-width: 180px;
}

.metric-inline {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.metric-inline .stat {
  margin: 0.25rem 0 0;
}

.metric-box .stat {
  margin-top: 0.35rem;
}

.stat-tile {
  background: #f8fafc;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  border: 1px solid #e2e8f0;
}

.stat-tile h3 {
  margin: 0;
  font-size: 1rem;
}

.stat-tile .stat {
  font-size: 2rem;
  margin: 0.5rem 0 0;
}

.stat-positive {
  color: #047857;
  background: rgba(16, 185, 129, 0.12);
  border-radius: 10px;
  padding: 0.1rem 0.35rem;
}

.stat-negative {
  color: #c53030;
  background: rgba(239, 68, 68, 0.12);
  border-radius: 10px;
  padding: 0.1rem 0.35rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.stat {
  font-size: 2.5rem;
  font-weight: 600;
  margin: 0.25rem 0;
}

.activity {
  list-style: none;
  padding: 0;
  margin: 0;
}

.activity li {
  padding: 0.75rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.activity li:last-child {
  border-bottom: none;
}

.muted {
  color: #64748b;
}

.error {
  color: #c53030;
}

.success {
  color: #047857;
}

.hidden {
  display: none;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

input,
textarea,
button,
select {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

button {
  border: none;
  background: #2563eb;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

th,
td {
  padding: 0.75rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}

tbody tr:hover {
  background: #f8fafc;
}

/* DSR layout */
.dsr-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.dsr-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.dsr-card-head h2 {
  margin: 0;
  font-size: 1.35rem;
}

.dsr-card-head p {
  margin: 0.35rem 0 0;
  max-width: 32rem;
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.dsr-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

.dsr-table th,
.dsr-table td {
  border: 1px solid #e2e8f0;
  padding: 0.65rem 0.55rem;
  text-align: center;
  font-size: 0.85rem;
  background: #fff;
}

.dsr-table thead th {
  background: #f1f5f9;
  color: #1f2933;
  font-weight: 600;
}

.dsr-table thead tr:first-child th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.dsr-table thead tr:nth-child(2) th {
  font-size: 0.75rem;
  font-weight: 600;
}

.dsr-table input {
  width: 100%;
  box-sizing: border-box;
  border-radius: 6px;
}

.dsr-table input[type="date"] {
  min-width: 140px;
}

.dsr-table input[type="number"] {
  text-align: right;
}

.dsr-table input[type="text"] {
  text-align: right;
}

.dsr-table .meter-reading {
  font-variant-numeric: tabular-nums;
}

.dsr-table .calc-field[readonly] {
  background: #f8fafc;
  color: #475569;
}

.meter-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.meter-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.meter-title {
  margin: 0;
  font-size: 1rem;
  color: #1f2933;
}

.sheet-remarks label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.sheet-remarks textarea {
  width: 100%;
  resize: vertical;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.sheet-actions button {
  flex-shrink: 0;
}

.sheet-actions p {
  margin: 0;
}

.dsr-history h3 {
  margin: 0;
  font-size: 1.05rem;
}

.dsr-history .table-scroll {
  margin-top: 0.75rem;
}

.meter-table,
.meter-history {
  min-width: 0;
}

.meter-table {
  table-layout: fixed;
}

.meter-table th,
.meter-table td {
  padding: 0.45rem 0.35rem;
  font-size: 0.72rem;
}

.meter-table.compact input {
  width: 15ch;
  max-width: 100%;
}

.meter-table.compact input[type="date"] {
  width: 100%;
  min-width: 160px;
}

.meter-table input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.meter-table input[type="number"]::-webkit-outer-spin-button,
.meter-table input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stock-table,
.stock-history {
  min-width: 880px;
}

@media (max-width: 768px) {
  .dsr-table {
    min-width: 880px;
  }

  .dsr-table th,
  .dsr-table td {
    font-size: 0.78rem;
    padding: 0.55rem 0.45rem;
  }
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: #94a3b8;
  font-size: 0.85rem;
}

/* Login page tweaks */
.login-page {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #e2e8f0;
}

.login-page .card {
  width: min(360px, 92vw);
  text-align: center;
}

.login-page input,
.login-page button {
  width: 100%;
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  main {
    margin-top: 1rem;
  }
}
