/* KTM Field — mobile-first, one-hand, outdoors.
   Rules that matter: minimum 48px tap targets, high contrast, no hover-only
   affordances, and a sticky action bar so the primary action is always
   reachable with a thumb. */

:root {
  --ink: #101828;
  --ink-soft: #475467;
  --line: #e4e7ec;
  --bg: #f4f6fa;
  --card: #ffffff;
  --brand: #0f1b2d;
  --brand-soft: #1c2f4a;
  --accent: #ecb34d;
  --go: #0b7a3e;
  --go-soft: #e7f6ee;
  --warn: #b4530a;
  --warn-soft: #fdf1e3;
  --stop: #b42318;
  --stop-soft: #fdecea;
  --info: #1d4ed8;
  --info-soft: #e8eefc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

body { padding-bottom: env(safe-area-inset-bottom); }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }

.muted { color: var(--ink-soft); font-weight: 400; }

/* Brand ---------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: .4rem; }
.brand-mark {
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--accent);
  font-size: 1rem;
}
.brand-sub { color: #fff; font-size: .82rem; letter-spacing: .12em; text-transform: uppercase; opacity: .8; }
.brand-lg { justify-content: center; }
.brand-lg .brand-mark { font-size: 1.6rem; color: var(--accent); }
.brand-lg .brand-sub { color: var(--ink-soft); font-size: 1rem; }

/* Sign in -------------------------------------------------------------- */
.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: radial-gradient(120% 80% at 50% 0%, #1c2f4a 0%, #0f1b2d 55%, #0b1524 100%);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 18px;
  padding: 1.5rem 1.25rem 1.4rem;
  box-shadow: 0 20px 50px rgba(4, 10, 22, .45);
}
.login-card .brand-lg .brand-mark { color: var(--brand); }
.login-hint { color: var(--ink-soft); font-size: .92rem; margin: .6rem 0 1.1rem; text-align: center; }

.field { display: block; margin-bottom: .9rem; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .35rem; letter-spacing: .01em; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 50px;
  padding: .7rem .8rem;
  border: 1px solid #cfd6e0;
  border-radius: 11px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 3px solid rgba(29, 78, 216, .25);
  border-color: var(--info);
}
.check { display: flex; align-items: center; gap: .55rem; font-size: .93rem; color: var(--ink-soft); margin: .2rem 0 1rem; }
.check input { width: 20px; height: 20px; }
.form-error {
  margin: .7rem 0 0;
  padding: .6rem .75rem;
  border-radius: 10px;
  background: var(--stop-soft);
  color: var(--stop);
  font-size: .9rem;
  font-weight: 600;
}

/* Buttons -------------------------------------------------------------- */
.btn {
  min-height: 50px;
  padding: 0 1.05rem;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  touch-action: manipulation;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-soft); }
