:root {
  --bg: #f3f5f8;
  --bg-soft: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0f5c55;
  --accent-hover: #0a4742;
  --accent-soft: #e7f3f1;
  --accent-ink: #083b37;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px rgba(15, 23, 42, .04);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --display: "Outfit", "Source Sans 3", sans-serif;
  --sidebar: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    linear-gradient(180deg, #f8fafc 0%, var(--bg) 28%, #eef2f7 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 1.1rem .85rem 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  z-index: 20;
}

.mobile-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .75rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.mobile-bar strong {
  font-family: var(--display);
  font-size: 1rem;
  letter-spacing: -.02em;
}
.menu-toggle {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: .55rem .75rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .35rem .55rem 1.1rem;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background:
    linear-gradient(145deg, #12756c 0%, #0f5c55 55%, #0b3f3b 100%);
  position: relative;
  flex-shrink: 0;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 8px 7px 8px 14px;
  border-right: 2px solid rgba(255,255,255,.9);
  border-bottom: 2px solid rgba(255,255,255,.9);
  transform: skewX(-12deg);
}
.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.02rem;
  letter-spacing: -.02em;
  font-weight: 700;
}
.brand span { color: var(--muted); font-size: .78rem; line-height: 1.25; }

.nav { display: grid; gap: .15rem; }
.nav a {
  color: #475569;
  padding: .62rem .8rem;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: .94rem;
}
.nav a:hover {
  background: var(--bg-soft);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.main {
  padding: 1.35rem 1.5rem 2.5rem;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  letter-spacing: -.03em;
  font-weight: 700;
  line-height: 1.15;
}
.topbar p {
  margin: .3rem 0 0;
  color: var(--muted);
  font-size: .95rem;
  max-width: 54ch;
}
.topbar > div:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 11px;
  padding: .62rem 1rem;
  font-weight: 700;
  font-family: inherit;
  font-size: .92rem;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  text-decoration: none;
  transition: background .15s ease, transform .15s ease;
}
.btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.btn-sm {
  padding: .42rem .7rem;
  font-size: .84rem;
  border-radius: 9px;
}

.grid { display: grid; gap: .9rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.05rem;
}
.card h3 {
  margin: 0 0 .35rem;
  font-size: .8rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.card .kpi {
  font-family: var(--display);
  font-size: clamp(1.35rem, 2vw, 1.7rem);
  letter-spacing: -.03em;
  font-weight: 700;
  color: var(--text);
}
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }

.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td {
  text-align: left;
  padding: .72rem .5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
tbody tr:hover td { background: #fafbfc; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .18rem .5rem;
  border-radius: 8px;
  font-size: .74rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.badge.urgent { background: var(--danger-soft); color: var(--danger); }
.badge.high { background: var(--warn-soft); color: var(--warn); }

.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: .75rem;
  overflow-x: auto;
  padding-bottom: .35rem;
  scroll-snap-type: x proximity;
}
.kanban-col {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 380px;
  padding: .65rem;
  scroll-snap-align: start;
}
.kanban-col h4 {
  margin: 0 0 .65rem;
  font-size: .78rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.ticket {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: .7rem .75rem;
  margin-bottom: .55rem;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.ticket strong { display: block; margin-bottom: .2rem; font-size: .95rem; }
.ticket .meta { color: var(--muted); font-size: .8rem; }

.form { display: grid; gap: .7rem; }
label {
  display: grid;
  gap: .32rem;
  font-size: .84rem;
  color: var(--muted);
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 10px;
  padding: .68rem .8rem;
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #7db5ae;
  box-shadow: 0 0 0 3px rgba(15, 92, 85, .12);
}
textarea { min-height: 90px; resize: vertical; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(15,92,85,.08), transparent 55%),
    radial-gradient(700px 380px at 100% 100%, rgba(15,23,42,.05), transparent 50%),
    var(--bg);
}
.auth-card { width: min(420px, 100%); }
.auth-card h1 {
  font-family: var(--display);
  margin: 0 0 .35rem;
  letter-spacing: -.03em;
  font-size: 1.55rem;
}
.flash {
  margin-bottom: 1rem;
  padding: .75rem .9rem;
  border-radius: 11px;
  background: var(--ok-soft);
  border: 1px solid #a7f3d0;
  color: #065f46;
  font-weight: 600;
}
.flash.error {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: #991b1b;
}

.landing {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.15rem 3.5rem;
}
.hero {
  display: grid;
  gap: .85rem;
  padding: 2rem 0 1.5rem;
}
.hero h1 {
  font-family: var(--display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1.05;
  letter-spacing: -.04em;
  margin: 0;
  max-width: 16ch;
  color: var(--text);
}
.hero p {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 48ch;
  margin: 0;
  line-height: 1.5;
}
.hero-actions {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  margin-top: .35rem;
}
.pill {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border: 1px solid #c5e4df;
  font-weight: 700;
  font-size: .8rem;
  padding: .35rem .65rem;
  border-radius: 999px;
}

dialog.card {
  border: 1px solid var(--line) !important;
  background: #fff !important;
  color: var(--text) !important;
  max-width: calc(100vw - 2rem);
}

@media (max-width: 1100px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kanban { grid-template-columns: repeat(5, 240px); }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .mobile-bar { display: flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 8px 0 30px rgba(15,23,42,.12);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.35);
    z-index: 15;
  }
  .main { padding: 1rem 1rem 2rem; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 1.35rem; }
}

@media (max-width: 560px) {
  .kanban { grid-template-columns: repeat(5, min(78vw, 260px)); }
  .btn, .btn-ghost { width: 100%; }
  .topbar > div:last-child { width: 100%; }
  .topbar > div:last-child .btn,
  .topbar > div:last-child .btn-ghost { flex: 1; }
  .task-actions .btn, .task-actions .btn-ghost { width: auto; flex: 1; }
}

/* —— OneBox-like surfaces —— */
.nav-label {
  margin: .85rem .8rem .25rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #94a3b8;
}
.home-apps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .65rem;
}
.home-app {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .85rem .9rem;
  text-decoration: none !important;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, transform .15s ease;
}
.home-app:hover {
  border-color: #a7c9c4;
  transform: translateY(-1px);
}
.home-app strong {
  display: block;
  font-family: var(--display);
  color: var(--text);
  font-size: .95rem;
  letter-spacing: -.02em;
}
.home-app span {
  display: block;
  margin-top: .2rem;
  color: var(--muted);
  font-size: .78rem;
}
.home-links { display: grid; gap: .45rem; }
.home-links a {
  font-weight: 600;
  padding: .55rem .7rem;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  text-decoration: none !important;
  color: var(--text);
}
.home-links a:hover { background: var(--accent-soft); color: var(--accent-ink); }

.funnel-bars { display: grid; gap: .7rem; }
.funnel-label {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  font-size: .86rem;
  font-weight: 600;
  margin-bottom: .28rem;
}
.funnel-track {
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.funnel-fill {
  height: 100%;
  border-radius: 999px;
  min-width: 2px;
  transition: width .35s ease;
}

.task-card { display: grid; gap: 1rem; }
.task-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.task-title {
  margin: .4rem 0 .2rem;
  font-family: var(--display);
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  letter-spacing: -.03em;
}
.task-badges { display: flex; flex-wrap: wrap; gap: .35rem; }
.task-stage-form { min-width: min(220px, 100%); }
.task-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem;
}
.task-kpis > div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .75rem .85rem;
}
.task-kpis span { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.task-kpis strong { display: block; margin-top: .25rem; font-family: var(--display); font-size: 1.05rem; }
.task-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(260px, .85fr);
  gap: .9rem;
  align-items: start;
}
.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .9rem;
}
.form-inline {
  grid-template-columns: minmax(0, 1fr) 110px auto;
  align-items: end;
}
.comment-form {
  display: grid;
  gap: .5rem;
  margin: .65rem 0 1rem;
}
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0;
}
.timeline li {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: .65rem;
  position: relative;
  padding-bottom: .95rem;
}
.timeline li:not(:last-child) .tl-dot::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 14px;
  bottom: -4px;
  width: 2px;
  background: var(--line);
}
.tl-dot {
  width: 10px;
  height: 10px;
  margin-top: .35rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  position: relative;
  z-index: 1;
}
.tl-body { display: grid; gap: .15rem; }
.tl-body strong { font-size: .9rem; }
.tl-body p { margin: .2rem 0 0; font-size: .88rem; line-height: 1.4; }
.timeline.compact li { padding-bottom: .7rem; }

