:root {
  --bg: #f4f7ff;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --accent: #0ea5a5;
  --accent-2: #f97316;
  --line: #e5e7eb;
  --danger: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #e9fbf9, transparent 42%), radial-gradient(circle at 90% 0%, #ffeedd, transparent 38%), var(--bg);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 18px 45px rgba(17, 24, 39, 0.12);
  display: grid;
  gap: 10px;
}

.login-card h2 { margin: 0; }
.login-card p { margin: 0 0 6px; color: var(--muted); }
.login-card small { color: var(--muted); }
.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-title img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  flex: 0 0 auto;
}

.bg-blur {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
}
.actions { display: flex; align-items: center; gap: 8px; }
#userBadge { color: var(--muted); font-size: .88rem; font-weight: 600; }

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.02rem; margin: 0; }
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-brand img {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  flex: 0 0 auto;
}

main { padding: 16px 20px 34px; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  margin-bottom: 14px;
}

.tab-btn {
  flex: 0 0 130px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 8px 10px;
  font-size: .95rem;
  line-height: 1.15;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: linear-gradient(120deg, var(--accent), #22d3ee);
  color: #fff;
  border-color: transparent;
}

.panel {
  display: none;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
}

.panel.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: .5; transform: translateY(4px); } }

.panel-head {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.grid-form {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 12px;
  align-items: start;
}
.grid-form.compact { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.grid-form > * { align-self: start; }
.planning-filter-group {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.planning-filter-group select {
  min-height: 124px;
}
.readonly-note {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: #f8fafc;
}

input, select, textarea, button {
  font-family: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 9px;
  background: #fff;
}
label {
  font-size: .82rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 2px;
}
textarea { min-height: 72px; }
button { cursor: pointer; }
.btn {
  border: 0;
  background: linear-gradient(120deg, var(--accent), #14b8a6);
  color: #fff;
  font-weight: 600;
}
.btn.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn.warn { background: linear-gradient(120deg, #f59e0b, var(--accent-2)); }
.btn.danger { background: linear-gradient(120deg, #ef4444, #b91c1c); }

.table-wrap {
  width: 100%;
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
  table-layout: fixed;
}

.table-wrap > table {
  width: 100% !important;
  min-width: 0 !important;
  table-layout: fixed;
}
th, td {
  text-align: left;
  padding: 9px;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
  vertical-align: middle;
  word-break: break-word;
}
th { color: var(--muted); font-weight: 600; }
thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
}
.th-sort-btn {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  cursor: pointer;
}
.is-selected td { background: #ecfeff; }

.process-detail {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #f8fbff;
  overflow: hidden;
  max-height: 1200px;
  opacity: 1;
  transition: max-height .25s ease, opacity .2s ease, padding .2s ease;
}

.process-detail.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
}

.process-detail-row > td {
  padding: 0 !important;
  border-bottom: 0;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
}

.gantt {
  margin: 8px 0 14px;
  display: grid;
  gap: 8px;
}
.gantt-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}
.gantt-line {
  position: relative;
  height: 14px;
  background: #edf2f7;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.gantt-fill { position: absolute; top: 0; bottom: 0; border-radius: 999px; }
.gantt-deadline { border-left: 2px solid #dc2626; height: 20px; position: absolute; top: -3px; }

.timeline-wrap {
  width: 600px;
  min-width: 600px;
  max-width: 600px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #f8fafc;
  padding: 4px 6px;
}
.timeline-scroll {
  width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
}
.timeline-scroll.multi-month {
  overflow-x: auto;
}
.timeline-canvas {
  min-width: 100%;
  --day-gap: 4px;
}
.timeline-months {
  display: flex;
  margin-bottom: 2px;
}
.timeline-months span {
  text-align: center;
  font-size: .74rem;
  font-weight: 700;
  color: #1e3a8a;
  white-space: nowrap;
}
.timeline-wrap.overdue {
  background: #fee2e2;
  border-color: #fecaca;
}
.timeline-days {
  display: grid;
  grid-auto-flow: column;
  gap: var(--day-gap);
  font-size: .58rem;
  line-height: 1;
  color: #334155;
  margin-bottom: 2px;
  min-height: 12px;
}
.timeline-days span {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
.timeline-track {
  position: relative;
  height: 20px;
  border-radius: 999px;
  background: repeating-linear-gradient(
    to right,
    #e5e7eb 0,
    #e5e7eb var(--day-width, 11px),
    #f8fafc var(--day-width, 11px),
    #f8fafc calc(var(--day-width, 11px) + var(--day-gap, 4px))
  );
  overflow: hidden;
}

/* Planejamento precisa mais largura para timeline e acoes */
#planningTable {
  table-layout: auto !important;
}
#planningTable th,
#planningTable td {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}
#planningTable th:nth-child(1),
#planningTable td:nth-child(1) {
  min-width: 90px;
}
#planningTable th:nth-child(2),
#planningTable td:nth-child(2) {
  min-width: 160px;
}
#planningTable th:nth-child(3),
#planningTable td:nth-child(3) {
  min-width: 160px;
}
#planningTable th:nth-child(4),
#planningTable td:nth-child(4) {
  min-width: 120px;
}
#planningTable th:nth-child(5),
#planningTable td:nth-child(5),
#planningTable th:nth-child(6),
#planningTable td:nth-child(6),
#planningTable th:nth-child(9),
#planningTable td:nth-child(9) {
  min-width: 110px;
}
#planningTable th:nth-child(7),
#planningTable td:nth-child(7) {
  min-width: 120px;
}
#planningTable th:nth-child(8),
#planningTable td:nth-child(8) {
  min-width: 120px;
}
#planningTable th:nth-child(10),
#planningTable td:nth-child(10) {
  min-width: 360px;
}
#planningTable th:nth-child(11),
#planningTable td:nth-child(11) {
  min-width: 220px;
}
.timeline-bar {
  position: absolute;
  top: 1px;
  bottom: 1px;
  border-radius: 999px;
  opacity: .95;
  z-index: 1;
}
.timeline-deadline {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: #dc2626;
  z-index: 2;
  transform: translateX(-50%);
}

