:root {
  /* Dark theme = Standard */
  --color-bg: #10151a;
  --color-card: #1b2229;
  --color-card-alt: #232c34;
  --color-primary: #35d19c;
  --color-primary-dark: #26b586;
  --color-primary-contrast: #08130f;
  --color-accent: #ffb26b;
  --color-danger: #ff6f66;
  --color-text: #eef3f1;
  --color-text-muted: #93a5a8;
  --color-border: #2b343c;
  --color-track: #26303a;
  --color-topbar: #0e2a22;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  --flash-success-bg: rgba(53, 209, 156, 0.16);
  --flash-error-bg: rgba(255, 111, 102, 0.16);
  --radius: 14px;
}

:root[data-theme="light"] {
  --color-bg: #f4f7f6;
  --color-card: #ffffff;
  --color-card-alt: #f7faf9;
  --color-primary: #1f6f5c;
  --color-primary-dark: #16513f;
  --color-primary-contrast: #ffffff;
  --color-accent: #ff9f5a;
  --color-danger: #e2574c;
  --color-text: #22302c;
  --color-text-muted: #6b7d76;
  --color-border: #e2e8e5;
  --color-track: #e6ede9;
  --color-topbar: #1f6f5c;
  --shadow: 0 4px 16px rgba(31, 111, 92, 0.08);
  --flash-success-bg: #e3f5ee;
  --flash-error-bg: #fdeceb;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: var(--color-primary); text-decoration: none; }

h1, h2, h3 { margin: 0 0 8px 0; color: var(--color-text); }

.page-title { font-size: 24px; font-weight: 700; margin: 4px 0 16px 0; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 90px 16px;
}

/* Top bar (desktop / iPad landscape) */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--color-topbar);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 18px; }
.topnav a { color: rgba(255,255,255,0.85); margin-left: 18px; font-size: 14px; }
.topnav a.active, .topnav a:hover { color: #fff; font-weight: 600; }

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px)) 0;
  z-index: 30;
}
.bottomnav a {
  flex: 1;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 11px;
  padding: 6px 0;
}
.bottomnav a .icon { display: block; font-size: 20px; margin-bottom: 2px; }
.bottomnav a.active { color: var(--color-primary); font-weight: 600; }

@media (min-width: 780px) {
  .topbar { display: flex; }
  .bottomnav { display: none; }
  .container { padding-bottom: 40px; }
}

/* Flash messages */
.flash-wrap { margin-bottom: 14px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 14px;
}
.flash-success { background: var(--flash-success-bg); color: var(--color-primary); }
.flash-error { background: var(--flash-error-bg); color: var(--color-danger); }

/* Auth pages */
.auth-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
}
.auth-logo { text-align: center; font-size: 28px; }
.auth-sub { text-align: center; color: var(--color-text-muted); margin-bottom: 20px; font-size: 14px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--color-text-muted); }

/* Forms */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 14px 0 6px 0;
}
input[type="text"], input[type="password"], input[type="date"], input[type="file"], select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--color-card-alt);
  color: var(--color-text);
  -webkit-appearance: none;
}
select { appearance: none; background-image: none; }
input:focus, select:focus { outline: none; border-color: var(--color-primary); }

.date-row { display: flex; }
.date-row > div { flex: 1 1 0; }
.date-row > div:first-child { margin-right: 10px; }