.stage-builder { display: grid; gap: .55rem; }
.stage-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) 88px 72px auto;
  gap: .55rem;
  align-items: start;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}
.stage-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: .85rem;
}
.stage-fields { display: grid; gap: .35rem; }
.stage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  font-size: .78rem;
}
.stage-del { margin: 0; }
.inline-check {
  display: inline-flex !important;
  align-items: center;
  gap: .4rem;
  grid-template-columns: none !important;
  color: var(--text);
  font-size: .86rem;
}
.inline-check input { width: auto; }

.watchman-list { display: grid; gap: .55rem; }
.watchman-rule {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  align-items: flex-start;
  padding: .8rem .85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--ok-soft);
}
.watchman-rule.off { background: var(--panel-2); opacity: .75; }
.watchman-actions { display: flex; gap: .35rem; }

.filter-chips, .chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-bottom: .85rem;
}
a.chip, label.chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 600;
  font-size: .84rem;
  text-decoration: none !important;
  cursor: pointer;
}
a.chip.active, label.chip:has(input:checked) span {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: #b7d9d4;
}
label.chip { padding: 0; border: 0; background: transparent; }
label.chip input { display: none; }
label.chip span {
  display: inline-flex;
  padding: .4rem .7rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--chip, var(--accent)) 35%, var(--line));
  background: color-mix(in srgb, var(--chip, var(--accent)) 12%, #fff);
}
.people-list { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .65rem; }
.people-list li {
  padding: .65rem .7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.detail-list { margin: .6rem 0 0; display: grid; gap: .55rem; }
.detail-list > div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: .5rem;
  font-size: .93rem;
}
.detail-list dt { color: var(--muted); font-weight: 600; margin: 0; }
.detail-list dd { margin: 0; }

.kanban-drop {
  min-height: 120px;
}
.kanban-col.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}
.ticket.dragging {
  opacity: .55;
  cursor: grabbing;
}
.ticket[draggable="true"] {
  cursor: grab;
}
.kanban-hint {
  margin: .75rem 0 0;
  font-size: .85rem;
}
.cf-grid {
  display: grid;
  gap: .65rem;
  margin-bottom: .5rem;
}

@media (max-width: 1000px) {
  .task-layout { grid-template-columns: 1fr; }
  .task-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-row { grid-template-columns: 12px minmax(0, 1fr); }
  .stage-sort, .stage-color, .stage-row > .btn { grid-column: 2; }
  .form-inline { grid-template-columns: 1fr; }
}
