:root {
  --bg: #f5f7fb;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --border: #000000;
  --muted: #6b7280;
  --turkos: #c5e4e6;
  --blue-soft: #8ecae6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-touch-callout: none; /* Tar bort long-press meny på iOS */
  -webkit-user-select: none;   /* Safari */
  -moz-user-select: none;      /* Firefox */
  -ms-user-select: none;       /* IE/Edge */
  user-select: none;           /* Standard */
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: "Nunito", "Quicksand", "Trebuchet MS", sans-serif;
  background: var(--bg);
  color: #111827;
  display: flex;
  justify-content: center;
  padding: 24px 12px;
}

.layout {
  display: flex;
  align-items: flex-start;
  gap: 32px;
}

.wrapper {
  width: 100%;
  max-width: 550px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
}

.subtext {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 4px;
}

.date-fixed {
  position: fixed;
  top: 16px;
  right: 16px;
  font-size: 1.6rem;
  font-weight: 700;
  font-family: "Nunito", "Quicksand", "Trebuchet MS", sans-serif;
  color: #111827;
  z-index: 999;
  user-select: none;
  padding: 0;
  background: none !important;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

thead {
  background: #f9fafb;
}

th, td {
  padding: 8px 10px;
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

th {
  text-align: left;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

td.time-cell {
  width: 120px;
}

td.activity-cell {
  cursor: pointer;
  position: relative;
  height: 134px;
  padding: 6px 8px;
  -webkit-touch-callout: none; /* Safari */
  -webkit-user-select: none;   /* Chrome/Safari */
  -ms-touch-action: manipulation; /* Windows touch */
  touch-action: manipulation;
}

td.activity-cell.empty {
  background: #f9fafb;
}

td.activity-cell.empty::before {
  content: "Klicka för att välja kort";
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.add-row-btn {
  display: block;
  margin: 0 auto;
  margin-top: 10px;
  text-align: center;
}

/* MENU */
#menuButtons {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#menuButtons button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ==== KLOCK-KORT (tids-kolumnen) ==== */
.time-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 2px solid var(--border);
  background: var(--blue-soft);
  padding: 4px;
  border-radius: 6px;
  max-width: 110px;
  margin-inline: auto;
  cursor: pointer;
}

.time-card-inner {
  background: #ffffff;
  border-radius: 4px;
  /* border: 1px solid var(--border); */
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clock {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 4px solid #ff5b00;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #ffffff;
}

.clock::before {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  background: #000;
  border-radius: 50%;
  z-index: 3;
}

.hand {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform-origin: bottom center;
  transform: translateX(-50%) rotate(0deg);
  border-radius: 999px;
}

.hand.hour {
  width: 6px;
  height: 20px;
  background: #ff5b00; /* orange */
  z-index: 2;
}

.hand.minute {
  width: 4px;
  height: 25px;
  background: #384454; /* mörkblå */
  z-index: 1;
}

.time-text {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 2px;
}


/* drag handle */
.drag-header {
  width: 30px;
}

.drag-cell {
  width: 30px;
  text-align: center;
}

.drag-handle {
  display: inline-block;
  font-size: 1.2rem;
  line-height: 1;
  cursor: grab;
  user-select: none;
  opacity: 0;              /* gömd som standard */
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* visa bara ikonen när man hovrar över raden */
tbody tr:hover .drag-handle {
  opacity: 1;
  pointer-events: auto;
}

.drag-handle:active {
  cursor: grabbing;
}

/*
@media (min-device-width: 768px) and (max-device-width: 1024px) {
  .drag-handle {
    opacity: 1;
    pointer-events: auto;
  }
}
*/

/* ==== ÄMNES-KORT (aktivitet) ==== */

.activity-card {
  width: 100%;
  height: 100%;
  border: 2px solid var(--border);
  background: var(--blue-soft);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  align-items: stretch;
}

.activity-inner {
  background: #ffffff;
  border-radius: 4px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  gap: 10px;
}

.activity-title {
  font-size: 1.8rem;
  font-weight: 600;
}

.activity-image-wrapper {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.activity-image-wrapper img {
  max-height: 80px;
  max-width: 120px;
  object-fit: contain;
}

.activity-cell.done .activity-card {
  opacity: 0.4;
  filter: grayscale(0.6);
}

/*
.activity-cell.done::after {
  content: "✔ Klart";
  position: absolute;
  right: 10px;
  bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #16a34a;
}
*/

.comment-label {
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#activityComment {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d4d4d8;
  font-size: 0.9rem;
}

.activity-title-box {
  display: flex;
  flex-direction: column;
}

/* ==== Modal / välj kort ==== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: #fff;
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  padding: 18px 18px 16px;
  border-radius: 16px;
  box-shadow: 0 15px 35px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.close-modal {
  border: none;
  background: transparent;
  cursor: pointer;
  line-height: 1;
  padding: 0 10px;
  color: var(--muted);
}

#cardSearch {
  width: 100%;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid #d4d4d8;
  font-size: 0.9rem;
  outline: none;
}

#cardSearch:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

#cardList {
  overflow-y: auto;
  padding-right: 4px;
  margin-right: -4px;
  flex: 1;
  min-height: 120px;
}

.card-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border-radius: 12px;
  border: 1px solid #d4d4d8;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.card-option img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
  background: #f9fafb;
  padding: 4px;
}

.card-option span {
  font-weight: 500;
}

.card-option small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.card-option:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

button {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #e5e7eb;
  color: #111827;
}

button.primary {
  background: var(--primary);
  color: #fff;
}

button.danger {
  background: #fee2e2;
  color: #b91c1c;
}

button:hover {
  filter: brightness(0.96);
}

.done-toggle {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

/* custom card modal */
.custom-card-content {
  max-width: 400px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.close-custom-card-modal {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
}

#customCardTitle {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d4d4d8;
  font-size: 0.9rem;
}

#saveCustomCard {
  margin-top: 12px;
  width: auto !important;
  display: inline-block !important;
  margin-left: auto;
}

#openCustomCardModal {
  margin-right: auto;
}

/* share modal */
.share-modal-content {
  max-width: 480px;
  position: relative;
  overflow-y: auto;
}

.close-share-modal {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: transparent;
  font-size: 1.6rem;
  cursor: pointer;
}

.share-label {
  display: block;
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: #4b5563;
}

.share-link-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#shareLinkInput {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #d4d4d8;
  font-size: 0.9rem;
}

#copyShareLink {
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  background: #6366f1;
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
}

#copyShareLink:hover {
  background: #4f46e5;
}

#qrCodeContainer {
  margin: 12px auto 20px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.share-hint {
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 4px;
}

/* TIME TIMER */
/* Knapp */
.open-timer-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #f97316;
  color: white;
  border: none;
  border-radius: 50px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  z-index: 900;
}

