:root {
  --bg: #f7f5fb;
  --card: #ffffff;
  --ink: #232332;
  --muted: #7d7d94;
  --line: #e5e1f0;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(60, 40, 90, 0.10);

  --accent: #cbb6ec;
  --accent-ink: #5b21b6;
  --accent-strong: #6d28d9;

  --soon: #ea580c;
  --soon-bg: #fff1e8;

  --marquee-gradient: linear-gradient(135deg, #8b5cf6, #ea580c);
  --marquee-shadow: 0 4px 14px rgba(234, 88, 12, 0.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 18px;
}
.brand-logo { flex: 0 0 auto; border-radius: 9px; }
.brand-title {
  margin: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 26px;
}
.brand-title-thin { font-weight: 400; color: var(--muted); }
.brand-title-bold {
  font-weight: 800;
  background: var(--marquee-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.header-actions {
  flex: 0 0 auto;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-icon-btn:active { background: var(--accent); }

.header-add-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--marquee-gradient);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--marquee-shadow);
}
.header-add-btn:active { transform: scale(0.92); }

/* Ticket list */
.ticket-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ticket-row-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
}

.ticket-row-delete-bg {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  padding-left: 22px;
  font-weight: 700;
  font-size: 14px;
}

.ticket-row-move-bg {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--accent-strong);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 22px;
  font-weight: 700;
  font-size: 14px;
  /* Fully overlaps .ticket-row-delete-bg (both inset:0) — hidden by
     default and only shown during an active left-drag (see
     wireCardGestures), so only one background ever paints at a time. */
  visibility: hidden;
}

.ticket-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  cursor: pointer;
  touch-action: pan-y;
  will-change: transform;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.ticket-card:active { opacity: 0.75; }

.ticket-card.is-soon {
  border-color: var(--soon);
  background: var(--soon-bg);
}

.ticket-thumb-wrap {
  position: relative;
  flex: 0 0 auto;
}
.ticket-thumb-placeholder {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ticket-thumb-emoji {
  font-size: 26px;
  line-height: 1;
  /* The 🎟️ emoji is a fixed-color glyph — filter is the only way to shift
     its rendered hue toward the app's purple instead of its native
     orange/red, while keeping the exact same ticket artwork used in the
     tab bar. */
  filter: hue-rotate(265deg) saturate(2.5) brightness(0.8);
}
.ticket-thumb-count {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--accent-strong);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  box-shadow: 0 0 0 2px var(--card);
}

.ticket-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ticket-name {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-meta {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-sub {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-reminder {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--soon);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-badge {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
}
.ticket-card.is-soon .ticket-badge {
  color: #fff;
  background: var(--soon);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px 20px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-width: 60px;
  min-height: 40px;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--marquee-gradient); color: #fff; box-shadow: var(--marquee-shadow); }
.btn-ghost { background: transparent; color: var(--muted); }

/* Bottom tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -1px 8px rgba(60, 30, 90, 0.06);
  z-index: 5;
}
.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.tab-icon { font-size: 20px; line-height: 1; filter: grayscale(0.4); opacity: 0.6; }
.tab.is-active { color: var(--accent-strong); }
.tab.is-active .tab-icon { filter: none; opacity: 1; }

/* Modal */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  /* flex + margin:auto on the card (not grid place-items:center) so that
     when the card is taller than the viewport, it degrades to top-aligned
     and scrollable instead of centering and clipping unreachable content
     off both the top and bottom. */
  display: flex;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 10;
  overflow-y: auto;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 20, 45, 0.45);
}
.modal-card {
  position: relative;
  background: var(--card);
  border-radius: 18px;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 40px rgba(45, 20, 60, 0.28);
  margin: auto;
  flex-shrink: 0;
}
.modal-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
  padding-right: 26px;
}

