/* DomainLens Portfolio — Telegram Mini App.
   Colours come from Telegram's theme variables so the app sits inside the client's own light/dark
   look; the urgency scale is ours and stays fixed. */
:root {
  --bg: var(--tg-theme-bg-color, #f6f5f1);
  --bg2: var(--tg-theme-secondary-bg-color, #ecebe5);
  --ink: var(--tg-theme-text-color, #1b1a17);
  --hint: var(--tg-theme-hint-color, #6b6960);
  --link: var(--tg-theme-link-color, #1a5fd0);
  --btn: var(--tg-theme-button-color, #1f6feb);
  --btn-ink: var(--tg-theme-button-text-color, #ffffff);
  --line: var(--tg-theme-section-separator-color, rgba(127, 127, 127, .22));
  --danger: var(--tg-theme-destructive-text-color, #d93a3f);
  --u-red: #e5484d;
  --u-amber: #e8a317;
  --u-green: #2f9e66;
  --u-none: #9a978d;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --r-s: 10px;
  --r-m: 16px;
  --r-pill: 999px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  font-stretch: 92%;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---- top bar ---------------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar h1 {
  margin: 0; flex: 1; min-width: 0;
  font-size: 20px; font-weight: 700; font-stretch: 78%; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar h1.domain { font: 700 17px/1.2 var(--mono); letter-spacing: -.02em; }
.bar .meta { color: var(--hint); font: 500 13px var(--mono); white-space: nowrap; }
.back {
  display: grid; place-items: center; width: 36px; height: 36px; margin-left: -8px;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--link);
}

/* ---- list tools --------------------------------------------------------------- */
.tools { padding: 12px 16px 4px; display: grid; gap: 10px; }
.search {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--bg2); outline: none;
}
.search:focus { border-color: var(--btn); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: transparent; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.row-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--hint); }
.row-tools select { border: 0; background: transparent; color: var(--link); font-weight: 600; padding: 4px 0; }
.linkish { border: 0; background: transparent; color: var(--link); font-weight: 600; padding: 4px 0; font-size: 13px; }

.total {
  margin: 4px 16px 0; padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 13px; color: var(--hint);
}
.total b { color: var(--ink); font: 700 14px var(--mono); }

/* ---- domain ledger -------------------------------------------------------------- */
.ledger { list-style: none; margin: 0; padding: 0; }
.ledger li { border-bottom: 1px solid var(--line); }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  width: 100%; padding: 12px 16px 10px; text-align: left;
  border: 0; background: transparent;
  transition: background .2s var(--ease);
}
.item:active { background: var(--bg2); }
.item .name { font: 700 15px/1.25 var(--mono); letter-spacing: -.02em; overflow-wrap: anywhere; }
.item .days { font: 700 13px/1.25 var(--mono); text-align: right; white-space: nowrap; }
.item .sub { grid-column: 1 / -1; font-size: 12.5px; color: var(--hint); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.item .sub .tag { color: var(--link); }
.fuse { grid-column: 1 / -1; height: 3px; margin-top: 6px; border-radius: var(--r-pill); background: var(--bg2); overflow: hidden; }
.fuse i { display: block; height: 100%; border-radius: inherit; }
.u-red { color: var(--u-red); } .u-amber { color: var(--u-amber); } .u-green { color: var(--u-green); } .u-none { color: var(--u-none); }
/* text needs more contrast than the bars: pull the hue toward the theme's ink colour */
@supports (color: color-mix(in srgb, red, blue)) {
  .u-red { color: color-mix(in srgb, var(--u-red) 72%, var(--ink)); }
  .u-amber { color: color-mix(in srgb, var(--u-amber) 52%, var(--ink)); }
  .u-green { color: color-mix(in srgb, var(--u-green) 68%, var(--ink)); }
  .u-none { color: var(--hint); }
}
.fuse .u-red { background: var(--u-red); } .fuse .u-amber { background: var(--u-amber); }
.fuse .u-green { background: var(--u-green); } .fuse .u-none { background: var(--u-none); opacity: .35; }

.empty { padding: 48px 24px; text-align: center; color: var(--hint); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* ---- detail ------------------------------------------------------------------------- */
.hero { padding: 18px 16px 14px; border-bottom: 1px solid var(--line); }
.hero .big { font: 700 34px/1 var(--mono); letter-spacing: -.04em; }
.hero .big small { font: 600 14px var(--sans); letter-spacing: 0; color: var(--hint); margin-left: 6px; }
.hero .when { margin-top: 6px; color: var(--hint); font-size: 13px; }
.hero .fuse { height: 4px; margin-top: 12px; }
.renew {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: calc(100% - 32px); margin: 14px 16px 4px; padding: 12px 14px;
  border: 1px solid var(--btn); border-radius: var(--r-s);
  background: transparent; color: var(--btn); font-weight: 700; text-align: left;
}
.renew small { display: block; font-weight: 500; color: var(--hint); font-size: 12px; }

.section { padding: 14px 16px 6px; }
.section h2 { margin: 0 0 8px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--hint); }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--hint); }
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--bg2); outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--btn); }
.field textarea { min-height: 96px; resize: vertical; }
.field .err { color: var(--danger); font-size: 12px; }
.pair { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.counter { text-align: right; font-size: 11px; color: var(--hint); }

.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--r-s); overflow: hidden; }
.seg button { padding: 9px 8px; border: 0; background: transparent; font-weight: 600; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.hint { font-size: 12px; color: var(--hint); margin: 6px 0 0; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 12px; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: var(--r-pill); background: var(--line); position: relative; margin: 0; transition: background .2s var(--ease); }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .25s var(--ease); }
.switch input:checked { background: var(--u-green); }
.switch input:checked::after { transform: translateX(18px); }

.tagbox { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--bg2); }
.tagbox input { flex: 1; min-width: 90px; border: 0; background: transparent; outline: none; padding: 4px; }
.tagpill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: var(--r-pill); background: var(--bg); font-size: 13px; font-weight: 600; }
.tagpill button { width: 20px; height: 20px; border: 0; border-radius: 50%; background: transparent; color: var(--hint); line-height: 1; }

dl.facts { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
dl.facts dt { color: var(--hint); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
dl.facts dd.mono { font-family: var(--mono); font-size: 12.5px; white-space: pre-line; }

.actions { display: flex; gap: 8px; padding: 10px 16px 20px; flex-wrap: wrap; }
.ghost { padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r-s); background: transparent; font-weight: 600; font-size: 14px; }
.ghost.danger { color: var(--danger); }

/* ---- sticky primary action ------------------------------------------------------------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.primary {
  width: 100%; padding: 14px; border: 0; border-radius: var(--r-s);
  background: var(--btn); color: var(--btn-ink); font-weight: 700; font-size: 15px;
  transition: transform .15s var(--ease), opacity .2s var(--ease);
}
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .45; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 7;
  padding: 11px 14px; border-radius: var(--r-s);
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600; text-align: center;
  animation: rise .3s var(--ease);
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.addbox textarea { min-height: 160px; font-family: var(--mono); font-size: 14px; }
.results { list-style: none; margin: 0; padding: 0 16px; font-size: 13px; }
.results li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.results li span:first-child { font-family: var(--mono); overflow-wrap: anywhere; }

.skeleton { margin: 16px; height: 14px; border-radius: var(--r-pill); background: var(--bg2); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
