:root {
  /* Light Theme (default) */
  --color-primary: #29235c;
  --color-primary-hover: #1e1a42;
  --color-secondary: #b11622;
  --color-secondary-hover: #8a101a;
  --color-background: #ffffff;
  --color-surface: #e9ecef;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-border: #dee2e6;
  --color-input-bg: #ffffff;
  --color-ring: rgba(41, 35, 92, 0.125);
}

[data-theme="dark"] {
  --color-primary: #5c5faa;
  --color-primary-hover: #7d80c9;
  --color-secondary: #d44a5c;
  --color-secondary-hover: #e06a7d;
  --color-background: #121212;
  --color-surface: #1e1e1e;
  --color-text: #e0e0e0;
  --color-text-muted: #9ca3af;
  --color-border: #374151;
  --color-input-bg: #2a2a2a;
  --color-ring: rgba(92, 95, 170, 0.25);
}

/* Base styles */
body {
  min-height: 100vh;
  background-color: var(--color-background);
  color: var(--color-text);
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

header > nav > ul {
  font-size: 16px;
}

header > nav > ul > li {
  padding: 0px 2.5px;
}

body > main {
  padding-left: 40px;
  padding-right: 40px;
}

main article:first-child {
  margin-top: 0;
}

.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.headings h2 {
  margin: 0;
}

/* Navigation */
nav {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.logo-link {
  margin: 0;
  padding: 0;
}

.logo-link:focus {
  background-color: inherit;
}

nav h4 {
  margin: 0;
}

nav ul li a {
  color: var(--color-text);
  transition: all 0.2s ease;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin: 0 2px;
}

nav ul li a:hover {
  color: var(--color-primary);
  background-color: var(--color-border);
}

nav ul li a.nav-link.active {
  color: var(--color-primary);
  background-color: var(--color-primary);
  color: #ffffff;
}

nav ul li a.nav-link:hover {
  color: #ffffff;
  background-color: var(--color-primary-hover);
}

/* Theme toggle button */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text);
  font-size: 1.2rem;
  padding: 0;
  margin-left: 0.5rem;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
}

/* Buttons with role="button" - PRIMARY */
a[role="button"],
button[type="submit"]:not(.secondary):not(.contrast),
button[role="button"]:not(.secondary):not(.contrast) {
  background-color: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
  font-weight: 500;
  transition: all 0.2s ease;
  padding: 0.5rem 0.75rem;
}

a[role="button"]:hover,
button[type="submit"]:not(.secondary):not(.contrast):hover,
button[role="button"]:not(.secondary):not(.contrast):hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: #ffffff;
}