.info-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.info-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.info-label {
  color: var(--muted);
  flex: 0 0 auto;
}
.info-value {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}
.info-link {
  color: var(--accent-strong);
  text-decoration: none;
}
.modal-close-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close-btn:active { background: var(--accent); color: var(--accent-ink); }
.modal-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  margin-top: 14px;
}
.modal-card label:first-of-type { margin-top: 0; }
.modal-card input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--ink);
}
.modal-card input:focus { border-color: var(--accent-strong); }
.modal-card input[type="file"] { padding: 8px 4px; border: none; }
.field-hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.time-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}
.time-picker select {
  flex: 1 1 0;
  min-width: 0;
  padding: 12px 8px;
  font-size: 16px;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--ink);
}
.time-picker select:focus { border-color: var(--accent-strong); }
.time-colon {
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 700;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.file-preview img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}
.file-preview-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-remove-btn {
  flex: 0 0 auto;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.file-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-list .file-preview { margin-top: 0; }
.file-list img,
.file-list .file-list-icon {
  cursor: pointer;
}
.file-list-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.file-list-name { cursor: pointer; }

.link-add-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.link-add-row input { flex: 1 1 auto; }
.link-add-row .btn { flex: 0 0 auto; padding: 0 16px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions-stacked {
  flex-direction: column;
  align-items: stretch;
}
.modal-actions-stacked .btn { width: 100%; }

.modal-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 0;
}

.file-preview-static { margin-top: 12px; }

.btn-ghost-outline {
  background: transparent;
  color: var(--accent-ink);
  border: 1.5px solid var(--accent);
}

/* Family sharing setup */
.family-code-display {
  margin: 6px 0 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1.5px dashed var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: center;
  color: var(--accent-ink);
}

.btn-text-link {
  display: block;
  width: 100%;
  margin: 14px 0 0;
  padding: 4px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  text-align: center;
}

#add-to-calendar-row .btn-text-link {
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 700;
}
.btn-text-link-small {
  margin-top: 6px !important;
  font-size: 12px !important;
  font-weight: 400 !important;
}

/* Ticket picker (attach a shared file to an existing ticket) */
.picker-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.picker-row {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
}
.picker-row:active { opacity: 0.7; }
.picker-row-name { font-size: 15px; font-weight: 600; color: var(--ink); }
.picker-row-date { font-size: 12.5px; color: var(--muted); }

/* Attachment viewer */
.attachment-card {
  position: relative;
  width: 92vw;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.attachment-carousel {
  width: 100%;
  max-height: 88vh;
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  scrollbar-width: none;
}
.attachment-carousel::-webkit-scrollbar { display: none; }
.attachment-slide {
  flex: 0 0 100%;
  min-width: 0;
  scroll-snap-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachment-slide img {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 12px;
  display: block;
  pointer-events: none;
}
.attachment-pdf {
  width: 100%;
  min-height: 280px;
  border-radius: 12px;
  background: #4b4b52;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px;
}
.attachment-pdf-icon {
  font-size: 56px;
  line-height: 1;
}
.attachment-pdf-status {
  color: #fff;
  font-size: 14px;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
}
.attachment-pdf-open-link {
  margin-top: 4px;
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--marquee-gradient);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--marquee-shadow);
}
.attachment-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.attachment-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  transition: background 0.15s ease;
}
.attachment-dot.is-active { background: #fff; }
.attachment-close-btn {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 1;
}

/* Undo bar */
.undo-bar[hidden] { display: none; }
.undo-bar {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 20;
  font-size: 14px;
  max-width: calc(100vw - 32px);
}
#undo-label {
  min-width: 0;
  white-space: normal;
  word-break: break-word;
}
.undo-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
}

/* Schedule-conflict warning (Add/Edit form) */
.conflict-warning {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1.5px solid #e8b4ae;
  background: #fdf1ef;
  color: var(--ink);
  font-size: 13px;
}
.conflict-warning.is-ticketed {
  border-color: var(--danger);
  background: #fbe3e0;
}
.conflict-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--danger);
  font-size: 14px;
}
.conflict-icon { flex: 0 0 auto; }
.conflict-list {
  margin: 8px 0 0;
  padding-left: 34px;
  line-height: 1.4;
}
.ticket-thumb-placeholder { position: relative; }
.conflict-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 15px;
  height: 15px;
}
.conflict-warning.is-soft {
  border-color: #ebd08a;
  background: #fdf6e3;
}
.conflict-warning.is-soft .conflict-head { color: #b7791f; }
