* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f4f8;
  color: #2d3748;
  min-height: 100vh;
}

header {
  background: #1a365d;
  color: #fff;
  padding: 1rem 2rem;
  text-align: center;
}

header h1 { font-size: 1.4rem; letter-spacing: 1px; }
header p { font-size: 0.75rem; opacity: 0.8; margin-top: 2px; }

.grid-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  overflow: hidden;
}

.input-panel { grid-row: 1 / 3; align-self: start; }
.diagram-panel { grid-column: 2; }
.results-panel { grid-column: 2; }

.upload-area {
  background: #ebf8ff;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #bee3f8;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#file-name { font-size: 0.8rem; color: #4a5568; }

form { padding: 0.75rem 1rem 1rem; }

fieldset {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.75rem;
}

legend {
  font-weight: 700;
  font-size: 0.8rem;
  color: #1a365d;
  padding: 0 4px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  gap: 4px;
}

.field-row label {
  font-size: 0.72rem;
  color: #4a5568;
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
}

.field-row input,
.field-row select {
  width: 130px;
  padding: 3px 6px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  font-size: 0.8rem;
  text-align: right;
}

.field-row select { text-align: left; }

.field-row input:focus,
.field-row select:focus {
  outline: none;
  border-color: #3182ce;
  box-shadow: 0 0 0 2px rgba(49,130,206,0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  width: 100%;
  margin-top: 0.5rem;
  background: #2b6cb0;
  color: #fff;
}

.btn-secondary {
  background: #edf2f7;
  color: #2d3748;
  font-size: 0.8rem;
}

.btn-download {
  background: #38a169;
  color: #fff;
  font-size: 0.8rem;
  padding: 0.35rem 0.8rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.diagram-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: #f7fafc;
  border-bottom: 1px solid #e2e8f0;
}

.diagram-header h2 { font-size: 0.9rem; color: #1a365d; }

.toggle-label {
  font-size: 0.78rem;
  color: #4a5568;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.condition-label {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: #2b6cb0;
}

.diagram-container {
  width: 100%;
  min-height: 350px;
}

.diagram-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: #f7fafc;
  border-bottom: 1px solid #e2e8f0;
}

.results-header h2 { font-size: 0.9rem; color: #1a365d; }

.download-buttons { display: flex; gap: 6px; }

#results-table-wrapper { overflow-x: auto; padding: 0; }

#results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

#results-table th {
  background: #f7fafc;
  padding: 0.5rem 0.6rem;
  text-align: center;
  font-weight: 600;
  color: #4a5568;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

#results-table td {
  padding: 0.4rem 0.6rem;
  text-align: center;
  border-bottom: 1px solid #edf2f7;
}

#results-table tr.clickable { cursor: pointer; }
#results-table tr.clickable:hover { background: #ebf8ff !important; }
#results-table tr.active-row { outline: 2px solid #2b6cb0; outline-offset: -2px; }

#results-table tr.row-iniciais { background: #ebf8ff; }
#results-table tr.row-finais { background: #f0fff4; }
#results-table tr.row-pv { background: #fffaf0; }
#results-table tr.row-eds { background: #fefcbf !important; }
#results-table tr.row-eds:hover { background: #fef08a !important; }
#results-table tr.row-label td { font-weight: 700; color: #1a365d; }

.badge-eds {
  display: inline-block;
  background: #d69e2e;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.3;
}

.empty-msg { text-align: center; color: #a0aec0; padding: 2rem !important; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #e53e3e; }
.toast.success { background: #38a169; }

@keyframes wind {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(8px, -8px); }
}

@media (max-width: 900px) {
  .grid-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .input-panel { grid-row: auto; max-height: none; }
  .diagram-panel { grid-column: 1; }
  .results-panel { grid-column: 1; }
}