/* Buttons */
.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn-primary { background: var(--color-primary); color: var(--color-primary-contrast); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-card-alt); color: var(--color-primary); border: 1px solid var(--color-border); }
.btn-danger { background: var(--flash-error-bg); color: var(--color-danger); }
.btn-block { width: 100%; margin-top: 20px; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* Section headers */
.section { margin-top: 28px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-head h2 { font-size: 17px; }

.link-more {
  display: inline-block;
  margin: 8px 0 16px 0;
  font-size: 14px;
  font-weight: 600;
}

.empty-hint { color: var(--color-text-muted); font-size: 14px; line-height: 1.5; }

/* Vacation cards */
.card-grid {
  display: flex;
  flex-wrap: wrap;
  margin: -6px;
}
.vac-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 6px;
  flex: 1 1 260px;
  position: relative;
}
.vac-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.vac-card-link:hover {
  text-decoration: none;
  color: inherit;
}
.vac-card-edit {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  text-decoration: none;
  color: var(--color-text-muted);
  transition: background 0.15s ease;
  z-index: 2;
}
.vac-card-edit:hover {
  background: var(--color-border);
  color: var(--color-text);
}
.vac-card-top { display: flex; align-items: center; justify-content: space-between; }
.vac-card-top h3 { font-size: 16px; }
.progress-badge {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.vac-dates { color: var(--color-text-muted); font-size: 13px; margin: 4px 0 10px 0; }
.vac-item-count { color: var(--color-text-muted); font-size: 12px; margin: 8px 0 0 0; }

.progress-bar {
  background: var(--color-track);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.progress-bar-lg { height: 14px; }
.progress-fill {
  background: linear-gradient(90deg, #dc3232 0%, #ff6432 25%, #ffb26b 50%, #9acd32 80%, #35d19c 100%);
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-wrap { margin: 14px 0 18px 0; }
.progress-text {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* Template list */
.tpl-list, .tpl-list-full { margin-top: 4px; }
.tpl-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.tpl-count { color: var(--color-text-muted); font-size: 12px; }

.tpl-item-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.tpl-item-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.tpl-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  margin-bottom: 10px;
}
.tpl-card-link:hover {
  text-decoration: none;
  color: inherit;
}
.tpl-item-top { display: flex; justify-content: space-between; align-items: center; }
.tpl-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.tpl-item-actions > * { margin-right: 0; margin-top: 0; }

/* Item rows in template form */
.item-list-head { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.item-list-head label { margin: 0; }
.item-list-actions { display: flex; gap: 8px; align-items: center; }

/* Mobile portrait: make item-list-head more compact */
@media (max-width: 480px) {
  .item-list-head {
    flex-wrap: wrap;
  }
  .item-list-head label {
    width: 100%;
    margin-bottom: 6px;
  }
  .item-list-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .item-list-actions .btn-sm {
    padding: 6px 10px;
    font-size: 12px;
  }
}
.item-rows { margin-top: 12px; }
.item-row { display: flex; align-items: center; margin-bottom: 8px; }
.item-row input[type="text"] { margin-right: 8px; }
.item-row select.cat-input { max-width: 150px; margin-right: 8px; }
.item-row-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}
.btn-move-sm {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 10px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-move-sm:hover {
  background: var(--color-border);
  color: var(--color-text);
}
.btn-remove-row {
  border: none;
  background: var(--flash-error-bg);
  color: var(--color-danger);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  flex: 0 0 38px;
  cursor: pointer;
}
.drag-handle {
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: grab;
  padding: 0 8px;
  user-select: none;
  flex-shrink: 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
.drag-handle:active {
  cursor: grabbing;
}
.item-row[draggable="true"] {
  cursor: default;
}
.item-row[draggable="true"] .drag-handle {
  cursor: grab;
}
.item-row[draggable="true"] .drag-handle:active {
  cursor: grabbing;
}

/* Template selection checkboxes */
.tpl-select-list { margin-top: 6px; }
.tpl-checkbox {
  display: flex;
  align-items: center;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  font-weight: 400;
  font-size: 14px;
}
.tpl-checkbox input { margin-right: 10px; width: 18px; height: 18px; }

/* Vacation detail */
.vac-header { margin-top: 4px; }

/* Compact action bar for mobile */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 8px 0 12px 0;
}

/* Dropdown menu for actions */
.action-menu-wrapper {
  position: relative;
}

.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  font-size: 16px;
  cursor: pointer;
  color: var(--color-text);
  transition: background 0.15s ease;
  padding: 0;
}

.menu-toggle:hover {
  background: var(--color-border);
}

.action-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 180px;
  z-index: 50;
  margin-top: 4px;
  overflow: hidden;
}

.action-menu.show {
  display: block;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--color-text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease;
}

.menu-item:hover {
  background: var(--color-card-alt);
}

.menu-item-danger {
  color: var(--color-danger);
}

.menu-item-danger:hover {
  background: var(--flash-error-bg);
}
.action-group {
  display: flex;
  align-items: center;
  gap: 2px;
}
.inline-form { display: inline; margin: 0; }

/* Icon-only buttons for compact mobile view */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  color: var(--color-text);
  transition: background 0.15s ease;
  padding: 0;
}
.btn-icon:hover {
  background: var(--color-border);
}
.btn-danger-icon:hover {
  background: var(--flash-error-bg);
  color: var(--color-danger);
}

/* Small icon buttons for template list */
.btn-icon-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--color-text);
  transition: background 0.15s ease;
  padding: 0;
  line-height: 1;
  vertical-align: middle;
}
.btn-icon-sm:hover {
  background: var(--color-border);
}
.tpl-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  cursor: default;
}
.tpl-item-actions > * {
  margin-right: 0;
  margin-top: 0;
}