.open-timer-btn:hover {
  background: #fb923c;
}

/* Timer */
#timerWrapper {
  text-align: center;
  font-family: sans-serif;
  margin: 10px auto 0 auto;
}

#timerCircle {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto 16px auto;
}

#timerCircle svg {
  width: 100%;
  height: 100%;
}

.timer-bg {
  fill: none;
  stroke: #e5e7eb;
  stroke-width: 10;
}

.timer-fill {
  fill: none;
  stroke: #ef4444;
  stroke-width: 10;
  stroke-linecap: butt; /* round */
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.2s linear;

  /* 👇 Starta vid kl 12 och gå MEDURS */
  transform: rotate(-90deg) scaleY(-1);
  transform-origin: 50% 50%;
}

#timerText {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  font-weight: bold;
}

#timerControls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

#timerControls button {
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: #6366f1;
  color: white;
  cursor: pointer;
}

#timerControls button:hover {
  background: #4f46e5;
}

#timerMinutes {
  width: 60px;
  padding: 4px;
  font-size: 1rem;
  border-radius: 6px;
  border: 1px solid #d4d4d8;
}

/* Modal */
.timer-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.50);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.timer-modal.open {
  display: flex;
}

.timer-modal-content {
  background: white;
  padding: 20px;
  border-radius: 16px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  position: relative;
  animation: popupScale 0.25s ease-out;
}

@keyframes popupScale {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.close-timer {
  position: absolute;
  top: 10px;
  right: 14px;
  cursor: pointer;
}

/* Info modal */
/* Liten "i"-knapp uppe på sidan */
.info-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: #e5e7eb;
  color: #111827;
  font-weight: 600;
  font-family: 'Quicksand', system-ui, sans-serif;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 950;
}

.info-btn:hover {
  background: #d1d5db;
}

.info-btn img {
  text-align: center;
  width: 24px;
  height: 24px;
  vertical-align: middle;
  opacity: 0.8;
}

