/* Copyright (c) 2026 mtdrabek (Matúš Drábek) */

/* Colors come from the user's Telegram theme (light, dark, custom) */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --surface: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #7d7d85);
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);
  --line: rgba(128, 128, 128, 0.25);
  --fill: rgba(128, 128, 128, 0.16);
  --r: 14px;
  --pad: 16px;
  --top: calc(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  padding: calc(12px + var(--top)) var(--pad) calc(120px + env(safe-area-inset-bottom, 0px));
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--btn); outline-offset: 2px; }

.screen { max-width: 640px; margin: 0 auto; }
.screen.center { display: grid; place-items: center; min-height: 60vh; }

/* ----- type ----- */
.title { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; margin: 20px 0 6px; }
.sub { margin: 0 0 16px; color: var(--hint); font-size: 15px; }
.head .title { margin-bottom: 2px; }
.head .sub { margin-bottom: 0; }

/* ----- wizard ----- */
.steps { display: flex; gap: 4px; margin-top: 4px; }
.seg { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.seg.on { background: var(--btn); }

.ticket { background: var(--surface); border-radius: var(--r); margin: 16px 0 0; padding: 4px 0; }
.tk-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  width: 100%; padding: 9px var(--pad); background: none; border: 0; text-align: left;
}
.tk-row + .tk-row { border-top: 1px solid var(--line); }
.tk-label { color: var(--hint); font-size: 14px; flex: none; }
.tk-val { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }

.field {
  display: block; width: 100%; padding: 13px var(--pad); border: 0; border-radius: var(--r);
  background: var(--surface); color: var(--text); font: inherit; font-size: 17px; resize: none;
}
.field::placeholder { color: var(--hint); }
.field:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--btn); }
.field + .group, .field + .chips { margin-top: 14px; }
.field-error { color: var(--danger); font-size: 14px; margin: 8px 4px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }

/* ----- grouped lists (people, chats) ----- */
.group { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--r); overflow: hidden; }
.group li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px var(--pad); background: none; border: 0; text-align: left;
}
.row:active { background: var(--fill); }
.row-text { flex: 1; min-width: 0; }
.row-title { display: block; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: block; font-size: 14px; color: var(--hint); }
.badge {
  min-width: 24px; padding: 2px 8px; border-radius: 999px; text-align: center;
  background: var(--btn); color: var(--btn-text); font-size: 14px; font-weight: 600;
}

.avatar {
  flex: none; display: grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 600;
  width: var(--size, 40px); height: var(--size, 40px); font-size: calc(var(--size, 40px) * 0.42);
  background: hsl(var(--hue), 42%, 46%);
}

/* ----- list screen ----- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 2px; margin: 14px 0 16px; border-radius: 10px; background: var(--fill); }
.tab { border: 0; background: none; padding: 8px 6px; border-radius: 8px; font-size: 15px; font-weight: 500; }
.tab[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.tab .n { color: var(--hint); font-weight: 400; margin-left: 4px; }

.card { background: var(--surface); border-radius: var(--r); margin: 0 0 14px; padding: 12px 0 4px; }
.person-head { display: flex; align-items: center; gap: 12px; padding: 0 var(--pad) 4px; }
.person-head-text { flex: 1; min-width: 0; }
.person-name { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-sub { font-size: 14px; color: var(--hint); }

.chip-btn { flex: none; border: 0; background: var(--fill); color: var(--accent); padding: 7px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; }

.cat { margin: 12px 0 0; padding: 0 var(--pad); font-size: 14px; font-weight: 600; color: var(--accent); }
.cat .n { color: var(--hint); font-weight: 400; margin-left: 6px; }

.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 10px var(--pad); }
.item + .item { border-top: 1px solid var(--line); margin-left: var(--pad); padding-left: 0; padding-right: var(--pad); }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 17px; overflow-wrap: anywhere; }
.item-title.struck { text-decoration: line-through; color: var(--hint); }
.item-link { display: inline-block; max-width: 100%; margin-top: 2px; color: var(--accent); font-size: 15px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { margin-top: 4px; font-size: 13px; color: var(--hint); }

.quote {
  margin: 6px 0 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--accent);
  font-size: 15px; opacity: 0.9; white-space: pre-wrap; overflow-wrap: anywhere;
}

.check, .status {
  flex: none; position: relative; width: 28px; height: 28px; margin-top: 1px; padding: 0;
  display: grid; place-items: center; border-radius: 50%;
  border: 2px solid var(--hint); background: none; color: transparent;
}
.check::after { content: ""; position: absolute; inset: -10px; } /* bigger tap target */
.check.on, .status.on { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.status { width: 22px; height: 22px; margin-top: 3px; border-width: 2px; }
.status svg { width: 14px; height: 14px; }

.icon-btn { flex: none; position: relative; width: 28px; height: 28px; padding: 0; border: 0; background: none; color: var(--hint); display: grid; place-items: center; }
.icon-btn::after { content: ""; position: absolute; inset: -8px; }
.icon-btn:active { color: var(--danger); }

.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px var(--pad); background: var(--surface); border-radius: var(--r); }
.switch-row input { width: 22px; height: 22px; accent-color: var(--btn); }

/* ----- states ----- */
.empty { text-align: center; padding: 40px var(--pad); color: var(--hint); }
.empty h2 { margin: 0 0 6px; font-size: 19px; color: var(--text); }
.empty p { margin: 0 0 16px; }
.empty .chip-btn { padding: 10px 18px; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--btn); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; top: calc(12px + var(--top)); z-index: 10;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 15px; text-align: center;
  opacity: 0; transform: translate(-50%, -16px); pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  #toast { transition: none; }
}
