/* ---------- TPT Toolkit design system ---------- */
:root {
  --red: #d92a1a;
  --red-dark: #b01f12;
  --red-soft: #fdecea;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f6f7;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,.07);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  min-height: 100dvh;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .5rem;
  background: var(--red); color: #fff;
  padding: calc(var(--safe-top) + .8rem) 1rem .9rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.appbar-text { min-width: 0; }
.appbar h1 { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar p  { margin: 1px 0 0; font-size: .8rem; opacity: .85; }
.appbar.is-home { padding-top: calc(var(--safe-top) + 1.2rem); padding-bottom: 1.4rem; }
.appbar.is-home h1 { font-size: 1.6rem; }
.appbar.is-tool p { display: none; }
.back {
  flex: none; width: 40px; height: 40px; margin-left: -.4rem;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: rgba(255,255,255,.16); cursor: pointer;
}
.back[hidden] { display: none; }
.back:active { background: rgba(255,255,255,.3); }
.back svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- View container ---------- */
.view { padding: 1rem 1rem calc(var(--safe-bottom) + 2rem); max-width: 900px; margin: 0 auto; outline: none; }
.loading { text-align: center; color: var(--muted); padding: 3rem 0; }

/* ---------- Home tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; }
.tile {
  display: flex; flex-direction: column; gap: .6rem;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; color: inherit; text-decoration: none; border: 1px solid transparent;
  transition: transform .12s ease, border-color .12s ease;
}
.tile:active { transform: scale(.97); border-color: var(--red); }
.tile-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--red-soft); display: grid; place-items: center; }
.tile-icon svg { width: 26px; height: 26px; fill: none; stroke: var(--red); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile h2 { margin: 0; font-size: 1rem; line-height: 1.2; }
.tile p  { margin: 0; font-size: .82rem; color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 2rem; }

/* ---------- Shared components (use these in every tool) ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.card h2 { margin: 0 0 .6rem; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .2rem 0 .8rem; }

.field { margin-top: .85rem; }
.field > label, .field-label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; }
input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .7rem .8rem;
  font: inherit; font-size: 16px; /* 16px stops iOS zoom-on-focus */
  color: var(--ink); background-color: #fff;
  border: 1px solid #d1d5db; border-radius: 10px;
  appearance: none; -webkit-appearance: none;
}
input[type=date] { min-height: 46px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; background-size: 18px; padding-right: 2.2rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(217,42,26,.15); }
.check { display: flex; gap: .55rem; align-items: center; font-size: .9rem; }
.check input { width: 20px; height: 20px; accent-color: var(--red); flex: none; }
.row { display: flex; gap: .7rem; }
.row > .field { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .8rem 1.1rem; font: inherit; font-weight: 600; font-size: 1rem;
  color: #fff; background: var(--red); border: 0; border-radius: 10px; cursor: pointer; text-decoration: none;
}
.btn:active { background: var(--red-dark); }
.btn.block { width: 100%; margin-top: 1.1rem; }
.btn.secondary { background: var(--red-soft); color: var(--red-dark); }
.btn.secondary:active { background: #f9d4cf; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

.result { margin-top: 1.1rem; padding: 1rem; text-align: center; border-radius: 12px; background: var(--red-soft); color: var(--red-dark); font-weight: 700; font-size: 1.1rem; }
.result.error { background: #fff4e5; color: #92400e; }
.result small { display: block; font-weight: 500; color: var(--ink); margin-top: .3rem; font-size: .9rem; }
.result[hidden] { display: none; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .6rem; text-align: center; border-bottom: 1px solid var(--line); font-size: .92rem; }
th { background: var(--red); color: #fff; font-weight: 600; }
tr:nth-child(even) td { background: #fafafa; }

.split { display: flex; flex-direction: column; gap: 1rem; }
@media (orientation: landscape) and (min-width: 700px) {
  .split { flex-direction: row; align-items: flex-start; }
  .split > * { flex: 1; min-width: 0; }
}
.field > label.check { font-weight: 500; }