.btn-go { background: var(--go); color: #fff; }
.btn-hold { background: var(--warn); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border-color: #cfd6e0; }
.btn-ghost:active { background: #eef1f6; }
.btn-danger { background: var(--stop-soft); color: var(--stop); border-color: #f3c7c2; }

.icon-btn {
  width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
}
.icon-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.topbar .icon-btn:active { background: rgba(255, 255, 255, .24); }

/* Views ---------------------------------------------------------------- */
.view { min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 60px;
  padding: 0 .8rem;
  padding-top: env(safe-area-inset-top);
  background: var(--brand);
  color: #fff;
}
.topbar-right { display: flex; align-items: center; gap: .35rem; }
.who { font-size: .82rem; opacity: .82; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-title { font-size: .98rem; font-weight: 650; flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { display: flex; gap: .4rem; padding: .7rem .8rem .2rem; }
.tab {
  min-height: 42px;
  padding: 0 .9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 650;
  cursor: pointer;
}
.tab.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; padding: .6rem .8rem .2rem; }
.summary .stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .55rem .6rem;
  text-align: center;
}
.summary .stat b { display: block; font-size: 1.25rem; line-height: 1.1; }
.summary .stat span { font-size: .72rem; color: var(--ink-soft); letter-spacing: .02em; text-transform: uppercase; }

.list { padding: .75rem .8rem 3rem; display: grid; gap: .7rem; }

/* Task card ------------------------------------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .85rem .9rem;
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}
.card:active { transform: scale(.995); }
.card.overdue { border-left: 4px solid var(--stop); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.card-code { font-size: .74rem; font-weight: 700; letter-spacing: .08em; color: var(--ink-soft); }
.card-name { font-size: 1.02rem; font-weight: 700; margin: .1rem 0 .15rem; }
.card-meta { font-size: .86rem; color: var(--ink-soft); }
.card-foot { display: flex; align-items: center; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .22rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}
.chip.scheduled { background: var(--info-soft); color: var(--info); }
.chip.progress { background: var(--warn-soft); color: var(--warn); }
.chip.hold { background: var(--stop-soft); color: var(--stop); }
.chip.done { background: var(--go-soft); color: var(--go); }
.chip.plain { background: #eef1f6; color: var(--ink-soft); }
.chip.late { background: var(--stop-soft); color: var(--stop); }

.empty {
  margin: 2rem 1.2rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: .95rem;
}

/* Detail --------------------------------------------------------------- */
.detail-body { padding: .8rem .8rem 7rem; display: grid; gap: .75rem; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem;
  box-shadow: var(--shadow);
}
.panel h3 { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: .6rem; }
.kv { display: grid; grid-template-columns: 40% 1fr; gap: .35rem .6rem; font-size: .94rem; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.contact-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .7rem; }
.contact-row .btn { flex: 1 1 auto; text-decoration: none; font-size: .92rem; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.timeline li { border-left: 3px solid var(--line); padding-left: .65rem; }
.timeline .t-what { font-weight: 650; font-size: .94rem; }
.timeline .t-when { font-size: .8rem; color: var(--ink-soft); }
.timeline .t-note { font-size: .88rem; margin-top: .15rem; }

.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  gap: .5rem;
  padding: .7rem .8rem calc(.7rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.action-bar .btn { flex: 1 1 0; }
.action-bar .btn-wide { flex: 1 1 100%; }

.banner {
  padding: .7rem .8rem;
  border-radius: 12px;
  font-size: .9rem;
  font-weight: 600;
}
.banner.info { background: var(--info-soft); color: var(--info); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.stop { background: var(--stop-soft); color: var(--stop); }

/* Dialogs -------------------------------------------------------------- */
.sheet {
  border: 0;
  padding: 0;
  width: min(560px, 100%);
  max-height: 92dvh;
  margin: auto auto 0;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 -12px 40px rgba(4, 10, 22, .3);
}
.sheet::backdrop { background: rgba(6, 12, 22, .5); }
.sheet-form { padding: 1.1rem 1rem calc(1rem + env(safe-area-inset-bottom)); display: grid; gap: .2rem; }
.sheet-sub { color: var(--ink-soft); font-size: .88rem; margin: .3rem 0 .9rem; }
.sheet-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.sheet-actions .btn { flex: 1; }

.photo-actions { display: flex; gap: .5rem; }
.photo-actions .btn { flex: 1; }
.photo-list { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.photo-list figure, .photos-body figure {
  margin: 0;
  position: relative;
  width: 84px;
}
.photo-list img, .photos-body img {
  width: 84px; height: 84px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}
.photo-list figcaption, .photos-body figcaption { font-size: .68rem; color: var(--ink-soft); margin-top: .15rem; }
.photo-remove {
  position: absolute; top: -6px; right: -6px;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 0;
  background: var(--stop);
  color: #fff;
  font-size: .8rem;
  line-height: 1;
  cursor: pointer;
}
.photos-body { display: flex; gap: .6rem; flex-wrap: wrap; min-height: 70px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: 90vw;
  padding: .7rem 1rem;
  border-radius: 12px;
  background: #101828;
  color: #fff;
  font-size: .9rem;
  box-shadow: 0 10px 25px rgba(4, 10, 22, .35);
}

@media (min-width: 720px) {
  .list { grid-template-columns: repeat(2, 1fr); }
  .detail-body { max-width: 720px; margin: 0 auto; }
  .action-bar { max-width: 720px; margin: 0 auto; border-radius: 16px 16px 0 0; }
}
