/* ── CSS Custom Properties ──────────────────────────────────────────────── */
:root {
  --color-primary: #2d7d46;
  --color-primary-dark: #1f5c33;
  --color-danger: #c0392b;
  --color-warning: #e67e22;
  --color-muted: #6b7280;
  --color-text: #1f2937;
  --bg-page: #f3f4f6;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border: #d1d5db;
  --border-light: #e5e7eb;
  --radius: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
}

/* ── Dark mode ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --color-primary: #4caf50;
  --color-primary-dark: #388e3c;
  --color-danger: #ef5350;
  --color-muted: #9e9e9e;
  --color-text: #e0e0e0;
  --bg-page: #121212;
  --bg-card: #1e1e1e;
  --bg-input: #2a2a2a;
  --border: #3a3a3a;
  --border-light: #2e2e2e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
}

[data-theme="dark"] .btn-ghost {
  border-color: #5a5a5a;
  color: #b0b0b0;
}
[data-theme="dark"] .btn-ghost:hover {
  background: #2a2a2a;
  color: var(--color-text);
  border-color: #7a7a7a;
}

[data-theme="dark"] dialog {
  background: var(--bg-card);
  color: var(--color-text);
}
[data-theme="dark"] dialog::backdrop {
  background: rgba(0,0,0,0.65);
}
[data-theme="dark"] .topnav {
  background: #1b4d2a;
}
[data-theme="dark"] .dropdown-menu {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--color-text);
}
[data-theme="dark"] .dropdown-menu button {
  color: var(--color-text);
}
[data-theme="dark"] .dropdown-menu button:hover {
  background: var(--bg-page);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--bg-page);
}

/* ── Top Nav ─────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  background: var(--color-primary);
  color: #fff;
  padding: 0 1.25rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topnav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.topnav-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1.5px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }

/* In nav, invert primary */
.topnav .btn-primary { background: #fff; color: var(--color-primary); }
.topnav .btn-primary:hover { background: #e8f5e9; }

.btn-secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }
.btn-secondary:hover { background: rgba(255,255,255,0.1); }

/* Off-nav secondary */
.report-controls .btn-secondary,
.modal-footer .btn-secondary,
.controls-actions .btn-secondary {
  background: transparent; color: var(--color-text); border-color: var(--border);
}
.report-controls .btn-secondary:hover,
.modal-footer .btn-secondary:hover,
.controls-actions .btn-secondary:hover { background: var(--bg-page); }

.btn-ghost { background: transparent; color: var(--color-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { color: var(--color-text); background: var(--bg-page); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #a93226; }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

.hidden { display: none !important; }

/* ── Dropdown ─────────────────────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: 200;
  overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  text-align: left;
  background: none;
  border: none;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
}
.dropdown-menu button:hover { background: var(--bg-page); }

/* ── Modals / Dialogs ─────────────────────────────────────────────────────── */
dialog {
  border: none;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 0;
  max-width: 95vw;
  /* The CSS reset (* { margin: 0 }) overrides the UA stylesheet's margin: auto
     which is what centres showModal() dialogs. Restore it explicitly here. */
  margin: auto;
}
dialog::backdrop { background: rgba(0,0,0,0.45); }

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.96) translateY(-10px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}
@keyframes backdrop-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
dialog[open] {
  animation: modal-enter 0.24s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
dialog[open]::backdrop {
  animation: backdrop-fade-in 0.22s ease both;
}

/* Do NOT set display on dialog directly — browser controls display:none when closed.
   Use [open] selector so flex only applies when the dialog is actually open. */
.modal    { width: min(520px, 96vw); }
.modal-lg { width: min(560px, 96vw); }
.panel    { width: min(440px, 96vw); }
dialog.panel[open] { display: flex; flex-direction: column; max-height: 85vh; }

.modal-header, .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-card);
  border-radius: 10px 10px 0 0;
}
.modal-header h2, .panel-header h2 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--color-muted);
  padding: 0.2rem;
  line-height: 1;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg-page); color: var(--color-text); }

