:root {
  --caffeine-limit: 400;
  --card-bg: rgba(34, 34, 34, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --accent: #2ea461;
  --accent-strong: #37ff8b;
  --text-muted: rgba(255, 255, 255, 0.65);
}

main.caffeine-content {
  display: grid;
  gap: 2rem;
  padding: 3rem 2rem 4rem;
  max-width: 1000px;
  margin: 0 auto;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 2.2rem;
  backdrop-filter: blur(10px);
}

.summary-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.summary-metric {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.summary-label {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.summary-value {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 700;
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}

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

.summary-header h2 {
  margin: 0;
  border: none;
}

.summary-limit {
  margin: 0;
  color: var(--text-muted);
}

.progress {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  transition: width 0.4s ease, background 0.4s ease;
}

.status-message {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.status-message.warning {
  color: #ffc857;
}

.status-message.alert {
  color: #ff6b6b;
}

.status-message.secondary {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
  margin-top: -0.25rem;
}

.entry-card h2,
.history-card h2 {
  margin-top: 0;
  border: none;
}

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

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-weight: 600;
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="number"],
input[type="time"],
input[type="date"] {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: #ffffff;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input:focus {
  outline: none;
  border-color: rgba(55, 255, 139, 0.7);
  box-shadow: 0 0 0 3px rgba(55, 255, 139, 0.2);
}

.submit-button {
  align-self: flex-start;
}

.form-error {
  margin: 0;
  color: #ff6b6b;
  font-size: 0.9rem;
  min-height: 1.2rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent-strong);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  transition: background 0.2s ease, color 0.2s ease;
}

.link-button:hover,
.link-button:focus {
  background: rgba(55, 255, 139, 0.15);
  color: #ffffff;
}

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

.history-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  color: var(--text-muted);
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  padding: 0.85rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

th {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.empty-state td {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}

.delete-button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.7);
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  transition: border 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.delete-button:hover,
.delete-button:focus {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.6);
  transform: translateY(-1px);
}

.caffeine-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  padding: 1.5rem 2rem 0;
}

@media (max-width: 768px) {
  main.caffeine-content {
    padding: 2.5rem 1.25rem 3rem;
  }

  .card {
    padding: 1.8rem;
  }

  .summary-metrics {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .history-totals {
    flex-direction: column;
    gap: 0.75rem;
  }
}

@media (max-width: 480px) {
  header {
    padding: 2.2rem 1.2rem;
  }

  .card {
    padding: 1.4rem;
  }

  .summary-header {
    flex-direction: column;
    align-items: flex-start;
  }

}

@media (max-width: 600px) {
  main.caffeine-content {
    padding: 2rem 1rem 3rem;
  }

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

  .caffeine-nav {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 1rem 0;
  }

  .caffeine-nav .nav-button {
    width: 100%;
    text-align: center;
  }

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

  .table-wrapper {
    overflow: visible;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tbody tr {
    display: block;
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.25);
  }

  .responsive-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .responsive-table tbody tr td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 0;
    border-bottom: none;
  }

  .responsive-table tbody tr td::before {
    content: attr(data-label);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    color: var(--text-muted);
  }

  .responsive-table tbody tr td[data-label="Actions"] {
    justify-content: flex-start;
  }

  .responsive-table tbody tr td[data-label="Actions"] .delete-button {
    width: 100%;
    text-align: center;
  }

  .responsive-table tbody tr td[data-label="Active (mg)"] {
    align-items: center;
  }

  .responsive-table tbody tr td:last-child {
    padding-bottom: 0;
  }

  .responsive-table tbody tr td:first-child {
    padding-top: 0;
  }

  .responsive-table .empty-state {
    display: block;
    padding: 0;
    background: none;
    border: none;
  }

  .responsive-table .empty-state td {
    display: block;
    padding: 1rem 0;
  }
}