/* Secondary buttons */
a[role="button"].secondary,
button[type="submit"].secondary,
button[role="button"].secondary {
  background-color: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

a[role="button"].secondary:hover,
button[type="submit"].secondary:hover,
button[role="button"].secondary:hover {
  background-color: var(--color-primary);
  color: #ffffff;
}

/* Contrast/Danger buttons */
a[role="button"].contrast,
a[role="button"].secondary.outline:hover,
button.contrast,
button.secondary.outline:hover {
  background-color: var(--color-secondary);
  color: #ffffff;
  border-color: var(--color-secondary);
}

a[role="button"].contrast:hover,
button.contrast:hover,
button.secondary.outline:hover {
  background-color: var(--color-secondary-hover);
  border-color: var(--color-secondary-hover);
  color: #ffffff;
}

/* Delete buttons */
button[hx-delete] {
  background-color: transparent;
  color: var(--color-secondary);
  border-color: var(--color-secondary);
}

button[hx-delete]:hover {
  background-color: var(--color-secondary);
  color: #ffffff;
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  margin: 0;
  width: 36px;
  height: 36px;
}

.icon-btn svg {
  display: block;
}

/* Action buttons column */
.action-buttons {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

/* Status badges */
mark,
ins,
del {
  display: inline-block;
  animation: fadeIn 0.1s ease-in-out;
  font-size: small;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

mark {
  background-color: #ffc107;
  color: #000000;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

ins {
  background-color: var(--color-primary);
  color: #ffffff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

del {
  background-color: var(--color-secondary);
  color: #ffffff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

/* Table styling */
table thead th a,
table thead th a:link,
table thead th a:visited {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

table thead th a:hover {
  color: var(--color-primary);
}

table thead th {
  white-space: nowrap;
}

table {
  background-color: var(--color-surface);
  border-radius: 8px;
  overflow: hidden;
}

table thead {
  background-color: var(--color-primary);
  color: #ffffff;
}

table thead th {
  color: #ffffff;
  font-weight: 600;
}

table thead th a,
table thead th a:link,
table thead th a:visited {
  color: #ffffff;
}

table thead th a:hover {
  color: #e0e0e0;
}

table tbody tr {
  border-bottom: 1px solid var(--color-border);
}

table tbody tr:last-child {
  border-bottom: none;
}

table tbody tr:nth-child(odd) {
  background-color: var(--color-surface);
}

table tbody tr:hover {
  background-color: var(--color-input-bg);
}

table tbody td {
  min-height: 60px;
  vertical-align: middle;
  border-bottom: none;
  padding-top: 5px;
  padding-bottom: 5px;
  padding-left: 10px;
  padding-right: 10px;
}

/* Form elements */
input,
select,
textarea {
  background-color: var(--color-input-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-ring);
}

input::placeholder {
  color: var(--color-text-muted);
}

label {
  color: var(--color-text);
}

/* Cards/Articles */
article {
  margin-top: 40px;
  margin-bottom: 40px;
}

article > header {
  margin-bottom: 1.5rem;
  padding-top: 30px;
  padding-bottom: 30px;
}

/* Checkbox styling */
input[type="checkbox"] {
  accent-color: var(--color-primary);
}

input[type="checkbox"]:checked {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}

/* Checkbox/fieldset styling */
fieldset {
  margin-bottom: 1rem;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  cursor: pointer;
  color: var(--color-text);
}

.checkbox-group input[type="checkbox"] {
  margin: 0;
  width: auto;
}

fieldset {
  margin-bottom: 1rem;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  margin: 0;
  width: auto;
}

/* Time validation */
#time-validation small {
  display: block;
  margin-top: 0.25rem;
}

/* Textarea */
textarea {
  min-height: 80px;
  resize: vertical;
}

/* Form spacing */
form {
  margin-top: 0;
}

/* Print styles */
@media print {
  [data-theme="dark"] {
    --color-background: #ffffff;
    --color-text: #000000;
    --color-surface: #ffffff;
  }
}

/* Password Toggle */
.password-wrapper {
  position: relative;
  display: block; /* Ensure it takes full width if needed, or matches label behavior */
}

.password-wrapper input {
  padding-right: 40px; /* Make space for the icon */
}

.password-toggle {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-80%);
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  height: auto;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-toggle:hover,
.password-toggle:focus {
  background: transparent;
  border: none;
  color: var(--color-primary);
}

.password-toggle svg {
  width: 30px;
  height: 30px;
}

.modal-container {
  background-color: var(--color-surface);
}

/* Calendar Styles */
.week-time-grid,
.day-zone-grid {
  display: grid;
  grid-template-columns: repeat(8, 134px);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}

.day-zone-grid {
  grid-template-columns: auto repeat(var(--zone-columns, 1), 1fr);
}

.time-header {
  display: contents;
}

.time-header .time-label {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.day-header {
  background: var(--color-surface);
  padding: 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--color-border);
  border-left: 1px solid var(--color-border);
  font-weight: bold;
}

.day-header:first-child {
  border-left: none;
}

.day-name {
  font-size: 0.9em;
  color: var(--color-text-muted);
}

.day-date {
  font-size: 1.2em;
  color: var(--color-text);
}

.day-header-row {
  margin-bottom: 0.5rem;
}

.time-row {
  display: contents;
}

.time-label {
  background: var(--color-surface);
  padding: 0.5rem;
  text-align: right;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9em;
  color: var(--color-text-muted);
  font-weight: 500;
}

.time-cell {
  padding: 0.25rem;
  border-bottom: 1px solid var(--color-border);
  border-left: 1px solid var(--color-border);
  position: relative;
}

.time-cell:first-child {
  border-left: none;
}

.order-in-cell {
  font-size: 0.75em;
  padding: 0.25rem;
  margin: 0.1rem 0;
  border-radius: 3px;
  border-left: 3px solid var(--color-primary);
  background: rgba(41, 35, 92, 0.1);
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.order-in-cell.pending {
  border-left-color: #ffc107;
  background: rgba(255, 193, 7, 0.1);
}

.order-in-cell.done {
  border-left-color: var(--color-primary);
  background: rgba(41, 35, 92, 0.1);
}

.order-in-cell.canceled {
  border-left-color: var(--color-secondary);
  background: rgba(183, 22, 34, 0.1);
}

.month-grid {
  display: grid;
  grid-template-rows: auto repeat(auto-fit, 1fr);
  gap: 0;
}

.month-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-weight: bold;
  text-align: center;
  padding: 0.5rem 0;
}

.month-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.month-day {
  min-height: 120px;
  border: 1px solid var(--color-border);
  position: relative;
}

.month-week:nth-child(2) .month-day:first-child {
  border-radius: 0.25rem 0 0 0;
}

.month-week:nth-child(2) .month-day:last-child {
  border-radius: 0 0.25rem 0 0;
}

.month-week:last-of-type .month-day:first-child {
  border-radius: 0 0 0 0.25rem;
}

.month-week:last-of-type .month-day:last-child {
  border-radius: 0 0 0.25rem 0;
}

.month-day.other-month {
  background: var(--color-surface);
  color: var(--color-text-muted);
}

.month-day.has-orders {
  background: rgba(41, 35, 92, 0.1);
}

.day-number {
  font-size: 16px;
  font-weight: bold;
  margin-left: 0.25rem;
  margin-bottom: 0.25rem;
}

.day-orders-preview {
  font-size: 0.8em;
}

.order-preview {
  padding: 0.1rem 0.25rem;
  margin: 0.1rem 0;
  border-radius: 2px;
  font-size: 0.7em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-preview.pending {
  background: #ffc107;
  color: #000;
}

.order-preview.done {
  background: var(--color-primary);
  color: white;
}

.order-preview.canceled {
  background: var(--color-secondary);
  color: white;
}

.more-orders {
  font-size: 0.7em;
  color: var(--color-text-muted);
  font-style: italic;
}

.order-item.pending {
  border-left-color: #ffc107;
  background: rgba(255, 193, 7, 0.1);
}

.order-item.done {
  border-left-color: var(--color-primary);
  background: rgba(41, 35, 92, 0.1);
}

.order-item.canceled {
  border-left-color: var(--color-secondary);
  background: rgba(183, 22, 34, 0.1);
}

/* Week Grid */
.week-grid {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}

.week-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.week-day-header {
  padding: 0.5rem;
  text-align: center;
  font-weight: bold;
  font-size: 0.9em;
}

.week-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.week-day-cell {
  padding: 0.25rem;
  border-left: 1px solid var(--color-border);
  min-height: 120px;
}

.week-day-cell:first-child {
  border-left: none;
}

/* Stats Charts */
.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.stats-header p {
  margin: 0;
}

.stats-range-buttons {
  display: flex;
  gap: 0.5rem;
}

.stats-range-btn {
  color: var(--color-text);
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--color-border);
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.2s ease;
}

.stats-range-btn:hover {
  background: var(--color-surface);
}

.stats-range-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stats-chart-container {
  background: var(--color-surface);
  border-radius: 8px;
  padding: 1rem;
  min-height: 350px;
}

.stats-chart-full {
  width: 100%;
}

.stats-loading {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-muted);
}

.stats-error {
  text-align: center;
  padding: 2rem;
  color: var(--color-secondary);
}

.stats-empty {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-muted);
  font-style: italic;
}

@media (max-width: 600px) {
  .stats-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }

  .stats-range-buttons {
    flex-wrap: wrap;
  }

  .stats-chart-container {
    min-height: 280px;
  }
}