.leadtime-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}
.leadtime-table {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.leadtime-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.metric-chip {
  border: 1px solid #dbeafe;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px 10px;
}
.metric-chip span {
  display: block;
  color: var(--muted);
  font-size: .75rem;
}
.metric-chip strong {
  font-size: 1rem;
}
.leadtime-note {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  padding: 12px;
}
.leadtime-note h3 {
  margin: 0 0 8px;
}
.leadtime-note p {
  margin: 0 0 8px;
}
.summary-note {
  font-size: .92rem;
  color: #334155;
  margin-bottom: 8px;
}
.summary-tl-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 62vh;
  background: #fff;
}
.summary-tl-head,
.summary-tl-row {
  display: grid;
  grid-template-columns: 90px minmax(760px, 1fr) 80px;
  align-items: center;
}
.summary-tl-head {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #f8fafc;
  color: #64748b;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
.summary-tl-order-head,
.summary-tl-steps-head,
.summary-tl-order,
.summary-tl-steps {
  padding: 5px 8px;
}
.summary-tl-track-head,
.summary-tl-track-wrap {
  padding: 4px 0;
}
.summary-tl-axis {
  display: grid;
  grid-template-columns: repeat(1, minmax(120px, 1fr));
  gap: 0;
  margin-bottom: 4px;
}
.summary-tl-axis span {
  display: inline-flex;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  padding: 0 4px;
}
.summary-tl-row {
  border-bottom: 1px solid var(--line);
}
.summary-tl-row:last-child {
  border-bottom: 0;
}
.summary-tl-order strong {
  color: #1e3a8a;
  font-size: 1.7rem;
  line-height: 1;
}
.summary-tl-track {
  position: relative;
  height: 40px;
  border-radius: 0;
  background: #2c6ba6;
  overflow: hidden;
  min-width: 120px;
}
.summary-tl-fill {
  position: absolute;
  left: 0;
  top: 10px;
  height: 18px;
  background: #12b347;
}
.summary-tl-marker {
  position: absolute;
  top: 7px;
  bottom: 7px;
  width: 2px;
  background: #0f172a;
  transform: translateX(-50%);
}
.summary-tl-label {
  position: absolute;
  bottom: 2px;
  transform: translateX(-50%);
  font-weight: 800;
  color: #0f172a;
  font-size: .78rem;
}
.summary-tl-steps {
  text-align: right;
  color: #334155;
  font-weight: 700;
  font-size: .86rem;
}
.summary-empty {
  padding: 14px;
  color: #64748b;
}

.chart-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  align-items: stretch;
}

.chart-card {
  min-width: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  overflow: hidden;
  height: 320px;
}

.chart-card canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.drawer {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(450px, calc(100vw - 36px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(17, 24, 39, 0.18);
  padding: 12px;
  z-index: 40;
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.drawer-head h3 {
  margin: 0;
  font-size: 1rem;
}
.note-form {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 10px;
}
.note-form textarea {
  min-height: 70px;
  resize: vertical;
}
.note-form .btn {
  min-width: 90px;
}
.note-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-right: 2px;
}
.note-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #f8fafc;
}
.note-item h4 {
  margin: 0 0 4px;
  font-size: .95rem;
}
.note-item p {
  margin: 0;
  white-space: pre-wrap;
}
.note-empty {
  margin: 0;
  color: var(--muted);
}
.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.35);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 30;
}
.modal.hidden { display: none !important; }

.modal-card {
  width: min(760px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 22px 60px rgba(17, 24, 39, 0.2);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

@media (max-width: 768px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
  h1 { font-size: 1rem; }
  .chart-card { height: 260px; }
  .leadtime-layout { grid-template-columns: 1fr; }
  .leadtime-metrics { grid-template-columns: 1fr; }
  .summary-tl-head,
  .summary-tl-row {
    grid-template-columns: 72px minmax(620px, 1fr) 70px;
  }
  .summary-tl-order strong { font-size: 1.2rem; }
  .note-form { grid-template-columns: 1fr; }
}