.quick-add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.quick-add-row .action-menu-wrapper {
  flex-shrink: 0;
}

.quick-add {
  display: flex;
  flex: 1;
  margin-bottom: 0;
}
.quick-add input[type="text"] {
  margin-right: 8px;
  flex: 1;
  min-width: 0;
}
.quick-add select.cat-input { max-width: 120px; margin-right: 8px; flex-shrink: 0; }

/* Filter bar: category dropdown + hide-checked toggle */
.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  gap: 8px;
}
.filter-bar select {
  width: auto;
  min-width: 140px;
  margin-right: 0;
  margin-bottom: 8px;
  padding: 9px 12px;
}
.search-input {
  flex: 1;
  min-width: 120px;
  margin-bottom: 8px;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 14px;
  background: var(--color-card-alt);
  color: var(--color-text);
}
.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
}
#checklistWrap.hide-checked .checklist-item.checked { display: none; }

.checklist-section { margin-bottom: 20px; }
.cat-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.checklist-item label {
  display: flex;
  align-items: center;
  margin: 0;
  font-weight: 400;
  flex: 1;
  cursor: pointer;
}
.checklist-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-right: 12px;
  accent-color: var(--color-primary);
  flex: 0 0 22px;
}
.checklist-item .item-text { font-size: 15px; color: var(--color-text); }
.checklist-item.checked .item-text {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

/* Item action buttons (move up/down, delete) */
.item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 12px;
  flex-shrink: 0;
}
.item-actions-group {
  display: flex;
  align-items: center;
  gap: 1px;
}
.btn-move {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-move:hover {
  background: var(--color-border);
  color: var(--color-text);
}
.btn-delete {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
}
.btn-delete:hover {
  background: var(--flash-error-bg);
  color: var(--color-danger);
}

/* Drag and drop styles */
.checklist-item.dragging {
  opacity: 0.5;
  background: var(--color-border);
}
.checklist-item.drag-over {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}
.checklist-item {
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.checklist-item:active {
  cursor: grabbing;
}

/* Settings page */
.theme-form { display: flex; flex-wrap: wrap; margin-top: 10px; }
.theme-option {
  display: flex;
  align-items: center;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 10px 10px 0;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.theme-option input { margin-right: 10px; width: 18px; height: 18px; accent-color: var(--color-primary); }
.theme-swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  margin-right: 10px;
  border: 1px solid var(--color-border);
}
.theme-swatch-dark { background: linear-gradient(135deg, #10151a 50%, #35d19c 50%); }
.theme-swatch-light { background: linear-gradient(135deg, #f4f7f6 50%, #1f6f5c 50%); }

.category-chip-list { display: flex; flex-wrap: wrap; margin: 10px 0; }
.category-chip {
  display: flex;
  align-items: center;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  margin: 0 8px 8px 0;
  font-size: 13px;
}
.category-chip form { margin-left: 8px; }
.category-chip button {
  border: none;
  background: var(--flash-error-bg);
  color: var(--color-danger);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}

/* Admin users page */
.user-list {
  margin-top: 10px;
}
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.user-name {
  font-weight: 600;
  font-size: 15px;
}
.user-badge {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.user-badge-warning {
  background: var(--color-accent);
  color: #000;
}
.user-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.db-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.db-actions .inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.next-vacation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.next-vacation-text {
  font-size: 14px;
  color: var(--color-text-muted);
}
.next-vacation-text strong {
  color: var(--color-text);
}
.next-vacation-days {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
}

@media (max-width: 480px) {
  .next-vacation-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px 14px;
  }
  .next-vacation-text {
    font-size: 13px;
  }
  .next-vacation-days {
    font-size: 16px;
  }
}