.modal-body, .panel-body {
  padding: 1.25rem;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: 0 0 10px 10px;
}
.panel-body { border-radius: 0 0 10px 10px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}
.modal-footer-right { display: flex; gap: 0.5rem; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--bg-input);
  color: var(--color-text);
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}
.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}
.inline-form input[type="text"] {
  flex: 1;
  min-width: 120px;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--bg-input);
  color: var(--color-text);
}
.inline-form input[type="text"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* ── Colour swatches ─────────────────────────────────────────────────────── */
.color-pick-group { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.color-pick-group label { font-size: 0.8rem; color: var(--color-muted); }
.color-swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px #1f2937; }
input[type="color"] { width: 32px; height: 28px; padding: 2px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }

/* ── List items in panels ─────────────────────────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}
.list-item:last-child { border-bottom: none; }
.list-item .rep-name-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--bg-input);
  color: var(--color-text);
}
.list-item .rep-name-input:focus {
  outline: none;
  border-color: var(--color-primary);
}
.list-item .rep-colour-picker { width: 32px; height: 30px; flex-shrink: 0; }
.lt-name { flex: 1; }

.badge { font-size: 0.75rem; padding: 0.2rem 0.5rem; border-radius: 20px; }
.badge-builtin { background: #e8f5e9; color: var(--color-primary); border: 1px solid #c8e6c9; }

.empty-msg { color: var(--color-muted); font-style: italic; padding: 0.5rem 0; }

.lt-section-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin: 0.5rem 0 0.25rem;
}

hr { border: none; border-top: 1px solid var(--border-light); margin: 1rem 0; }
h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.75rem; }

/* ── Toast notifications ────────────────────────────────────────────────────── */
#toastContainer {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-md);
  transform: translateX(110%) translateY(6px);
  opacity: 0;
  max-height: 80px;
  overflow: hidden;
  transition: transform 0.38s cubic-bezier(0.34, 1.4, 0.64, 1),
              opacity 0.28s ease;
  pointer-events: auto;
  max-width: 300px;
}
.toast.toast-visible {
  transform: translateX(0) translateY(0);
  opacity: 1;
}
.toast-success { background: #2d7d46; }
.toast-error   { background: var(--color-danger); }
.toast-info    { background: #37474f; }
.toast-warning { background: var(--color-warning); }

/* ── Confirm dialog ─────────────────────────────────────────────────────────── */
.modal-sm { width: 360px; }
#confirmDialog .modal-body { padding: 1.25rem 1.25rem 0; }
#confirmDialog p { font-size: 0.95rem; margin-bottom: 1.25rem; line-height: 1.5; }

/* ── Day-of-week chips (recurring modal) ────────────────────────────────────── */
.day-checkboxes { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.day-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.83rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
}
.day-chip input[type="checkbox"] { display: none; }
.day-chip:has(input:checked) {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.recur-preview {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
}

/* ── Splash screen ─────────────────────────────────────────────────────────── */
#splashScreen {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2rem;
}
#splashScreen.hidden { display: none !important; }

.splash-title {
  color: rgba(255,255,255,0.6);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

/* Bounce loader (from Uiverse.io by mobinkakei) */
.wrapper {
  width: 200px;
  height: 60px;
  position: relative;
  z-index: 1;
}
.circle {
  width: 20px;
  height: 20px;
  position: absolute;
  border-radius: 50%;
  background-color: #fff;
  left: 15%;
  transform-origin: 50%;
  animation: circle7124 .5s alternate infinite ease;
}
@keyframes circle7124 {
  0% {
    top: 60px;
    height: 5px;
    border-radius: 50px 50px 25px 25px;
    transform: scaleX(1.7);
  }
  40% {
    height: 20px;
    border-radius: 50%;
    transform: scaleX(1);
  }
  100% {
    top: 0%;
  }
}
.circle:nth-child(2) {
  left: 45%;
  animation-delay: .2s;
}
.circle:nth-child(3) {
  left: auto;
  right: 15%;
  animation-delay: .3s;
}
.shadow {
  width: 20px;
  height: 4px;
  border-radius: 50%;
  background-color: rgba(0,0,0,0.9);
  position: absolute;
  top: 62px;
  transform-origin: 50%;
  z-index: -1;
  left: 15%;
  filter: blur(1px);
  animation: shadow046 .5s alternate infinite ease;
}
@keyframes shadow046 {
  0% { transform: scaleX(1.5); }
  40% { transform: scaleX(1); opacity: .7; }
  100% { transform: scaleX(.2); opacity: .4; }
}
.shadow:nth-child(4) {
  left: 45%;
  animation-delay: .2s;
}
.shadow:nth-child(5) {
  left: auto;
  right: 15%;
  animation-delay: .3s;
}

/* ── Dark mode toggle (from Uiverse.io by andrew-demchenk0) ──────────────── */
.switch {
  font-size: 17px;
  position: relative;
  display: inline-block;
  width: 64px;
  height: 34px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #73C0FC;
  transition: .4s;
  border-radius: 30px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 30px;
  width: 30px;
  border-radius: 20px;
  left: 2px;
  bottom: 2px;
  z-index: 2;
  background-color: #e8e8e8;
  transition: .4s;
}
.sun svg {
  position: absolute;
  top: 6px;
  left: 36px;
  z-index: 1;
  width: 24px;
  height: 24px;
  animation: rotate 15s linear infinite;
}
.moon svg {
  fill: #73C0FC;
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 1;
  width: 24px;
  height: 24px;
  animation: tilt 5s linear infinite;
}
@keyframes rotate {
  0%   { transform: rotate(0); }
  100% { transform: rotate(360deg); }
}
@keyframes tilt {
  0%   { transform: rotate(0deg); }
  25%  { transform: rotate(-10deg); }
  75%  { transform: rotate(10deg); }
  100% { transform: rotate(0deg); }
}
.input:checked + .slider {
  background-color: #183153;
}
.input:focus + .slider {
  box-shadow: 0 0 1px #183153;
}
.input:checked + .slider:before {
  transform: translateX(30px);
}

/* ── Nav buttons (from Uiverse.io by faizanullah1999) ─────────────────────── */
.primary-button {
  font-family: 'Ropa Sans', sans-serif;
  color: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.05rem;
  border: 1px solid #0E1822;
  padding: 0.55rem 1.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 531.28 200'%3E%3Cdefs%3E%3Cstyle%3E .shape %7B fill: %23FF4655 %7D %3C/style%3E%3C/defs%3E%3Cg id='Layer_2' data-name='Layer 2'%3E%3Cg id='Layer_1-2' data-name='Layer 1'%3E%3Cpolygon class='shape' points='415.81 200 0 200 115.47 0 531.28 0 415.81 200' /%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A");
  background-color: #0E1822;
  background-size: 200%;
  background-position: 200%;
  background-repeat: no-repeat;
  transition: 0.3s ease-in-out;
  transition-property: background-position, border, color;
  position: relative;
  z-index: 1;
  white-space: nowrap;
}
a.primary-button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.primary-button:hover {
  border: 1px solid #FF4655;
  color: white;
  background-position: 40%;
}
.primary-button::before {
  content: "";
  position: absolute;
  background-color: #0E1822;
  width: 0.2rem;
  height: 0.2rem;
  top: -1px;
  left: -1px;
  transition: background-color 0.15s ease-in-out;
}
.primary-button:hover::before { background-color: white; }
.primary-button:hover::after  { background-color: white; }
.primary-button::after {
  content: "";
  position: absolute;
  background-color: #FF4655;
  width: 0.3rem;
  height: 0.3rem;
  bottom: -1px;
  right: -1px;
  transition: background-color 0.15s ease-in-out;
}
.button-borders {
  position: relative;
  width: fit-content;
  height: fit-content;
}
.button-borders::before {
  content: "";
  position: absolute;
  width: calc(100% + 0.5em);
  height: 50%;
  left: -0.3em;
  top: -0.3em;
  border: 1px solid #0E1822;
  border-bottom: 0;
}
.button-borders::after {
  content: "";
  position: absolute;
  width: calc(100% + 0.5em);
  height: 50%;
  left: -0.3em;
  bottom: -0.3em;
  border: 1px solid #0E1822;
  border-top: 0;
  z-index: 0;
}

/* ── Draggable dialog header hint ─────────────────────────────────────────── */
.modal-header, .panel-header { cursor: grab; }
.modal-header:active, .panel-header:active { cursor: grabbing; }
/* Don't show grab cursor on interactive elements inside the header */
.modal-header button,
.panel-header button { cursor: pointer; }

/* ── Mobile responsive ────────────────────────────────────────────────────── */
@media (max-width: 700px) {

  /* Nav: scrollable actions row */
  .topnav { padding: 0 0.75rem; gap: 0.5rem; height: auto; min-height: 52px; flex-wrap: wrap; }
  .topnav-actions {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 0.4rem;
    padding: 0.4rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topnav-actions::-webkit-scrollbar { display: none; }
  /* Shrink nav buttons on mobile */
  .primary-button { font-size: 11px; padding: 0.45rem 0.7rem; letter-spacing: 0; }
  .button-borders::before, .button-borders::after { display: none; }
  /* Hide dark toggle label, keep the toggle itself */
  .switch { width: 46px; height: 26px; font-size: 13px; flex-shrink: 0; }
  .switch .slider:before { width: 22px; height: 22px; }
  .input:checked + .slider:before { transform: translateX(20px); }
  .sun svg, .moon svg { width: 18px; height: 18px; top: 4px; }
  .sun svg { left: 24px; }

  /* No grab cursor on mobile */
  .modal-header, .panel-header { cursor: default; }

  /* Stack form rows vertically */
  .form-row { flex-direction: column; gap: 0; }

  /* Make touch targets larger */
  .btn, .primary-button { min-height: 40px; }
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px; } /* prevent iOS auto-zoom */

  /* Modal body: more scroll room */
  .modal-body, .panel-body { max-height: 70dvh; overflow-y: auto; }

  /* Confirm dialog: also full-width bottom sheet */
  .modal-sm { width: 100% !important; max-width: 100% !important; }
}