.info-modal-content {
  max-width: 520px;
  position: relative;
  overflow-x: scroll;
}

.info-modal-content h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-family: 'Nunito', system-ui, sans-serif;
}

.info-modal-content h3 {
  margin-top: 16px;
  margin-bottom: 6px;
  font-size: 1rem;
}

.info-list {
  padding-left: 18px;
  margin: 0;
  font-size: 0.95rem;
}

.info-list li {
  margin-bottom: 4px;
}

.info-list em {
  font-style: italic;
}

.close-info-modal {
  position: absolute;
  top: 10px;
  right: 14px;
  cursor: pointer;
  font-size: 1.6rem;
}

.version-text {
  margin-top: 8px;
  font-size: 0.85rem;
  color: #6b7280;
}

.donate-box {
  margin-top: 0;
  text-align: center;
}

.donate-btn {
  display: inline-block;
  background: #FCDC5F;
  color: #1f2937;
  padding: 10px 18px;
  font-size: 0.95rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.2s ease, transform 0.1s ease;
}

.donate-btn:hover {
  background: #FBD332;
  transform: translateY(-1px);
}


/*
@media (max-width: 640px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }
  .wrapper {
    padding: 16px 14px 20px;
  }
  td.activity-cell {
    height: 88px;
  }
}
*/

@media (max-width: 600px) {
  .date-fixed {
    position: static;
    margin: 0 auto 0 auto;
    display: block;
    text-align: center;
    font-size: 1rem !important;
  }

  table {
    font-size: 0.9rem;
  }

  th, td {
    padding: 6px;
  }

  /* Tidscellen */
  td.time-cell {
    width: 80px;
  }

  .time-card {
    max-width: 60px;
    padding: 3px;
  }

  .clock {
    width: 35px;
    height: 35px;
    border-width: 2px;
  }

  .hand.hour { height: 14px; width: 4px;}
  .hand.minute { height: 18px; width: 2px; }

  .time-text {
    font-size: 0.9rem;
  }

  /* Aktivitetscellen */
  td.activity-cell {
    height: 90px;
  }

  .activity-card {
    border-width: 2px;
    padding: 4px;
  }

  .activity-inner {
    padding: 4px 6px;
  }

  .activity-title {
    font-size: 1rem;
  }

  .activity-comment {
    font-size: 0.75rem;
  }

  .activity-image-wrapper img {
    max-height: 50px;
    max-width: 80px;
  }

  /* Lägg till rad-knappen */
  .add-row-btn {
    font-size: 0.85rem;
    padding: 6px 12px;
    margin-top: 12px;
  }

  /* Modal */
  .modal-content {
    max-width: 90%;
    padding: 14px;
    border-radius: 12px;
  }

  #cardSearch {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .card-option {
    padding: 6px;
  }

  .card-option img {
    width: 42px;
    height: 42px;
  }

  /* Kommentar-input */
  #activityComment {
    padding: 6px 8px;
    font-size: 0.85rem;
  }

  /* #menuButtons {
    display: none;
  } */

  #menuButtons {
    top: inherit;
    bottom: 10px;
    left: 5px;
  }

  #menuButtons button {
    width: 35px;
    height: 35px;
    padding: 0;
    border-radius: 999px;
    justify-content: center;
  }

  #menuButtons button span {
    display: none;
  }
}

/* iPad Portrait Mode */
@media (max-width: 900px) and (orientation: portrait) {
  .date-fixed {
    position: static;
    margin: 0 auto 10px auto;
    display: block;
    text-align: center;
    font-size: 1.4rem;
  }

  /* Flytta in datumet i layoutflödet */
  body {
    display: block; /* så fixed-elementet inte stör layouten */
  }

  /* Se till att wrapper kommer under datumet */
  .layout,
  .wrapper {
    margin-top: 0;
    margin: 0 auto;
  }

  .modal-content {
    max-height: 55vh;
  }
}
/* iPad liggande */
@media (max-width: 1100px) and (orientation: landscape) {
  .date-fixed {
    font-size: 1.4rem;
  }
}

/* Skriv ut */
@media print {
  /* göm allt onödigt */
  #timerWrapper,
  #menuButtons,
  .add-row-btn,
  .drag-handle,
  .activity-cell.done::after,
  .modal {
    display: none !important;
  }

  body {
    background: none;
    margin: 0;
    padding: 20px;
  }

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

  .time-card,
  .activity-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
  }
}
